
//
// Site Support functions
// v4.0 29-Nov-2011 (first V4 layout functions)
// 

/*******************************************************************************
	Category Overlays
*******************************************************************************/

var ActiveThb=0;
var ShowDelay=100;
var HideDelay=120;

function thb_fade(id)
{
	FadeLevel+=5;

	if (FadeLevel>100)
		FadeLevel=100;

	el=document.getElementById(id);
	if (el)
	{
//		el.style.opacity=FadeLevel / 100.0;
//		el.style.filter='alpha(opacity=' + FadeLevel + ')';
		el.style.top=350-FadeLevel;
	}

	if (FadeLevel<100)
		setTimeout("thb_fade(" + "'" + id + "')", 15);
}



function thb_show(id)
{
	if (ActiveThb!=id)		// don't show anything if we've quickly moved out of this thumb already
		return;

	if (id)
	{
		var el=document.getElementById(id);
		if (el)
		{
			el.style.display='block';
		}
	}
}

function thb_hide(id)			// don't hide anything if we've quickly moved back into this thumb already
{
	if (ActiveThb==id)
		return;

	if (id)
	{
		var el=document.getElementById(id);
		if (el)
		{
			el.style.display='none';
		}
	}
}

function thb_mouseover(partno)
{
	var id='thb' + partno;

	ActiveThb=id;

	var delay=ShowDelay;

	setTimeout("thb_show(" + "'" + id + "')", delay);

	var el=document.getElementById(id);
	if (el)
	{
//		el.style.display='block';
	}
}

function thb_mouseout(partno, e)
{
	if (!e)
		var e = window.event;

	// from: http://www.webmasterworld.com/javascript/3752159.htm

	var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
	if (!reltg)
		return;

	while (reltg.tagName != 'BODY')
	{
		if (reltg.id == this.id)
			return;
		reltg = reltg.parentNode;
	}

	// Filter out case where mouseout is called when mouse is moved from transparent area back into image area
	//
	var node=null;
	if (e.target) node = e.target;
	else if (e.srcElement) node = e.srcElement;

	reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;

	while (true)
	{
		// if the reltarget is an image, and that img's parent is also parent to the transparent area, do nothing.
		//
		if (node==reltg.parentNode && reltg.tagName=="IMG")
			return;

		node = node.parentNode;
		if (!node)
			break;
	}

	var id='thb' + partno;

	ActiveThb=0;

	var delay=HideDelay;

	setTimeout("thb_hide(" + "'" + id + "')", delay);

	var el=document.getElementById(id);
	if (el)
	{
//		el.style.display='none';
	}
}



// Window opener functions  v1.0.6
// http://www.dithered.com/javascript/window/index.html
// code by Chris Nott (chris@NOSPAMdithered.com - remove NOSPAM)

/*******************************************************************************
	Popup Window openers
*******************************************************************************/

var winReference = null;


// Open a window at a given position on the screen
function openPositionedWindow(url, name, width, height, x, y, status, scrollbars, moreProperties, openerName) {
	
	// ie 4.5 and 5.0 mac - windows are 2 pixels too short; if a statusbar is used, the window will be an additional 15 pixels short
	var agent = navigator.userAgent.toLowerCase();
	if (agent.indexOf("mac") != -1 && agent.indexOf("msie") != -1 && (agent.indexOf("msie 4") != -1 || agent.indexOf("msie 5.0") != -1) ) {
		height += (status) ? 17 : 2;
	}

	// Adjust width if scrollbars are used (pc places scrollbars inside the content area; mac outside) 
	width += (scrollbars != '' && scrollbars != null && agent.indexOf("mac") == -1) ? 17 : 14;

	var properties = 'width=' + width + ',height=' + height + ',screenX=' + x + ',screenY=' + y + ',left=' + x + ',top=' + y + ((status) ? ',status' : '') + ',scrollbars' + ((scrollbars) ? '' : '=no') + ((moreProperties) ? ',' + moreProperties : '');
	var reference = openWindow(url, name, properties, openerName);
	
	return reference;
}


// Open a window at the center of the screen
function openCenteredWindow(url, name, width, height, status, scrollbars, moreProperties, openerName) {
	var x, y = 0;
	if (screen) {
      x = (screen.availWidth - width) / 2;
	   y = (screen.availHeight - height) / 2;
   }
	if (!status) status = '';
	if (!openerName) openerName = '';
	var reference = openPositionedWindow(url, name, width, height, x, y, status, scrollbars, moreProperties, openerName);
	return reference;
}	

// Open a full-chrome (all GUI elements) window
// This is like using a target="_blank" in a normal link but allows focussing the window
function openFullChromeWindow(url, name, openerName) {
	return openWindow(url, name, 'directories,location,menubar,resizable,scrollbars,status,toolbar');
}


// Core utility function that actually creates the window and gives focus to it
function openWindow(url, name, properties, openerName) {

	// ie4.x pc can't give focus to windows containing documents from a different domain
	// in this case, initially load a local interstisial page to allow focussing before loading final url
	var agent = navigator.userAgent.toLowerCase();
	if (agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) == 4 && agent.indexOf("msie 5") == -1 && agent.indexOf("msie5") == -1 && agent.indexOf("win") != -1 && url.indexOf('http://') == 0) {
		winReference = window.open('about:blank', name, properties);
		
		setTimeout('if (winReference && !winReference.closed) winReference.location.replace("' + url + '")', 300);
	}
	else {
		winReference = window.open(url, name, properties);
	}

	// ie doesn't like giving focus immediately (to new window in 4.5 on mac; to existing ones in 5 on pc)
	setTimeout('if (winReference && !winReference.closed) winReference.focus()', 200);
	
	if (openerName) self.name = openerName;
	return winReference;
}


/***************************
	Fade In/Out
***************************/

function mhx_animfadein(id, opac)
{  
	var el=document.getElementById(id);

	if (el.FadeState%2==0)
	{
		opac+=0.13;

		el.style.opacity = Math.min(opac, 1.0);
	  	el.style.filter = 'alpha(opacity = ' + (Math.min(opac, 1.0)*100) + ')';

		if (opac>=1.0)
		{
			el.FadeState++;
			return;
		}
	}

	setTimeout("mhx_animfadein('" + id + "', " + opac + ")", 25);
}

function mhx_animfadeout(id, opac)
{  
	var el=document.getElementById(id);

	if (el.FadeState%2)
	{
		opac-=0.13;
		if (opac<0.0)
			opac=0.0;

		el.style.opacity = Math.min(opac, 1.0);
	  	el.style.filter = 'alpha(opacity = ' + (Math.min(opac, 1.0)*100) + ')';

		if (opac<=0.0)
		{
			el.FadeState--;
			return;
		}
	}

	setTimeout("mhx_animfadeout('" + id + "', " + opac + ")", 25);
}

function mhx_fadein(id)
{
	var el=document.getElementById(id);
	if (!el)
		return;

	if (el.FadeState==null)
		el.FadeState=0;

	setTimeout("mhx_animfadein('" + id + "', 0)", 25);
}

function mhx_fadeout(id)
{
	var el=document.getElementById(id);
	if (!el)
		return;

	setTimeout("mhx_animfadeout('" + id + "', 1.5)", 25);
}

