$(document).ready(function() {

	// adjust attachment property of #bodywrap bg image (see below)
	adjust_content_height();

});

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

// ensure background watermark is always visible
// when the body wrapper is taller than the viewport,
// change the background-attachment property from 'scroll' to 'fixed'
function adjust_content_height() {
	if (!jQuery.support.opacity) {
		var $sidebarheight		= $("#sidebar1").height();
		var $contentheight		= $("#brandContent").height() ? $("#brandContent").height() : $("#mainContent").height();
		$sidebarheight			  += 14;
		var $contentheightadj	= ($sidebarheight > $contentheight) ? $sidebarheight : $contentheight;
		//alert('hi');
		//alert('Sidebar is ' + $sidebarheight + "px tall,\n" + '#content is ' + $contentheight + "px tall");
		$("#mainContent").css("height", $contentheightadj);
	}
}

// ensure background watermark is always visible
// when the body wrapper is taller than the viewport,
// change the background-attachment property from 'scroll' to 'fixed'
function adjust_bodywrap_bg() {
	var $viewportheight		= $(window).height();
	var $bodywrapheight		= $("#bodywrap").height();
	var $bodywrapbgattach	= ($viewportheight > $bodywrapheight) ? 'scroll' : 'fixed';
	//alert('Viewport is ' + $viewportheight + "px tall,\n" + '#bodywrap is ' + $bodywrapheight + "px tall,\n" + 'background-attachment of #bodywrap bg is ' + $bodywrapbgattach);
	$("#bodywrap").css("background-attachment", $bodywrapbgattach);
}

function preload_imgs($selector) {
	$($selector).each(function() {
		// Set the original src
		rollsrc = $(this).attr("src");
		rollON = rollsrc.replace('_off', '_on');
		newImg = new Image(); 				// create new image obj
		$(newImg).attr("src", rollON);	// set new obj's src
	});
}

function handle_mouseovers($selector) {
	$($selector).mouseover(function(){
		imgsrc = $(this).children("img").attr("src");
		if (typeof(imgsrc) != 'undefined') {
			imgsrcON = imgsrc.replace('_off', '_on');
			$(this).children("img").attr("src", imgsrcON);
		}
	});
}

function handle_mouseouts($selector) {
	$($selector).mouseout(function(){
		if (typeof(imgsrc) != 'undefined') {
			$(this).children("img").attr("src", imgsrc);
		}
	});
}

