// JavaScript Document

var stageWidth;
var stageHeight;
var currentPage = 'home';
var cookieFound = true;
var brs;

$(document).ready(function() {
	//getSetCookie();
	
	stageWidth = $(window).width();
	stageHeight = $(window).height();
	resizeAll();
	initValues();
	
	$(window).resize(function() {
		stageWidth = $(window).width();
		stageHeight = $(window).height();
		resizeAll();
	});
	
	brs = browserDetect();
	startLoading();
	addListeners();
});

function getSetCookie() {
	var cookie = 'beetlebailey';
	var options = { path: '/', expires: 1 };
	
	if ($.cookie(cookie) == null) {
		$.cookie(cookie, 'visited', options); 
	} else {
		cookieFound = true;
	}
}

function browserDetect() {
	var agt=navigator.userAgent.toLowerCase();
	if (agt.indexOf("msie") != -1) return 'IE';
}

function init() {
	stageWidth = $(window).width();
	stageHeight = $(window).height();
	resizeAll();
	setTimeout(animateIn, 500);
}

function resizeAll() {
	if (stageHeight > 700) $('#background').height(stageHeight-145);
	else $('#background').height(600);
}

function animateIn() {
	$('#hhBorder').delay(800).animate({opacity:1, specialEasing:{opacity:'easeInCirc'}}, 1500);
	$('#hhLogo').animate({opacity:1, marginTop:"-5px", specialEasing:{opacity:'easeInCirc'}}, 800);
	$('#hhTag').delay(600).animate({opacity:1, specialEasing:{opacity:'easeInCirc'}}, 600);
	$('.navAbout').delay(1300).animate({opacity:1, specialEasing:{opacity:'easeInExpo'}}, 1000);
	$('.navTimeline').delay(1800).animate({opacity:1, specialEasing:{opacity:'easeInExpo'}}, 1000);
	$('.navNews').delay(2300).animate({opacity:1, specialEasing:{opacity:'easeInExpo'}}, 1000);
	$('.navBlog').delay(2800).animate({opacity:1, specialEasing:{opacity:'easeInExpo'}}, 1000);
	$('#footer').delay(3300).animate({opacity:1, specialEasing:{opacity:'easeInExpo'}}, 1000);
}

function initValues() {
	if (cookieFound != true) {
		$('#hhBorder').animate({opacity:0}, 1);
		$('#hhLogo').animate({opacity:0}, 1).css("margin-top","150px");
		$('#hhTag').animate({opacity:0}, 1);
		$('.navAbout').animate({opacity:0}, 1);
		$('.navTimeline').animate({opacity:0}, 1);
		$('.navNews').animate({opacity:0}, 1);
		$('.navBlog').animate({opacity:0}, 1);
		$('#footer').animate({opacity:0}, 1);
	}
	$('#content').delay(100).css("visibility", "visible");
}

function addListeners() {
	$('.navAbout').hover(function() {
		$(this).children('.hide').fadeIn(1000);
	}, function() {
		$(this).children('.hide').fadeOut(1000);
	});
	
	$('.navTimeline').hover(function() {
		$(this).children('.hide').fadeIn(1000);
	}, function() {
		$(this).children('.hide').fadeOut(1000);
	});
	
	$('.navNews').hover(function() {
		$(this).children('.hide').fadeIn(1000);
	}, function() {
		$(this).children('.hide').fadeOut(1000);
	});
	
	$('.navBlog').hover(function() {
		$(this).children('.hide').fadeIn(1000);
	}, function() {
		$(this).children('.hide').fadeOut(1000);
	});
	
	if (brs != 'IE') {
		$('.navAbout').touchlink('about');
		$('.navTimeline').touchlink('timeline');
		$('.navNews').touchlink('news');
		$('.navBlog').touchlink('blog');
	}
}
