$(document).ready(function(){  

	var browser = navigator.userAgent.toLowerCase()
	var config = {
		sensitivity: 3,
		interval: 150,
		over: makeTall,
		timeout: 0,
		out: makeShort
	}
	
	$("ul.topnav li").hoverIntent(config);
	
	function makeTall() 
	{ //When list item is hovered over ...  
		$(this).find("ul.subnav").slideDown('fast').show()
	}

	function makeShort()
	{
		$(this).parent().find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up  
	}
	
	$('a.itemimg img').each(
		function ()
		{
			$(this).preload({
				onComplete:complete(this)
			});			
		}
	);
	
	
	function complete(obj)
	{
		resizeImage(obj)
	}

});  

function resizeImage(obj)
{
	var obj2 = obj;
	
	if(obj.parentNode.className == '')
	{
		obj = obj.parentNode;
	}

	if(document.defaultView && document.defaultView.getComputedStyle)
	{ // IS MOZILLA BASED BROWSER //
		var objheight = document.defaultView.getComputedStyle(obj.parentNode, '').getPropertyValue("height")
		var objwidth = document.defaultView.getComputedStyle(obj.parentNode, '').getPropertyValue("width")
	} else if(document.uniqueID && obj.parentNode.currentStyle){ 
		var objheight = obj.parentNode.currentStyle.height
		var objwidth = obj.parentNode.currentStyle.width
	}
	parenth = objheight.split('p')
	parentw = objwidth.split('p')
	parentAspect = parentw[0] / parenth[0]
	childAspect = obj2.width / obj2.height

	if((isNaN(childAspect)) || (childAspect == Infinity))
	{
		if(obj2.id)
		{
			setTimeout('resizeImage(document.getElementById("' + obj2.id + '"))',100)
		}	
	} else {
	
		if(parentAspect >= childAspect)
		{
			obj2.style.height = '100%'
			obj2.style.width = 'auto'
			//obj2.style.margin = 'auto'
		} else {
			obj2.style.width = '100%'
			//obj2.style.margin = ((parenth[0] - obj2.height)/2) + 'px 0 0 0'
			obj2.style.height = 'auto'
		}
	}
}

function searchClick(){
	
	var field = document.getElementById('site-search-box');
	if(field.value == 'Search')
		field.value = '';
	
}

function mailClick(){
	
	var field = document.getElementById('site-mail-box');
	if(field.value == 'ENTER EMAIL ADDRESS') field.value = '';
}

function RunHomeFlash() {
	var target = document.getElementById('flashrotation')
	var targetHTML = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="605" height="306" id="mada082709a_main" align="middle">\n'
	targetHTML = targetHTML + '<param name="allowScriptAccess" value="sameDomain" />\n'
	targetHTML = targetHTML + '<param name="movie" value="mada082709a_main.swf" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="bgcolor" value="#fbf4e2" /><embed src="mada082709a_main.swf" quality="high" wmode="transparent" bgcolor="#fbf4e2" width="605" height="306" name="mada082709a_main" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />\n'
	targetHTML = targetHTML + '</object>\n'
	target.innerHTML = targetHTML
}