$(document).ready(
	function()
	{
		$('#gallery img').load(onResize);
		$('#home img').load(onResize);
		checkSetHtml();
		addFlashLink();
		sendScreen();
		onScreenResize();
		onReadyMenuInit();
	}
);

$(window).resize(
	function() 
	{
		onScreenResize();
		onResize();
	}
);

var ratio = 0;
var base_url = location.protocol+"//"+location.host+"/";

function checkSetHtml()
{
	if($('#htmllink').size())
	{
		var href = base_url + "sethtml/";
		if((location.pathname).substr(1) != "")
		{
			href+= (location.pathname).substr(1);
		}
		else if(location.hash != "")
		{
			href+= (location.hash).substr(2);
		}
		$('#htmllink').attr('href', href);
	}
}

function addFlashLink()
{
	$('#view_flash').html('<a href="'+base_url+'setflash/">View Flash Version</a>');
}

function onResize()
{
	resizeImage('#focus_home', 	'#content', "less");
	resizeImage('#focus', 		'#gallery', "greater");
}

function resizeImage(container, image_container, heightCondition)
{
	var himg = $(container).height();
	if(himg > 0)
	{
		if(ratio == 0)
		{
			ratio 	= $(image_container+' img').width()/$(image_container+' img').height();
		}
		
		var tw		= $(image_container).width();
		var th		= tw/ratio;

		if((th > $(image_container).height() && heightCondition=="greater") || (th < $(image_container).height() && heightCondition=="less"))
		{
			th		= $(image_container).height();
			tw		= th*ratio;
		}
		
		$(container).width(tw);
		$(container).height(th);
		$(image_container+' img').css('margin-top', ($(image_container).height()-th)/2);
	}
}

function sendScreen()
{
	url = location.protocol+"//"+location.host+"/"+"setscreen/"+screen.width+"/"+screen.height;
	url = setupXmlHttp(url);
	sendXmlHttp(url);
	return false;
}




