var home = {
	setGlobals: function() {
		home.wrapper = jQuery('div#wrapper');
		home.innerWrapper = jQuery('div#inner-wrapper');
		home.header = jQuery('div#header');
		home.contentBody = jQuery('div#content-body');
		home.flashStuntDouble = jQuery('div#flash-stunt-double');
		home.mainFlash = jQuery('div#main-flash');
		home.footer = jQuery('div#footer');
		home.logo = jQuery('a#site-logo');
		home.search = jQuery('div#google-search');
	},
	
	checkForCookie: function() {
		home.animate = 0;
		// if (jQuery.cookie('viewedHome') === '1') {
		// 	home.animate = 0;
		// } else {
		// 	home.animate = 1;
		// 	jQuery('body').css({ backgroundImage: 'url(/images/pic/splash-underpic.jpg)' });
		// 	jQuery.cookie('viewedHome', 1);
		// }
	},
	
	initPage: function() {		
		if(home.animate === 1) {
			home.header.hide();
			home.innerWrapper.hide();
			jQuery('ul#sidenav h3, ul#sidenav > li, ul#faq-sidenav li, ul#sidenav ul[class!="subnav"] li').not(jQuery('ul#sidenav ul.home-stay-open li')).css({ opacity: 0, position: 'relative', left: '-20px' });
			jQuery('#sidenav-box h1').css({ left:'-41px', opacity: 0 });			
			home.wrapper.css({ width: 0, height: '1px' });
			home.footer.hide();
			home.logo.css({ opacity: 0, left: 0 });
			home.search.hide();
		}
	},
	
	animateH1: function() {
		jQuery('#sidenav-box h1').css({ opacity:'0' }).animate({ opacity:'1', left: '0px' }, 600, brizo.easing, function(){
			if(!jQuery('body#essence').length) {
				brizo.showBackLink();
			}			
		});
	},
	
	animateSidenav: function() {	
		var animatedLi = jQuery('ul#sidenav h3, ul#sidenav li, ul#faq-sidenav li').not(jQuery('ul.subnav li'));
		animatedLi.each(function(i){
			var aniDelay = (i+1) * 110;
			var thisLi = jQuery(this);
			setTimeout(function(){
				thisLi.animate({opacity:1, left: 0}, 300, brizo.easing);
				if(i+1 === animatedLi.length) {
					setTimeout(function(){
						// Apply sidenav show/hide
						brizo.setSidenav();
					}, 350);
				}
			}, aniDelay);
		});
	},
	
	show: {
		wrapperX: function(){ home.wrapper.animate({ width: '936px' }, 250, 'easeInQuad'); },
		wrapperY: function(){ home.wrapper.animate({ height: '698px' }, 400, 'easeInQuad'); },
		header: function() { home.header.show(); },
		innerWrapper: function() { home.innerWrapper.show(); },
		logo: function(){ home.logo.animate({ left: '34px', opacity: 1 }, 250, brizo.easing); },
		footer: function(){ home.footer.fadeIn(500);},
		search: function(){ home.search.fadeIn(500);}
	},
	
	loadPage: function() {
		if(home.animate === 1) {
			setTimeout(function(){
				setTimeout(home.show.wrapperX, 1);
				setTimeout(home.show.wrapperY, 250);
				setTimeout(home.show.header, 275);
				setTimeout(home.show.innerWrapper, 275);
				setTimeout(home.show.logo, 600);
				setTimeout(home.animateH1, 500);
				setTimeout(home.animateSidenav, 100);
				setTimeout(home.animateFlash, 900);			
				setTimeout(home.show.footer, 1200);
				setTimeout(home.show.search, 1600);
			}, 600);
		} else {
			home.animateFlash();
		}
	},
	
	animateFlash: function() {
		swfobject.embedSWF("/flash/homepage/HomeVideoPlayer.swf", "main-flash", "640", "440", "9.0.0", "flash/expressinstall.swf", mainFlashvars, mainParams, mainAttributes);
		swfobject.embedSWF('/flash/homepage/HomeSubFeatures.swf', 'bottom-links', '870', '147', '9.0.0', 'flash/expressinstall.swf', linksFlashvars, linksParams, linksAttributes);
	},
	
	videoOverlay: function(){
		
	}
};

jQuery(document).ready(function(){
	home.setGlobals();
	video.setGlobals();
	home.checkForCookie();
	home.initPage();
	home.loadPage();
});