/**
 * @classDescription	Common methods used throughout site
 * @author				Kevin Sweeney
 * @version				1.0
 */

var Global = {};

// Properties __________________________________________________________________

Global.initialNavBorderWidth = $('#navBorder').width();

// Methods _____________________________________________________________________

Global.createElements = function () {
	$('a[rel="external"]').attr('target', '_blank');
};

Global.registerEvents = function () {
	$('a', '#mainMenu').hover(Global.onMenuItemOver, Global.onMenuItemOut);
	$(window).bind('resize', Global.onWindowResized);
	$('a', '#footerLinks').bind('click', Global.onFooterLinkClick);
};

Global.checkFooterPosition = function () {
	
	var bodyTallerThanWindow = $('div.wrapper').height() > window.innerHeight;
	if (bodyTallerThanWindow === false) {
		$('#pageFooter').addClass('anchored');
	}
	else if ($('#pageFooter').hasClass('anchored')) {
		$('#pageFooter').removeClass('anchored');
	}
	
};

Global.warnIE = function () {
	$.cookie('warnIE', '1');
	alert("Looks like you're using Internet Explorer. That's fine, but this site probably won't run as well because IE doesn't support HTML5 or CSS3. I recommend giving the site a spin with Firefox, Chrome or Safari!")
};

// Event Handlers ______________________________________________________________

Global.onMenuItemOver = function (e) {
	var newWidth = $(this).offset().left + $(this).width() - 20;
	$('#navBorder').stop().animate({
		'width': newWidth + 'px'
	}, 125);
};

Global.onMenuItemOut = function (e) {
	$('#navBorder').stop().animate({
		'width': Global.initialNavBorderWidth + 'px'
	}, 500);
};

Global.onWindowResized = function (e) {
	Global.checkFooterPosition();
	try {
		_gaq.push(['_trackEvent', 'User Interaction', 'Resize Browser']);
	}
	catch (e) {}
};

Global.onFooterLinkClick = function (e) {
	try {
		_gaq.push(['_trackEvent', 'Navigation', 'Footer Link Click', $(this).attr('href')]);
	}
	catch (e) {}
};

// Initialization ______________________________________________________________

Global.initialize = function () {
	
	Global.createElements();
	Global.registerEvents();
	Global.checkFooterPosition();
	
	if ($.browser.msie && (!$.cookie('warnIE'))) {
		Global.warnIE();
	}
	
};

$(document).ready(Global.initialize);
