$(document).ready(function(){

	$('div.galleryThumbnailBox').hover(
		function(){
			if (!$(this).hasClass('current')){
				$(this).removeClass('notActive');
				$(this).addClass('active');
			}
		},
		function(){
			if (!$(this).hasClass('current')){
				$(this).removeClass('active');
				$(this).addClass('notActive');
			}
		}
	);
	
	//$('div.galleryThumbnailBox a').click(loadContent);	
	
		
});

function loadContent(thisObj, galleryId, photoId, loadAjax){
	/* galleryLoader is box 50x50 px */
	var galleryLoaderWidth = 50;
	var galleryLoaderHeight = 50;
	
	var galleryLoader = $('img#galleryLoader').clone();
	var galleryPhoto = $('div.galleryPhoto');

	galleryLoader.appendTo(galleryPhoto);
	
	$.getJSON('/gallery/ajax/galleryid='+galleryId+',photoid='+photoId, null, function(data){
		if (data){
			galleryPhoto.html('<img src="' + data.img + '" alt="' + data.alt + '" />');
			$('div.galleryDescriptionContent div.title').html(data.title);
			$('div.galleryDescriptionContent div.description').html(data.description);
			//$('title').html('Sniper - ' + data.alt);
			document.title = data.alt + ' - Sniper Notebook Serwis';
			
			moveGalleryThumbs(thisObj);
		}
	});
}

function moveGalleryThumbs(thisObj){
	var animateDistance = 170;
	var marginLeft = animateDistance*2;
	var visibleThumbsAreaWidth = animateDistance*6;
	
	$('div.current').removeClass('current').addClass('notActive');
	$(thisObj).parent().addClass('current').removeClass('active');
	
	var galleryThumbsContent = $('div#galleryThumbsContent');
	
	$('div.galleryThumbnailBox').each(
		function(i){
			if ($(this).hasClass('current')){
				var left = (animateDistance*i);

				if (left < marginLeft){
					left = 0;
				} else if ((left+visibleThumbsAreaWidth-marginLeft) > galleryThumbsContent.width()){
					left = galleryThumbsContent.css('left').replace('px','')*(-1);
				} else {
					left -= marginLeft;
				}
				
				galleryThumbsContent.animate({left: -(left)+'px'}, 1000);
			}
		}
	);
}
