var ua = navigator.userAgent.toLowerCase();
this.isIE = (ua.indexOf('msie') != -1 && !this.isOpera && (ua.indexOf('webtv') == -1) );

if(this.isIE == true)
{
	document.body.onload = initBackground;
}
else 
{

	if(/Safari/i.test(navigator.userAgent))
	{ //Test for Safari
		var _timer=setInterval(function()
		{
			if(/loaded|complete/.test(document.readyState))
			{
				clearInterval(_timer);
				initBackground(); // call target function
			}
		}, 10)
	}
	else
	{

		$(document).ready(function()
		{

			 initBackground(); 

		}); /* end document.ready */
	
	}
}

/**********************************************************************
These functions manipulate the background image when resizing the
browser window
**********************************************************************/
function initBackground()
{
	$(window).resize(backgroundResizeHandler);
	$(window).trigger('resize');
};
var backgroundResizeHandler = function()
{

	// If the inital image isn't cached, it'll report 0 dimensions.
	if ($('#background img').height() == 0 || $('#background img').width() == 0) 
	{
		//alert('load');
		setTimeout(function() { $(window).trigger('resize'); }, 100);
		return;
	}
	if ($('#background').hasClass('horizontal')) 
	{

		if ($('#background img').height() < $('#background').height()) 
		{
			$('#background').addClass('vertical').removeClass('horizontal');
			$('#background img').css('marginLeft', -1 * parseInt($('#background img').width() / 2));
			
			//document.getElementById('Content_Left').innerHTML = $('#background img').css('marginLeft');
			
		}
	} 
	else 
	{
		
		if ($('#background img').width() < $('#background').width()) 
		{
			$('#background').addClass('horizontal').removeClass('vertical');
			$('#background img').css('marginLeft', 0);
		}
	}
	
	if($('#background').height() < 800)
	{
		$('#background').css('height','800px');
	}
	else
	{
		$('#background').css('height','100%');
	}
	
};
