var photoThumbsWidth = 92;
var move = photoThumbsWidth * 3;
var stripesWidth;
var thumbsAreaWidth;
var shift;

$(document).ready(
function() {
	$('#site_tabs').tabs();		
	if ($('#photos_nr').attr('value')) setPhotoThumbs();	
	developedMainMenu();	
});


function setPhotoThumbs() {	
	$("#img_thumbs_stripe").css({opacity:0,visibility:'visible'});		
	
	var photosKey = $('#photos_key').attr('value');
	var photosQuantity = $('#photos_quantity').attr('value');		
	thumbsAreaWidth = $('#img_thumbs_area').css('width');	
	thumbsAreaWidth = thumbsAreaWidth.replace('px','');	
	stripesWidth = photosQuantity * photoThumbsWidth;	
	shift = (photosKey * photoThumbsWidth) - thumbsAreaWidth/2+photoThumbsWidth/2;
	
	shift = shiftCorrection(shift);	
	
	$("#img_thumbs_stripe").css({width:stripesWidth+"px"});	
	
	if (photoThumbsWidth > stripesWidth) {
		$("#thumbsShiftR").css({display:'none'});
		$("#thumbsShiftL").css({display:'none'});
	}
	
	$("#img_thumbs_stripe").css({width:stripesWidth+"px"});	
	$("#img_thumbs_stripe").css({marginLeft:-shift,opacity:1});
	
	
	$("#thumbsShiftL").click(function() {		
		var marginLeft = $("#img_thumbs_stripe").css('marginLeft');
		marginLeft = parseInt(marginLeft.replace('px',''));		
		if (marginLeft + move > 0) shiftX = -marginLeft;
		else shiftX = move;		
		$("#img_thumbs_stripe").animate({marginLeft:"+="+shiftX+"px"}, "slow");		
	})	
	$("#thumbsShiftR").click(function() {				
		var marginLeft = $("#img_thumbs_stripe").css('marginLeft');
		marginLeft = parseInt(marginLeft.replace('px',''));			
		if (marginLeft + stripesWidth > thumbsAreaWidth) {		
		    if (marginLeft - move + stripesWidth < thumbsAreaWidth) shiftX = marginLeft + stripesWidth - thumbsAreaWidth -2;
			else shiftX = move;		    
			$("#img_thumbs_stripe").animate({marginLeft:"-="+shiftX+"px"}, "slow");	
		}
	})			
	
}	
		
function shiftCorrection(shift) {	
	if (stripesWidth - shift < thumbsAreaWidth)  shift = stripesWidth - thumbsAreaWidth - 2;	
	else if (shift<0) shift = 0;	

	return(shift);
}	
