window.onload 	= initialize_page;

/**********************************************************************/
function initialize_page()
{
	swfobject.embedSWF("/flash/header.swf", "flash_header", "950", "249", "9.0.0", "/flash/expressInstall.swf");
	update_external_links();
}

function update_external_links()
{
	if(!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");

	for(var i=0; i<anchors.length; i++)
	{	
		var link = anchors[i].getAttribute("href");
		var href = link.replace('http://'+location.hostname+'/', '/'); // IE
		
		if(href.substr(0, 7)=='http://')
			anchors[i].target = "_blank";
	}
}


function initialize_background()
{
	window.onresize = stretch_background;
	stretch_background();
}

function stretch_background()
{
	var obj	= document.getElementById('stretchable_image');
	obj.removeAttribute('height');
	

	var desired_height  = (document.documentElement.clientHeight || document.body.clientHeight);
	var actual_height 	= obj.naturalHeight || obj.height;

	if(desired_height>actual_height)
		obj.style.height = desired_height+'px';
}



//<img style='visibility: hidden' width='WWW' height='HHH' alt='' onload='scale_image(this, WWW, HHH)' src='' />
function scale_image(obj, bound_width, bound_height)
{
	var x_ratio = 1;
	var y_ratio = 1;

	// IE does not have naturalWidth and naturalHeight
	obj.removeAttribute('width');
	obj.removeAttribute('height');

	var width 	= obj.naturalWidth || obj.width;
	var height 	= obj.naturalHeight || obj.height;


	if(bound_width>0 && width>bound_width)
		x_ratio=bound_width/width;
	
	width  = Math.round(width*x_ratio*10)/10;
	height = Math.round(height*x_ratio*10)/10;

	if(bound_height>0 && height>bound_height)
		y_ratio=bound_height/height;
	
	width  = Math.round(width*y_ratio*10)/10;
	height = Math.round(height*y_ratio*10)/10;

	obj.style.width		 = Math.round(width)+'px';
	obj.style.height	 = Math.round(height)+'px';
	obj.style.visibility = 'visible';
}



/**********************************************************************/
// usage <div onMouseOut="fixOnMouseOut(this, event, 'JavaScript Code');">So many childs</div>

function is_child_of(parent, child)
{
	if(child!=null)
	{
		while(child.parentNode)
		{
			if(child.parentNode==parent)
				return true;
			else
				child = child.parentNode;
		}
	}
	return false;
}

function fixOnMouseOut(element, event, JavaScript_code)
{
	var current_mouse_target = null;

	if(event.toElement)
		current_mouse_target = event.toElement;
	else if(event.relatedTarget)
		current_mouse_target = event.relatedTarget;

	if(!is_child_of(element, current_mouse_target) && element != current_mouse_target )
		eval(JavaScript_code);
}
/**********************************************************************/