$(function(){
	Page.Sizing.init();
	
	if (typeof sIFR == "function"){
		sIFR.replaceElement(named({sSelector:"body h1.sifrText", sFlashSrc:"_assets/flash/gothamMedium.swf", sColor:"#cc0000", sLinkColor:"#000000", sBgColor:"#FFFFFF", sHoverColor:"#CCCCCC", nPaddingTop:0, nPaddingBottom:0, sWmode:'transparent', sFlashVars:""}));
		sIFR.replaceElement(named({sSelector:"body h3.sifrText", sFlashSrc:"_assets/flash/gothamBook.swf", sColor:"#444444", nPaddingTop:0, nPaddingBottom:0, sWmode:'transparent', sFlashVars:""}));
		sIFR.replaceElement(named({sSelector:"body h2.sifrText", sFlashSrc:"_assets/flash/gothamBook.swf", sColor:"#444444", nPaddingTop:0, nPaddingBottom:0, sWmode:'transparent', sFlashVars:""}));
		sIFR.replaceElement(named({sSelector:"body h4.sifrText", sFlashSrc:"_assets/flash/gothamBook.swf", sColor:"#cc0000", sLinkColor:"#000000", sBgColor:"#FFFFFF", sHoverColor:"#CCCCCC", nPaddingTop:0, nPaddingBottom:0, sWmode:'transparent', sFlashVars:""}));
	}	
	
	function menuInit(arrayOfItems) {
		arrayOfItems.each(function(index) {
			$(this).mouseover(function(event) {
					var hook = $(this).attr('hook');
					var $tabs = $('.menuContent');
					$menuItems.each(function(index) {				 
						$(this).attr('class', '');
						$(this).stop();
					});
					$(this).attr('class', 'selected');
					$(this).animate({ opacity: '1' }, 'fast');
					$menuItems.each(function(index) {
						var className = $(this).attr('class');
						if(className != 'selected')
							$(this).animate({ opacity: '.3' }, 'fast');					 
					});
					$tabs.each(function(index) {
						var id = $(this).attr('id');
						if(id == hook) {
							$(this).css('display', 'block');
							$(this).css('left', '0px');
						}
						else {
							$(this).css('display', 'none');
							$(this).css('left', '-9999px');
						}
					});
			});
		});	
	}

	setTimeout("hideTabs()", 500);
	
	
	var $menuItems = $('#ucMenu > li ');
	menuInit($menuItems);
	/** initial option **/
	
	var $leftColumn = $('#leftColumn');
	
	$leftColumn.hover(function() {
			var hideTimer = setTimeout("resetTabs()",500);
			clearTimeout(hideTimer);
			//clearTimeout(scrollingTimer);
	}, function() {
			hideTimer = setTimeout("resetTabs()",500);
	});

});

function hideTabs() {
	var $tabs = $('.menuContent');
	$tabs.each(function(index) {				 
		$(this).css('display', 'none');
	});
	var $initialItem = $('ul#ucMenu li:eq(0)');
	$initialItem.addClass('selected');
	var $tabInitial = $('div#tab1');
	$tabInitial.css('display', 'block');
	$tabInitial.css('left', '0px'); 
	
}

function resetTabs() {
	var $tabs = $('.menuContent');
	var $menuItems = $('#ucMenu > li');
	
	$tabs.each(function(index) {
		var left = $(this).css('left');
		if(left != '-9999px'){
			$(this).css('display', 'none');
			$(this).css('left', '-9999px');
			//$(this).animate({ opacity: '0' }, 'slow', function() { $(this).css('left', '-9999px'); $(this).fadeTo('fast', 1); });
		}
	});
	
	$menuItems.each(function(index) {
		$(this).fadeTo('slow', 1);
		$(this).attr('class', '');
	});
}

$(window).resize(function(){
	Page.Sizing.resize();
});

Page = {};
Page.Sizing = {

	init: function(){
		this.body = $('body');
		this.initHeight = $(document).height();
		this.resize();
	},
	
	resize: function(){
		if (!this.body.get(0)) return;
		var windowHeight = $(window).height();
		var bodyHeight = windowHeight > this.initHeight ? windowHeight : this.initHeight;
		this.body.height(bodyHeight);
	}

}
