
// force ie to enable image caching
try { document.execCommand( "BackgroundImageCache", false, true); } catch(e) {};

// remove ie6 stylesheet if not ie6 or worse
// implementing in javascript because WebDNA tries to parse IE conditional comments in HTML
if(!($.browser.msie && $.browser.version < 7)) {
	$("#ie6stylesheet").remove();
}

$("#container").ready(function () {
	// restyle page if too short to display everything
	if(getHeight() < 580) {
		$("#container").addClass("short");
	}
});


$(document).ready(function(){
	$("#footer").hide();
	if(window.location.href.indexOf("nosplash") > 0) {
		hideSplash();
	}


	// animate menu buttons
	$(".menubutton").each(function(i) {
		$(this).css({ backgroundPositionY: "0px" });
		
		if($.browser.mozilla) {
			$(this).bind("mouseover", function() {
				$(this).css({
					backgroundPosition: "0px -16px"
				});
			});
			$(this).bind("mouseout", function() {
				$(this).css({
					backgroundPosition: "0px 0px"
				});
			});
			$(this).bind("mousedown", function() {
				$(this).css({
					backgroundPosition: "0px -16px"
				});
			});
		} else {
		
			$(this).bind("mouseover", function() {
				$(this).animate({
					backgroundPositionY: "-16px"
				}, 100);
			});

			$(this).bind("mouseout", function() {
				$(this).animate({
					backgroundPositionY: "0px"
				}, 100);

			});
			$(this).bind("mousedown", function() {
				$(this).animate({
					backgroundPositionY: "-16px"
				}, 100);

			});
		}
	});
	
	// set map opening action
	$("#showmap").bind("click", function() {
		window.location.href = "about.html";
	});
	
	// turn on gallery lightbox
	if($('.gallery a').length > 0) {
		$('.gallery a').lightBox();
	}
	if($('.press a').length > 0) {
			$('.press a').lightBox();
	}
	
	if($('.gallery2 a').length > 0) {
		$('.gallery2 a').lightBox();
	}
	if($('.press a').length > 0) {
			$('.press a').lightBox();
	}
	
	if($('.gallery3 a').length > 0) {
		$('.gallery3 a').lightBox();
	}
	if($('.press a').length > 0) {
			$('.press a').lightBox();
	}
	
//take care of input actions
	$("#mailinglist-email").focus(function() {
		if($(this).val() == "your@email.com") {
			$(this).val("");
		} else {
			$(this).select();
		}
	});
	$("#mailinglist-email").blur(function() {
		if($(this).val() == "") {
			$(this).val("your@email.com");
		}
	});
	$("#mailinglist-name").focus(function() {
		if($(this).val() == "your name") {
			$(this).val("");
		} else {
			$(this).select();
		}
	});
	$("#mailinglist-name").blur(function() {
		if($(this).val() == "") {
			$(this).val("your name");
		}
	});
	
	// de-obfuscate email links
	$("a.email").each(function() {
		
		$(this).html($(this).html().split(",")[0] + "@" + $(this).html().split(",")[1]);
		$(this).attr("href", "mailto:" + $(this).html());
	});
	
	$("#footer").show();
	
});

// obscure email addresses from harvesters
function email(addy, text) {
	if(text.length == 0) {
		document.write('<a href="mailto:' + addy + '@srgchicago.com">' + addy + '@srgchicago.com</a>');
	} else {
		document.write('<a href="mailto:' + addy + '@srgchicago.com">' + text + '</a>');
	}
}

function hideSplash() {
	$("#splash").hide();
	$("#container").show();
}	

function getHeight() {
	if (document.all) {
	    return document.body.offsetHeight;
	}
	return window.innerHeight;
}