$(document).ready(function(){
//next/prev buttons show/hide
$("a#next").hide();
$("a#prev").hide();
$(".imgs").mouseover(function(){
	if(animAllowed){
		if(current < img_count) $("a#next").show();
		if(current > 0) $("a#prev").show();
	}
});
$(".imgs").mouseout(function(){
	$("a#next").hide();
	$("a#prev").hide();
});

//list item states

var li0 = {"left": "0", "top": "110px", "width": "190px", "height": "143px"};
var li1 = {"left": "0", "top": "110px", "width": "190px", "height": "143px"};
var li2 = {"left": "100px", "top": "75px", "width": "280px", "height": "210px"};
var li3 = {"left": "255px", "top": "0", "width": "452px", "height": "340px"};
var li4 = {"left": "565px", "top": "75px", "width": "280px", "height": "210px"};
var li5 = {"left": "740px", "top": "110px", "width": "190px", "height": "143px"};
var li6 = {"left": "740px", "top": "110px", "width": "190px", "height": "143px"};


//image states
var im1 = {"width": "188px", "height": "141px"};
var im2 = {"width": "278px", "height": "208px"};
var im3 = {"width": "450px", "height": "338px"};

//shadow states
var sh1 = {"top": "15px", "left": "10px", "width": "202px", "height": "150px"};
var sh2 = {"top": "8px", "left": "7px", "width": "298px", "height": "228px"};
var sh3 = {"top": "0", "left": "0", "width": "482px", "height": "370px"};

function showcase_change(current){
	$("#prev").hide();
	$("#next").hide();
	if($.browser.msie){
		if(current >= 3) $($(".img-shadow li").get(current-3)).animate(li0).css("z-index", "0");
		if(current >= 2) {
			$($(".img-shadow li").get(current-2)).animate(li1).css("z-index", "1");
			$($(".img-shadow img.show").get(current-2)).animate(im1);
			$($(".img-shadow img.shadow").get(current-2)).animate(sh1);
		}
		if(current >= 1){
			$($(".img-shadow li").get(current-1)).animate(li2).css("z-index", "2");
			$($(".img-shadow img.show").get(current-1)).animate(im2);
			$($(".img-shadow img.shadow").get(current-1)).animate(sh2);
		}
		
		$($(".img-shadow li").get(current)).animate(li3).css("z-index", "5");
		$($(".img-shadow img.show").get(current)).animate(im3);
		$($(".img-shadow img.shadow").get(current)).animate(sh3);
		
		if(img_count - current >= 1) {
			$($(".img-shadow li").get(current+1)).animate(li4).css("z-index", "2");
			$($(".img-shadow img.show").get(current+1)).animate(im2);
			$($(".img-shadow img.shadow").get(current+1)).animate(sh2);
		}
		if(img_count - current >= 2) {
			$($(".img-shadow li").get(current+2)).animate(li5).css("z-index", "1");
			$($(".img-shadow img.show").get(current+2)).animate(im1);
			$($(".img-shadow img.shadow").get(current+2)).animate(sh1);
		}
		if(img_count - current >= 3) $($(".img-shadow li").get(current+3)).animate(li6).css("z-index", "0");
		
	} else if($.browser.safari){
		if(current >= 3) $($(".img-shadow li").get(current-3)).animate(li0).css("z-index", "0").fadeOut(1000);
		if(current >= 2) {
			$($(".img-shadow li").get(current-2)).animate(li1).css("z-index", "1").fadeIn(1000);
			$($(".img-shadow img.show").get(current-2)).animate(im1);
			$($(".img-shadow img.shadow").get(current-2)).animate(sh1);
		}
		if(current >= 1){
			$($(".img-shadow li").get(current-1)).animate(li2).css("z-index", "2");
			$($(".img-shadow img.show").get(current-1)).animate(im2);
			$($(".img-shadow img.shadow").get(current-1)).animate(sh2);
		}
		
		$($(".img-shadow li").get(current)).animate(li3).css("z-index", "3");
		$($(".img-shadow img.show").get(current)).animate(im3);
		$($(".img-shadow img.shadow").get(current)).animate(sh3);
		
		if(img_count - current >= 1) {
			$($(".img-shadow li").get(current+1)).animate(li4).css("z-index", "2");
			$($(".img-shadow img.show").get(current+1)).animate(im2);
			$($(".img-shadow img.shadow").get(current+1)).animate(sh2);
		}
		if(img_count - current >= 2) {
			$($(".img-shadow li").get(current+2)).animate(li5).css("z-index", "1").fadeIn(1000);
			$($(".img-shadow img.show").get(current+2)).animate(im1);
			$($(".img-shadow img.shadow").get(current+2)).animate(sh1);
		}
		if(img_count - current >= 3) $($(".img-shadow li").get(current+3)).animate(li6).css("z-index", "0").fadeOut(1000);
	} else {
		if(current >= 3) $($(".img-shadow li").get(current-3)).animate(li0, 1000, "swing").css("z-index", "0").fadeOut(1000);
		if(current >= 2) {
			$($(".img-shadow li").get(current-2)).animate(li1, 1000, "swing").css("z-index", "1").fadeIn(1000);
			$($(".img-shadow img.show").get(current-2)).animate(im1, 1000, "swing");
			$($(".img-shadow img.shadow").get(current-2)).animate(sh1, 1000, "swing");
		}
		if(current >= 1){
			$($(".img-shadow li").get(current-1)).animate(li2, 1000, "swing").css("z-index", "2");
			$($(".img-shadow img.show").get(current-1)).animate(im2, 1000, "swing");
			$($(".img-shadow img.shadow").get(current-1)).animate(sh2, 1000, "swing");
		}
		
		$($(".img-shadow li").get(current)).animate(li3, 1000, "swing").css("z-index", "3");
		$($(".img-shadow img.show").get(current)).animate(im3, 1000, "swing");
		$($(".img-shadow img.shadow").get(current)).animate(sh3, 1000, "swing");
		
		if(img_count - current >= 1) {
			$($(".img-shadow li").get(current+1)).animate(li4, 1000, "swing").css("z-index", "2");
			$($(".img-shadow img.show").get(current+1)).animate(im2, 1000, "swing");
			$($(".img-shadow img.shadow").get(current+1)).animate(sh2, 1000, "swing");
		}
		if(img_count - current >= 2) {
			$($(".img-shadow li").get(current+2)).animate(li5, 1000, "swing").css("z-index", "1").fadeIn(1000);
			$($(".img-shadow img.show").get(current+2)).animate(im1, 1000, "swing");
			$($(".img-shadow img.shadow").get(current+2)).animate(sh1, 1000, "swing");
		}
		if(img_count - current >= 3) $($(".img-shadow li").get(current+3)).animate(li6, 1000, "swing").css("z-index", "0").fadeOut(1000);
	}

	setTimeout(function(){
		animAllowed = true;
		if(current < img_count) $("a#next").show();
		if(current > 0) $("a#prev").show();
	}, 1000);
}



//init
var current = 0;
var animAllowed = true;
var img_count = $(".img-shadow li").length - 1;
for(i = 0; i <= img_count; i++){
	if(i < current - 2)  {
		$($(".img-shadow li").get(i)).css(li0).css("z-index", "0");
		$($(".img-shadow img.show").get(i)).css(im1);
		$($(".img-shadow img.shadow").get(i)).css(sh1);
	} else if(i == current - 2) {
		$($(".img-shadow li").get(i)).css(li1).css("z-index", "1");
		$($(".img-shadow img.show").get(i)).css(im1);
		$($(".img-shadow img.shadow").get(i)).css(sh1);
	} else if(i == current - 1){
		$($(".img-shadow li").get(i)).css(li2).css("z-index", "2");
		$($(".img-shadow img.show").get(i)).css(im2);
		$($(".img-shadow img.shadow").get(i)).css(sh2);
	}	else if(i == current){
		$($(".img-shadow li").get(i)).css(li3).css("z-index", "5");
		$($(".img-shadow img.show").get(i)).css(im3);
		$($(".img-shadow img.shadow").get(i)).css(sh3);
	}	else if(i == current + 1){
		$($(".img-shadow li").get(i)).css(li4).css("z-index", "2");
		$($(".img-shadow img.show").get(i)).css(im2);
		$($(".img-shadow img.shadow").get(i)).css(sh2);
	}	else if(i == current + 2){
		$($(".img-shadow li").get(i)).css(li5).css("z-index", "1");
		$($(".img-shadow img.show").get(i)).css(im1);
		$($(".img-shadow img.shadow").get(i)).css(sh1);
	}	else if(i > current + 2){
		$($(".img-shadow li").get(i)).css(li6).css("z-index", "0");
		$($(".img-shadow img.show").get(i)).css(im1);
		$($(".img-shadow img.shadow").get(i)).css(sh1);
	}
}

$("#prev").click(function(){
	if(current > 0 && animAllowed){
		current--;
		animAllowed = false;
		showcase_change(current);
	}
	return false;
});
$("#next").click(function(){
	if(current < img_count && animAllowed) {
		current++;
		animAllowed = false;
		showcase_change(current);
	}
	return false;
});


});
