$(document).ready(function(){
  var currentPB = 0;
  var pbWidth = 90;
  var pb_length = $('.thumbnail ul li');
  var noPB = pb_length.length;

  $('.publication .detail .thumbnail ul').css('overflow', 'hidden');

  pb_length
    .wrapAll('<div id="slideInnerPhotos"></div>')
	.css({
      'float' : 'left',
      'width' : pbWidth
    });

  $('#slideInnerPhotos').css('width', pbWidth * noPB);

  manageControlsPhoto(currentPB);

  $('.publication .detail .thumbnail .control').bind('click', function(){
		currentPB = ($(this).attr('id')=='rightControl') ? currentPB+1 : currentPB-1;
    	manageControlsPhoto(currentPB);
    	
		$('#slideInnerPhotos').animate({
      		'marginLeft' : pbWidth*(-currentPB)
    	});
  });

  function manageControlsPhoto(position){
	  	//count length all photo_thumb 
	  	var all_length = $(".thumbnail ul").find("li").length;
		
		if(position==0){ 
			$('.publication .detail .thumbnail #leftControl').hide();
		} 
		else{ 
			$('.publication .detail .thumbnail #leftControl').show();
		}
    	if(position==noPB-1 || currentPB == (all_length-4) || all_length <= 4){ 
			$('.publication .detail .thumbnail #rightControl').hide();
		} 
		else{ 
			$('.publication .detail .thumbnail #rightControl').show();
		}
  }	
  
  
});


