$(function() {
	/*
	ONLY LOAD FIRST 3 IMAGES
	ON CLICK NEXT GET URL FROM THE 3RD IMG
	THEN LOAD IT AND APPLY MY SHRINK FUNCTION TO IT
	
	THIS WILL HELP WITH LOAD TIMES WHEN THIS GALLERY GETS BIGGER
	*/
	
	$.fn.imageShrink = function() { // IMAGE SHRINK
		return this.each(function(i){					  
			$height = $(this).height();
			$width = $(this).width();
			$heightMin = $height/1.3;
			$widthMin = $width/1.3;
			$(this).animate({height:$heightMin+"px", width:$widthMin+"px","opacity": .5},200);	
		});
	};
	
	$.fn.imageZoom = function() { // IMAGE ZOOM
		$height = $(this).height();
		$width = $(this).width();
		$heightMin = $height*1.3;
		$widthMin = $width*1.3;
		$(this).animate({height:$heightMin+"px", width:$widthMin+"px","opacity": 1},200);	
	};

	// PHOTO SCROLLER	
	var photoApi = $(".page-template-photo-php .curtan").scrollable({
		clickable:false,
		api:true,
		size:1,
		easing:'bounce',
		speed:500,
		onSeek:function(){
			$disable = false;
		}
	});
	
	//SCROLLER NAVIGATION
	$('.page-template-photo-php .theNextImage').click(function() {
		if(!$disable) {	
			$('.page-template-photo-php .thePrevImage').show(200);
			$disable = true;
			$('.items .active').next().removeClass('inactive').addClass('nextActive');
			$('.items .active').removeClass('active').addClass('lastActive');
			$('.items .lastActive img').imageShrink();
			$('.items .nextActive img').imageZoom();
			photoApi.next();
			$('.items .lastActive').removeClass('lastActive').addClass('inactive');
			$('.items .nextActive').removeClass('nextActive').addClass('active');
			if ($('.items li:last').hasClass('active')) {
				$('.page-template-photo-php .theNextImage').hide(200);
			}
			return false;
		} else {
			return false;
		}
	});	
	
	$('.page-template-photo-php .thePrevImage').click(function() {
		if(!$disable) {	
			$('.page-template-photo-php .theNextImage').show(200);
			$disable = true;													   									   
			$('.items .active').prev().removeClass('inactive').addClass('nextActive');
			$('.items .active').removeClass('active').addClass('lastActive');
			$('.items .nextActive img').imageZoom();
			$('.items .lastActive img').imageShrink();
			photoApi.prev();
			$('.items .lastActive').removeClass('lastActive').addClass('inactive');
			$('.items .nextActive').removeClass('nextActive').addClass('active');
			if ($('.items li:first').hasClass('active')) {
				$('.page-template-photo-php .thePrevImage').hide(200);
			}
			return false;
		} else {
			return false;
		}
	});			
	$disable = false;
});

$(window).load(function() { // FULLY LOADED FN
	$('.galery-navi .inactive img').load().imageShrink();
	$('.page-template-photo-php .theNextImage').load().show(200);
});
