function revert(u){ //kártya anim
	u = u ? u : 400;
	$(".section").each(function(i){
		$(this).removeClass("wide").css("z-index","50").css("top",0).animate({
			width: "144px",
			height: "160px",
			left: i * 185 + "px"
		},u);
	})		
}

var im,nn;
function fadeImg(){
	$(im[nn]).fadeOut();
	nn++;
	if(nn == im.length) nn = 0;
	$(im[nn]).fadeIn();
	setTimeout(fadeImg,5000);	
}

function countdown(){ //visszaszámlálás
	var d = new Date(2009,06,14);
	var today = new Date();
	var day = 1000*60*60*24;
	var diff = Math.ceil( ( d.getTime() - today.getTime() )/day );
	$("#countdown").text("– "+diff+" days remaining");
}

$(window).load(function(){
	$("#loader").css("display","none");
})

function mainPage(){

	im = $("#showreel img").get(); nn = 0;
	fadeImg();
	//countdown();
	$(".submenus a").click(function(){
		$(this).siblings().removeClass("current");
		$(this).addClass("current");
		var i = $(this).attr("href");
			if(i == "#where"){
				$(i).children("iframe").css("display","block");
			}
		var s = $(this).parent().parent().children(".slide");
		if($(i).css("display") != "block") {
			s.slideUp(200);
			$(i).slideDown(300);
			return false;
		}
	})

	$(".section").click(function(){
	
		var p = $(this);
		if(!p.hasClass("wide")) {
		
			revert(0);
			p.css("z-index","400").animate({
				width: "490px",
				height: "300px",
				left: "184px",
				top: "-60px"
			},400,"swing",function(o){$(this).addClass("wide")})
			
			var s = $(p.prevAll().get().reverse()).add(p.nextAll());
			s.each(function(i){
				if(i < 2) {c = 0;z=1}else {c = 465;z= -1} 
				$(this).css("z-index",50+((i+1)*z*10)).removeClass("wide").animate({
					left:  c+(i*184)/2 +"px",
					top: 0,
					height: "160px"
				});
			});
		} else {
			revert(400);			
		}
	})	
}

function ready(){
			$("#loader").css("display","block");
			
			Cufon.replace('h2,h3, span.black, span.normal, th, span.time, #apply, #bigapply', { fontFamily: 'MyriadPro' });
		   
		   var lb = $("a.lb");
		   if(lb.length != 0)
		   lb.lightBox({
			overlayBgColor: '#000',
			overlayOpacity: 0.6,
			imageLoading: 'images/loading.gif',
			imageBtnClose: 'images/close.gif',
			imageBtnPrev: 'images/prev.gif',
			imageBtnNext: 'images/next.gif',
			containerResizeSpeed: 350,
			txtImage: '',
			txtOf: ' - '
		   });	
}

		$(document).ready(ready);
