jQuery(document).ready(
	function(){
		var isiPad = navigator.userAgent.match(/iPad/i) != null;
		var isiPhone = navigator.userAgent.match(/iPhone/i) != null;
		if(!isiPad && !isiPhone){
			SocialButton.init();
			ProjectButton.init();
		}
		SiteAnimation.init();
	}
);

var LogoAnimation = {
	interval : null,
	currentImage : 0,
	init : function(){
		LogoAnimation.interval = setInterval('LogoAnimation.animate()',750/14)
	},
	animate : function(){
		if(LogoAnimation.currentImage<13){
			LogoAnimation.currentImage++;
		}else{
			LogoAnimation.currentImage = 13;
			clearInterval(LogoAnimation.interval);
		}
		var newPos = LogoAnimation.currentImage*400;
		jQuery(".logo_halo h1").css( 'background-position', 'center -'+newPos+'px' );
	}
}

var SocialButton = {
	init: function(){
		jQuery(".social_link").mouseenter(
	    	function(){
	    		jQuery(this).children("img").fadeIn(250);
	    	}
	    ).mouseleave(
	    	function(){
	    		jQuery(this).children("img").fadeOut(250);
	    	}
	    );
	}
}

var SiteAnimation = {
	init : function(){
		SiteAnimation.resize();
		jQuery(window).resize(function(e){
			SiteAnimation.resize();
		});
		var isiPad = navigator.userAgent.match(/iPad/i) != null;
		var isiPhone = navigator.userAgent.match(/iPhone/i) != null;
		if(isiPad || isiPhone){
			SiteAnimation.reset();			
		}else{
			SiteAnimation.start();
		}
	},
	start : function(){
		jQuery('.logo_halo').delay(500).fadeTo(1000, 1.0,'easeInOutQuad',function(){
			LogoAnimation.init();
		});
		jQuery('#bottom_box').delay(750).fadeTo(750, 1.0,'easeInOutQuad');
		jQuery("#bottom_box").delay(250).animate({ bottom : "26px"}, 1000, 'easeInOutQuad');
	},
	reset : function()
	{
		jQuery('.logo_halo').fadeTo(0, 1.0,'easeInOutQuad');
		jQuery('.logo_halo h1').fadeTo(0, 1.0,'easeInOutQuad');
		jQuery('.logo_halo h1').css('background','url(wp-content/themes/lj2012/images/LaJungle.png) center top no-repeat');
		jQuery('#bottom_box').fadeTo(0, 1.0,'easeInOutQuad');
		jQuery("#bottom_box").css({ bottom : "26px"});
	},
	resize : function(){
		var isiPad = navigator.userAgent.match(/iPad/i) != null;
		var isiPhone = navigator.userAgent.match(/iPhone/i) != null;
		var documentHeight = jQuery(document).height();
		var topPositionLogo = (documentHeight>640) ? (- 460 + ((documentHeight-400)*.25)) : -400;
		if(documentHeight<765){
			var bottomPosition = parseInt(jQuery("#bottom_box").css('bottom'));
			jQuery("#bottom_box").css({ height : "555px" });
			jQuery("#lastest > section.header").css({ marginTop : "30px"});
			jQuery(".logo_halo").css({ top : topPositionLogo+"px"});
			if(bottomPosition<26){
				jQuery("#bottom_box").css({ bottom : '-229px' });
			}
		}else{
			jQuery("#bottom_box").css({ height : "600px"});
			jQuery("#lastest > section.header").css({ marginTop : "48px"});
			jQuery(".logo_halo").css({ top : topPositionLogo + "px"});
		}
		if(isiPad){
			if(documentHeight>1000){
				jQuery(".logo_halo h1").css("-webkit-background-size","auto auto");
				jQuery(".logo_halo").css({ top : topPositionLogo + "px"});
			}else{
				jQuery(".logo_halo h1").css("-webkit-background-size","45% auto");
				jQuery(".logo_halo").css({ top : "-340px"});
			}
		}
		if(isiPhone){
			if(documentHeight<750){
				jQuery("#lastest").css({ 'display' : "none"});
				jQuery(".logo_halo h1").css("-webkit-background-size","45% auto");
				jQuery(".logo_halo").css({ top : "-340px"});
				jQuery("#bottom_box").css({ height : "300px"});
				jQuery("#bottom_box").css({ overflow : "hidden"});
			}else{
				jQuery(".logo_halo h1").css("-webkit-background-size","auto auto");
				jQuery("#lastest").css({ 'display' : "block"});
				jQuery("#bottom_box").css({ overflow : "scroll"});
			}
		}
	}
}

var ProjectButton = {
	init : function(){
		jQuery(".project").mouseenter(
			function(){
				var bottom = jQuery(this).children("div.thumb").children(".bottom");
				var top = jQuery(this).children("div.thumb").children(".top");
				var left = jQuery(this).children("div.thumb").children(".left");
				var right = jQuery(this).children("div.thumb").children(".right");
				var title = jQuery(this).children("div.project_title").children(".face1");
				var title2 = jQuery(this).children("div.project_title").children(".face2");
				top.stop();  left.stop(); right.stop(); title.stop(); title2.stop(); bottom.stop();
				bottom.animate({ bottom : "0px" },500,'easeOutQuad');
				top.animate({ top : "0px" },500,'easeOutQuad');
				left.animate({ left : "0px" },500,'easeOutQuad');
				right.animate({ right : "0px" },500,'easeOutQuad');
				title.animate({ top : "-18px"},250,'easeOutQuad');
				title2.animate({ top : "-18px"},250,'easeOutQuad');
			}
		).mouseleave(
			function(){
				var bottom = jQuery(this).children("div.thumb").children(".bottom");
				var top = jQuery(this).children("div.thumb").children(".top");
				var left = jQuery(this).children("div.thumb").children(".left");
				var right = jQuery(this).children("div.thumb").children(".right");
				var title = jQuery(this).children("div.project_title").children(".face1");
				var title2 = jQuery(this).children("div.project_title").children(".face2");
				var borderSize = bottom.height();
				top.stop(); left.stop(); right.stop(); title.stop(); title2.stop(); bottom.stop();
				bottom.animate({ bottom : "-"+borderSize+"px" },250,'easeOutQuad');
				top.animate({ top : "-"+borderSize+"px" },250,'easeOutQuad');
				left.animate({ left : "-"+borderSize+"px" },250,'easeOutQuad');
				right.animate({ right : "-"+borderSize+"px" },250,'easeOutQuad');
				title.animate({ top : "0px"},250,'easeOutQuad');
				title2.animate({ top : "0px"},250,'easeOutQuad');
			}
		);
	}
}

