$(document).ready(function(){
	$("#nav ul.nav").superfish();
	
	$("#Home-template #left a:even").addClass("even");
	$("#Home-template #left a:odd").addClass("odd");
			
	if ($("a[target='_blank'] img")) {
		$("a[target='_blank'] img").parent('a').attr({ rel: "prettyOverlay" });
		prettyPhoto.init();
	}
	
	
	// Setup header	
	var minWidth = 900;
	var smallHeight = 200;
	var minWindowHeight = 600;
	
	// Banner turned off for now
	var div = $("#banner not here");
	if (div) {
		var img = div.children("div img:first");
		var imgHeight = img.height();
		if (img && img.width() > minWidth && imgHeight > smallHeight) {
			div.css( { overflow: "hidden", height: imgHeight } );
			div.addClass('animate');
		}
	}
	
	var resizeHeader = function() {
		if ($(window).height() < minWindowHeight) {
			$(function(){$('.animate').animator(1, expandHeader);});
			saveWindowHeight();
		}
		else {
			$(function(){$('.animate').animator(1, contractHeader);});
			saveWindowHeight();
		}
	};
	
	function expandHeader(Walker, GoEnd){
		newHeight = parseInt(Walker.css("height")) - 1;
		if(GoEnd) newHeight = smallHeight;
		if (newHeight > smallHeight) Walker.css("height", newHeight);
		return (newHeight > smallHeight);
	}
	function contractHeader(Walker, GoEnd){
		newHeight = parseInt(Walker.css("height")) + 1;
		if(GoEnd) newHeight = imgHeight;
		if (newHeight < imgHeight) Walker.css("height", newHeight);
		return (newHeight < imgHeight);
	}
	
	
	$(window).resize(resizeHeader);
	
	if ($(window).height() < minWindowHeight) {
		div.css( { height: smallHeight });
	}
	
	function saveWindowHeight() {
		createCookie("windowHeight", $(window).height(), 30);
	}
	
	function createCookie(name,value,days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	}



});