// JavaScript Document

$(document).ready(function(){
	for(var j=1; j<=8; j++){
		if(j<=4) $("div.list-themes-photos div.item-photos-"+j).css({backgroundPosition:""+((j)*(-120))+"px 0px"});
		else $("div.list-themes-photos div.item-photos-"+j).css({backgroundPosition:""+((j)*(120))+"px 0px"});
	}

	
	anim_slogan();
	setTimeout("anim_listPhotos(1)", 5000);
	
	
	// animation menu
	$("div#nav ul li").mouseenter(function(){
		$(this).addClass("on");
		$(this).stop().animate({height:50},{duration:500, easing:"easeOutBounce", complete:function(){
			$(this).css({height:"50px"});
		}});
		$("a", this).stop().animate({paddingTop:20},{duration:500, easing:"easeOutBounce", complete:function(){
			$(this).css({paddingTop:"20px"});
		}});
	});
	$("div#nav ul li").mouseleave(function(){
		$(this).removeClass("on");
		$(this).stop().animate({height:30},{duration:500, easing:"easeOutBounce", complete:function(){
			$(this).css({height:"30px"});
		}});
		$("a", this).stop().animate({paddingTop:0},{duration:500, easing:"easeOutBounce", complete:function(){
			$(this).css({paddingTop:"0px"});
		}});
	});
	
	// fancybox
	$("a.fbox").fancybox({
		'titlePosition' : 'over'
	});
	
});



function anim_listPhotos(i){
	for(var j=1; j<=8; j++){
		if(j<=4) $("div.list-themes-photos div.item-photos-"+j).delay(500+(j*20)).animate({backgroundPosition:"("+((i+j)*(-120))+" 0)"}, {duration:5000, complete:function(k){
			$(this).css({backgroundPosition:""+k+"px 0px"});
		}(((i+j)*(-120)))});
		else $("div.list-themes-photos div.item-photos-"+j).delay(500+(j*20)).animate({backgroundPosition:"("+((i+j)*(120))+" 0)"}, {duration:5000, complete:function(k){
			$(this).css({backgroundPosition:""+k+"px 0px"});
		}(((i+j)*(120)))});
	}
	setTimeout("anim_listPhotos("+(i+1)+")", 10000);
}

function anim_slogan(){
	$("div.slogan p").css({top:"20px", opacity:0});
	$("div.slogan p#slogan1").animate({top:0, opacity:1,'filter': ''},{duration:1000}).delay(2000).animate({opacity:0},{duration:500});	
	$("div.slogan p#slogan2").delay(3000).animate({top:0, opacity:1,'filter': ''},{duration:1000}).delay(2000).animate({opacity:0},{duration:500});	
	$("div.slogan p#slogan3").delay(6000).animate({top:0, opacity:1,'filter': ''},{duration:1000}).delay(3000).animate({opacity:0},{duration:500, complete:function(){
		anim_slogan();
	}});
}


(function($) {
	$.extend($.fx.step,{
	    backgroundPosition: function(fx) {
            if (fx.state === 0 && typeof fx.end == 'string') {
                var start = $.curCSS(fx.elem,'backgroundPosition');
                start = toArray(start);
                fx.start = [start[0],start[2]];
                var end = toArray(fx.end);
                fx.end = [end[0],end[2]];
                fx.unit = [end[1],end[3]];
			}
            var nowPosX = [];
            nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
            nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
            fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

           function toArray(strg){
               strg = strg.replace(/left|top/g,'0px');
               strg = strg.replace(/right|bottom/g,'100%');
               strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
               var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
               return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
           }
        }
	});
})(jQuery);
