Cufon.replace('#header .slogan', { fontFamily: 'EdScript', fontSize: '40px', hover: true});

$(document).ready( function() {
	DisplayNavigation();		
	DisplayTab();
	ResizeFont();
	//$("#bg-container img").hide();
	//$("#bg-container").readydiv(function() { ResizeHandler(); });
	$("#content").readydiv(function() { ContentSlideIn(); });
});

$(window).resize(function(){
  ResizeHandler();
});

function ContentSlideIn() 
{ 
	$(window).load(function() {
		if($("#site.home").length > 0) 
		{
		  ResizeHandler();  
			
			var ContentElement = $("#content");	
			var SubMenuElement = $("#submenu");	
			
			var ContentHeight  = ContentElement.outerHeight() + 10;
			var SubMenuHeight  = SubMenuElement.outerHeight() + 10;
	
			ContentElement.css("top", "-" + ContentHeight + "px");
			SubMenuElement.css("top", "-" + SubMenuHeight + "px");
			
			setTimeout(function(){
				ContentElement.animate({top: "0px"}, 
															((ContentHeight / 200) * 200));
														
				SubMenuElement.animate({
					top: "0px"
				}, {queue: false });	
			}, 1000);
		}
	});  
}

function DisplayNavigation()
{
	var NavigationElement 		 = $("a.slide");
	var SubNavigationContainer = $("ul.sub");
		
	NavigationElement.each(function(){
		NavigationElement.hover(function() {
			$(this).next("ul.sub").animate({
				height: $(this).next("ul")[0].scrollHeight + "px"
			}, {queue: false });	
		}, function() {
			$(this).next("ul.sub").animate({
				height: "0px"
			}, {queue: false });	
		});

		SubNavigationContainer.hover(function() {
			$(this).stop();
			$(this).animate({
				height: $(this)[0].scrollHeight + "px"
			}, {queue: false });	
		}, function() {
			$(this).animate({
				height: "0px"
			}, {queue: false });	
		});
	});			
}

var bSlideBack = true;

function DisplayTab()
{
	var TabContentElement = $("#tabcontent");
	var TabElement 				= $("#tabcontent .tab");
	
	TabContentElement.find(".content").hover(function() {
		bSlideBack = false;
	}, function() { 
		bSlideBack = true;
	});
	
	if($("#site.home").length > 0) {
		TabContentElement.animate({
			right: "0px"
		}, {queue: false });		
		
		setTimeout(function(){
			if(bSlideBack) {
	      TabContentElement.animate({
					right: "-" + TabContentElement.find(".content").outerWidth()
				}, {queue: false });
			}
    },6000);
  } 
	
	TabElement.click(function() {
		if($(this).parent().css("right") == "0px") {
			$(this).parent().animate({
				right: "-" + $(this).next(".content").outerWidth()
			}, {queue: false });	
		} else {
			$(this).parent().animate({
				right: "0px"
			}, {queue: false });		
		}	
	});	
}

var bFadeIn = true;

