/*
 * http://jquery.com/
 */
 
$(document).ready(function() {
	slider1(2500, 270); // set delay between the automatic slider and width of photos 
});

function slider1($secs, $photo_wth) {
	$addC = $(".itemidx.current").length;	
		if($addC == 0) {
			$(".itemidx:first").addClass("current");	
		}
	$allPort = ($(".itemidx").length) - 1;	
	//alert($allPort);
	$wthDivide = 390 - $photo_wth;	
	$tileWth = parseInt($wthDivide / $allPort);	
	$caption_wth = $photo_wth - 30;	
	$caption_wth = $caption_wth + 'px';	
	$photo_wth = $photo_wth + 'px';
	
	$(".itemidx").css("height", $tileWth);	$(".itemidx.current").css("height", $photo_wth);	
	$(".caption").css({ height: $caption_wth, opacity: 0 });	
	
	if(typeof(isClicked) == 'undefined') { var isClicked = 0; }
	
	$(".itemidx").click(function() {
			isClicked = 1;	
			var classClicked = $(this).attr('class');	
			
				if(classClicked !== 'itemidx current') {
					$(".itemidx.current").removeClass("current").addClass("prev").stop().animate({ height: $tileWth }, 830);	
					$(this).addClass("current").css("height", $tileWth).stop().animate({ height: $photo_wth }, 930);	
					$(".itemidx.prev").removeClass("prev"); 
				}	
	});
	
	if(typeof(isHovered) == 'undefined') { var isHovered = 0; }	
	
	$(".itemidx").hover(function() {	isHovered = 1;	}, function() {	isHovered = 0;	});	
	
	setInterval(function() {	if(isHovered == 0 && isClicked == 0) {	nextItm('270px', $tileWth);	}	}, $secs);
}

function nextItm($photo_wth, $tile_width) {	
	$current = $(".itemidx.current");	$next = $(".itemidx.current").next();	
		if($next.attr('class') == undefined) {	$next = $(".itemidx:first");	
		} else {	}	
	$current.removeClass("current").css("height", $photo_wth).stop().animate({ height: $tile_width }, 830);	
	$next.addClass("current").css("height", $tile_width).stop().animate({ height: $photo_wth }, 930);
}

