var timeout;

$(window).load(function(){
	resizeBackground();
	watchForResize();
	hideSearchInput();
});

function resizeBackground() {
	
	var img = $("#background>img");
		
	if ($(img).attr("complete")) {
		
		$(".background").fadeIn("slow");
		
		var image_width = $(img).width();
		var image_height = $(img).height();
		var image_ratio = (image_width / image_height);
	
		var window_width = $(window).width();
		var window_height = $(window).height();
		var window_ratio = (window_width / window_height);
		
		if (window_ratio > image_ratio) {
			$(img).width(window_width);
			$(img).height("auto");
		}
		else {
			$(img).height(window_height);
			$(img).width("auto");
		}	
	}
	else {
		setTimeout("resizeBackground()", timeout);
		timeout = 2 * timeout;
	}
}

function watchForResize() {
	$(window).resize(function(){			
		resizeBackground();
	});
}

function hideSearchInput() {
	$("#s").blur(function() {
		if ($(this).attr("value") == "") {
			$(this).attr("value", "Search");
		}
	});
	$("#s").focus(function() {
		if ($(this).attr("value") == "Search") {
			$(this).attr("value", "");
		}
	});
}