function ResizeHandler() { 
	var ContentContainer				= $("#content-container");
	var BackContainer						= $("#bg-container");
	var BackContainerImage			= $("#bg-container img");
	var ImageWidth							= $("#bg-container img").width();
	var ImageHeight							= $("#bg-container img").height();

	var ContentContainerHeight  = parseInt(ContentContainer.outerHeight()); 
	var ContentContainerWidth   = parseInt(ContentContainer.outerWidth());
	
	BackContainer.css("overflow", "hidden");
	BackContainerImage.css("position", "absolute");
	
	var SiteHeight 							= parseInt($("#site").innerHeight());
	var HeaderContainerHeight		= parseInt($("#header-container").outerHeight());
	var FooterContainerHeight		= parseInt($("#footer-container").outerHeight());

	var ContainerHeight					= SiteHeight - HeaderContainerHeight - FooterContainerHeight;
	
	BackContainer.height(ContainerHeight); // set height of the container so no scrollbar is measured
	
	var WindowHeight 						= parseInt($(window).height());
	var WindowWidth 						= parseInt($(window).width());
	
	BackContainer.width(WindowWidth);
	BackContainer.css("width", "100%");

	if(WindowWidth < ContentContainerWidth) {
		BackContainerImage.css('width', ContentContainerWidth + "px");
	} else {
		BackContainerImage.css('width', WindowWidth + "px");
	}
	
	if($.browser.msie && $.browser.version < 7.0) { // IE6 does not correctly implement width:100%
		BackContainer.css("width", BackContainerImage.width() + "px");
	}

	var NewImageHeight = GetDimensionChange(ImageWidth, BackContainerImage.width(), ImageHeight);
	if(NewImageHeight > ContainerHeight) {
		BackContainerImage.css("top", (Math.floor(NewImageHeight - ContainerHeight) / 2) * -1 + "px");
		BackContainerImage.height(NewImageHeight);
		BackContainerImage.css("left", "0px");
	} else {
		BackContainerImage.css("top", "0px");
		BackContainerImage.height(ContainerHeight);
		var NewImageWidth = GetDimensionChange(ImageHeight, ContainerHeight, ImageWidth);
		BackContainerImage.width(NewImageWidth);
	  if(WindowWidth < ContentContainerWidth) {
	  	BackContainerImage.css("left", (Math.floor(NewImageWidth - ContentContainerWidth) / 2) * -1 + "px");
	  } else {
	  	BackContainerImage.css("left", (Math.floor(NewImageWidth - WindowWidth) / 2) * -1 + "px");
	  }
	}

	if(bFadeIn) {
		BackContainerImage.animate({opacity: 1}, "slow");	
		bFadeIn = false;
	}
}

function GetDimensionChange(SrcDimension, NewDimension, DimensionValue)
{
	return DimensionValue * (NewDimension/SrcDimension);
}

function ResizeFont()
{
	if($.cookie("TEXT_SIZE")) {
		$("#content").addClass($.cookie("TEXT_SIZE"));
		$("#content p").addClass($.cookie("TEXT_SIZE"));	
		$("#tabcontent").addClass($.cookie("TEXT_SIZE"));	
		$("#submenu").addClass($.cookie("TEXT_SIZE"));	
		$("#extranav").addClass($.cookie("TEXT_SIZE"));	
		$("#navigation").addClass($.cookie("TEXT_SIZE"));	
		$(".resizer li." + $.cookie("TEXT_SIZE")).addClass("current");
	} else {
		$(".resizer li.small").addClass("current");
	}
	ChangeFont($.cookie("TEXT_SIZE"));
	
	$(".resizer a").click(function() {
		$(".resizer li").each(function () {
			$(this).removeClass("current ");
		});
				
		var textSize = $(this).parent().attr("class");
		ChangeFont(textSize);
		
		$(this).parent().addClass("current");
		
		$.cookie("TEXT_SIZE", textSize, { path: "/", expires: 10000 });

		ResizeHandler();
		
		

		return false;
	});
}

function ChangeFont(textSize) 
{
	if(textSize == "large") {
		$("#content").css("font-size", "16px");
		$("#content").css("line-height", "22px");
		
		$("#tabcontent").css("font-size", "16px");
		$("#tabcontent").css("line-height", "22px");
		
		$("#submenu").css("font-size", "16px");
		$("#submenu").css("line-height", "22px");
		
		$("#extranav").css("font-size", "14px");

		$("#navigation").css("font-size", "16px");
	} else {
		$("#content").css("font-size", "12px");
		$("#content").css("line-height", "16px");
		
		$("#tabcontent").css("font-size", "12px");
		$("#tabcontent").css("line-height", "16px");
		
		$("#submenu").css("font-size", "12px");
		$("#submenu").css("line-height", "16px");
		
		$("#extranav").css("font-size", "10px");

		$("#navigation").css("font-size", "12px");
	}
		
	if($.browser.msie && $.browser.version == '6.0'){
    var FooterHtml = $('#footer-container').html();
    $('#footer-container').remove();
    $('#site').append('<div id="footer-container"></div>');
    $('#footer-container').html(FooterHtml);
  }
}

// cookie script
jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options.expires=-1}var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000))}else{date=options.expires}expires='; expires='+date.toUTCString()}var path=options.path?'; path='+(options.path):'';var domain=options.domain?'; domain='+(options.domain):'';var secure=options.secure?'; secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('')}else{var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break}}}return cookieValue}};
