$(document).ready(function() {

  jQuery.fn.extend({
  
    slideRightShow: function() {
      return this.each(function() {
        $(this).show('slide', {direction: 'right'}, 1000);
      });
    },
  
    slideLeftHide: function() {
      return this.each(function() {
        $(this).hide('slide', {direction: 'left'}, 1000);     
      });  
    },
  
    slideRightHide: function() {
      return this.each(function(){   
        $(this).hide('slide', {direction: 'right'}, 1000);   
      });   
    },
  
    slideLeftShow: function() {    
      return this.each(function() {     
        $(this).show('slide', {direction: 'left'}, 1000);  
      });   
    }

  });


//     $("#teaser_content").animate({
//       left: '-940'
//     },
//     1000, function() {
//         // Animation complete.
//     });
//  
 
 
  
//   $("#teaser_content").animate({width:'toggle'},3000); 

  // délka zobrazení jednoho obrázku v ms
  var change_time = 10000;
  // počitadlo cyklů
  var counter = 0;
  // počet fotografií(cyklů)
  var count = 4;

  // automatické posouvání
  myInterval = setInterval(function() {

    // inkrementace counteru
    counter = counter+1;

    // nastavení aktivní položky navigace teaseru
    $('#item_'+counter).removeClass('selected');

    // resetování counteru
    if(counter == count)
      counter = 0;
  	$('#item_'+(counter+1)).addClass('selected');

    // nastavní hodnoty kam se má posunout teaser
    var move_left = counter*940;

    $("#teaser_content").animate({
      left: -move_left
    },
    1000, function() {
      // Animation complete.
    });

  }, change_time);


  /*
  * ruční posouvání
  */
  // posunutí vlevo  
	$('#stripNavL0 a').click(function(e) {
		e.preventDefault();

    var left_pos = $("#teaser_content").css('left');
    left_pos = left_pos.replace('px','');

    $("#teaser_content").animate({
      left: -left_pos
    },
    1000, function() {
      // Animation complete.
    });


  });

  // posunutí vpravo
	$('#stripNavR0 a').click(function(e) {
		e.preventDefault();

    var left = $("#teaser_content").css('left');
    left = left.replace('px','');

    count = parseInt(left/940);
    alert(count);

//  alert(move_left);
    $("#teaser_content").animate({
      left: left
    },
    1000, function() {
      // Animation complete.
    });

  });


  /*
  * posouvání klikem na konkrétní položku
  */  
	$('.teaser_nav_item').click(function() {
    clearInterval(myInterval);
    var id = $(this).attr('rel');

    var move_left = ((id-1)*940);
    
    $("#teaser_content").animate({
      left: -move_left
    },
    1000, function() {
      // Animation complete.
    });

    // nastavení aktivní položky navigace teaseru
    $('.selected').removeClass('selected');
  	$('#item_'+id).addClass('selected');

  });

});
