/*!
 * jQuery Ck's Vitrine for Seed APS website 1.0.0
 * http://www.seed.com.br/
 *
 * Copyright 2011, Christoffer Kraus
 * http://c2kraus.wordpress.com/
 *
 * Date: Sun Mar 27 16:53:12 2011 -0300
 */

var nextstand = '.left'; var autoclick = true;
function stand() { 
	$(nextstand).click(); 
	nextstand = nextstand == '.right' ? '.left' : '.right';
}
	
$(document).ready(function() {
	var stand = setInterval('stand()',7500);
	
	$( ".stand" ).hide();
	$( ".text" ).hide();
	$( ".stand" ).fadeTo("slow", 1);
	$( ".stand:eq(0)" ).animate({ width:264, height:176, left:15, top:19 }, 800);
	$( ".stand:eq(2)" ).animate({ width:330, height:220, left:50, top:0 }, 800);
	$( ".stand:eq(1)" ).animate({ width:297, height:198, left:120, top:10 }, { 
		duration:800, complete: function(now, fx) {
			$( ".text:eq(2)" ).fadeTo(900, 1);
		}
	});
	$( ".stand:eq(0)" ).addClass('left').css("z-index",10);
	$( ".stand:eq(2)" ).addClass('center').css("z-index",30);
	$( ".stand:eq(1)" ).addClass('right').css("z-index",20);
	
	var animate = false;
	$(".stand" ).click(function(){
		if (animate) { return false }
		if (stand) clearInterval(stand)
		stand = setInterval('stand()',15000);
		
		if (!$(this).hasClass("center")) {
			animate = true;
			if ($(this).hasClass("left")) {
				$(".right").animate({ left:450 }, 500);
				$("#text"+$(".center").attr("id").substr(5)).fadeTo(900,0);
	
				$(this).animate({ left:-249 },
				{ duration:500, complete: function( now, fx ){				
					$(this).removeClass("left"); $(this).removeClass("center"); $(this).removeClass("right");
					$(".center").addClass("left"); $(".center").removeClass("center"); $(".center").removeClass("right");
					$(".left").css("z-index",10)
					$(this).css("z-index",30);
		
					$(this).animate({ width:330, height:220, left:50, top:0 },
					{ duration:800, complete: function( now, fx ){
						animate = false;
					}});
					$(".left").animate({ width:264, height:176, left:15, top:19 }, 800);
					$(".right").animate({ left:120 }, 800);
					$(this).addClass("center");
					$("#text"+$(".center").attr("id").substr(5)).fadeTo(900,1).css("z-index",2);
					$("#text"+$(".left").attr("id").substr(5)).fadeTo(0,0).css("z-index",1);
					$("#text"+$(".right").attr("id").substr(5)).fadeTo(0,0).css("z-index",1);
				}});
			}
			else {
				$(".left").animate({ left:-249 }, 500);
				$("#text"+$(".center").attr("id").substr(5)).fadeTo(900,0);
							
				$(this).animate({ left:450 },
				{ duration:500, complete: function( now, fx ){
					$(this).removeClass("right"); $(this).removeClass("center"); $(this).removeClass("left"); 
					$(".center").addClass("right"); $(".center").removeClass("center"); $(".center").removeClass("left");
					$(".right").css("z-index",20)
					$(this).css("z-index",30);
	
					$(this).animate({ width:330, height:220, left:50, top:0 },
					{ duration:800, complete: function( now, fx ){
						animate = false;
					}});
					$(".right").animate({ width:297, height:198, left:120, top:10 }, 800);
					$(".left").animate({ left:15 }, 800);
					$(this).addClass("center");
					$("#text"+$(".center").attr("id").substr(5)).fadeTo(900,1).css("z-index",2);
					$("#text"+$(".left").attr("id").substr(5)).fadeTo(0,0).css("z-index",1);
					$("#text"+$(".right").attr("id").substr(5)).fadeTo(0,0).css("z-index",1);
				}});
			}
		}
		else {
			var standlink = $("#text"+ $(".center").attr("id").substr(5) +" h2 a").attr("href");
			if (standlink != "") {
				window.location = standlink + "img";
			}
			else {
				animate = true;
				$("#text"+$(".center").attr("id").substr(5)).fadeTo(900,1).css("z-index",2);
				$("#text"+$(".left").attr("id").substr(5)).fadeTo(0,0).css("z-index",1);
				$("#text"+$(".right").attr("id").substr(5)).fadeTo(0,0).css("z-index",1);
				
				$( ".left" ).animate({ width:264, height:176, left:15, top:19 }, 0).css("z-index",10);
				$( ".right" ).animate({ width:297, height:198, left:120, top:10 }, 0).css("z-index",20);
				$( ".center" ).animate({ width:330, height:220, left:50, top:0 },
				{ duration:0, complete: function( now, fx ){
					animate = false;
				}}).css("z-index",30);
			}
		}
	});
	
	
	$( ".stand" ).hover(function(){
		$(this).addClass('hover')},function(){
		$(this).removeClass('hover')
	});

});
