callNav = function()
{
	sfHover("nav");
}

var _HiderContainer = null;

function BrowserDetect() {
	var ua = navigator.userAgent.toLowerCase();
	// browser name
	this.isIE = ( (ua.indexOf('msie') != -1) && (ua.indexOf('opera') == -1) && (ua.indexOf('webtv') == -1) );
	// browser version
	this.versionMinor = parseFloat(navigator.appVersion);
	if (this.isIE && this.versionMinor >= 4) {
		this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
	}
	this.versionMajor = parseInt(this.versionMinor);
	// specific browser shortcuts
	this.isIE5x = (this.isIE && this.versionMajor == 5);
	this.isIE55 = (this.isIE && this.versionMinor == 5.5);
	this.isMac   = (ua.indexOf('mac') != -1);
}


function sfHover(strMenuId) {
	BrowserDetect();
	if(this.isIE && this.versionMajor <7)
	{
	var navRoot = document.getElementById(strMenuId);
	var sfEls = navRoot.getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].submenu = sfEls[i].getElementsByTagName("UL")[0];
		if(typeof(sfEls[i].submenu)!= "undefined"  )
			sfEls[i].iFrame = iFrameCtrl(sfEls[i].submenu, sfEls[i]);
		
		sfEls[i].onmouseover=function() {
			this.className+=" over";
			if(typeof(this.iFrame)!= "undefined")ShowiFrame(this.iFrame);
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" over\\b"), "");
			if(typeof(this.iFrame)!= "undefined")HideiFrame(this.iFrame);
		}
	}
	}
}

if (window.attachEvent) 
{
	window.attachEvent("onload", callNav);
	window.attachEvent("onload", prepareSelects);
}

function iFrame(oLayer, oNewHiderContainer) {

	var zIndex = oLayer.style.zIndex;
	if (zIndex == "")
		zIndex = xGetAnyCS(oLayer, "z-index");
	zIndex = parseInt(zIndex);
	if ( isNaN(zIndex) ) {
		zIndex = 2;
	}
	
	oIframe = document.getElementById("hider" + oLayer.id);
	if (!oIframe) {
		zIndex--;
		oNewHiderContainer.insertAdjacentHTML("afterBegin", '<iframe id="hider' + oLayer.id + '" scroll="no" frameborder="0" src="include/DoNotRemove.htm" class="iframe" style="zIndex:'+zIndex+';border:0;sFilter:filter:progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0);"></iframe>');
		oIframe = document.getElementById("hider" + oLayer.id);
	}
	
	return oIframe;
}

function iFrameCtrl(oLayer, oNewHiderContainer) {
	oIframe = iFrame(oLayer, oNewHiderContainer);
	if (oIframe) {
		xMoveTo( oIframe, xLeft(oLayer), xTop(oLayer) );
		xResizeTo( oIframe, xWidth(oLayer), xHeight(oLayer) );
	}
	return oIframe;
}


function HideiFrame(oIframe) {
	xHide( oIframe );
}

function ShowiFrame(oIframe)
{
	xShow(oIframe);
}


function raw_popup(url, name, strFeatures) 
{
	var theWindow = window.open(url, name, strFeatures);
	if(theWindow != null)
		theWindow.focus();
	return theWindow;
}
	

function onKeyPress_Return() 
{     
	if (event.keyCode == 13) 
	{   
		event.cancelBubble = true;
		event.returnValue = false;
	}
}

function onKeyPress_Return(evt,item) 
{
	var e=(window.event)?window.event:evt;
	if(e)
	{
		if (e.keyCode == 13||e.charCode==13||e.which==13) 
		{ 
			if(item != null)
				item.click();
			e.cancelBubble = true;
			e.returnValue = false;
		}
	}
}

function selectTab(group,tab) 
{
	var element = document.getElementById(group);
	element.className = tab;
}


// Set the class of corresponding faux select
function fauxState(current_select,fauxstate)
{
	var current_faux = current_select.previousSibling;
	
	if(current_select.selectedIndex != '0')
	{
		current_faux.className = "faux-"+fauxstate;
	}
	else
	{
		current_faux.className = "faux-"+fauxstate+"-default";
	}
}

// When the select element gets focus
function focusSelect(current_select)
{
	// Make faux select 'active'
	fauxState(current_select,"active");
}

// When the select element loses focus
function blurSelect(current_select)
{
	// Hide select
	current_select.className = "inactive";
	
	// Make faux select 'inactive'
	fauxState(current_select,"inactive");
}

// When changing select value
function changeSelect(current_select)
{	
	// Determine current selected option
	current_index=current_select.selectedIndex;
	var current_text = current_select.options[current_index].text;
	
	// Update faux select inner text
	var current_faux = current_select.previousSibling.firstChild;
	current_faux.firstChild.nodeValue = current_text;

	// Make faux select 'active'
	fauxState(current_select,"active");
}

// When clicking an option in the select
function clickSelect(current_select)
{ 
	// Hide select
	current_select.className = "inactive";
}

// When clicking the faux select
function clickFaux(current_faux)
{
	
	// Set focus to corresponding select
	var current_select = current_faux.nextSibling;
	
	// Set faux to 'active'
	if(current_faux.className == "faux-inactive")
	{
	//	Redundant as this appears in select onfocus?
	//current_faux.className = "faux-active";
	}
	
	if(current_select.className == "inactive")
	{
		current_select.className = "active";
	}
	else
	{
		current_select.className = "inactive";
	}
	current_select.focus();
}

// Setup faux select elements
function prepareSelects()
{
//		printfire("prepareSelects fired");
	// Test key object support
	if (!document.getElementsByTagName) { return false;}
	if (!document.createElement) { return false;}
	if (!document.createTextNode) { return false;}
	
	if (!document.getElementById("bncBannerCtrl_srcSearch_pnlSearchTabAnchors")) { return false;}
//		if (!document.appendChild) return false; // Script works despite failing this test in IE 5.5 !?
//		if (!document.insertBefore) return false; // Script works despite failing this test in IE 5.5 !?
	
	
	
	var searchform = document.getElementById("bncBannerCtrl_srcSearch_pnlSearchTabAnchors");
	
	// Find all select elements in the form
	var selects = searchform.getElementsByTagName("select");
	
	//printfire(selects);
	
	
	// Set up each select
	for (var i=0; i<selects.length; i++) 
	{
		current_select = selects[i];
		displaySelect(current_select);
	}
}

function displaySelect(current_select)
{
	if(current_select.className!="inactive")
	{
		// Store initial (styled) width of select
		var selectwidth = current_select.offsetWidth;
		
		current_select.style.width = "auto";
		
		// Set size of select to match the number of options
		var selectsize = current_select.options.length;
		current_select.setAttribute("size",selectsize);
		
		
		// Disallow multiple selections (Default)
	//	current_select.multiple="false";
	//	current_select.multiple=false;
		
		// Hide select
		current_select.className = "inactive";
		
		
		// Create a node that stands in for closed select
		var current_faux = document.createElement("span");
		
		var inner_faux = document.createElement("span");
		inner_faux.className = "inner";
		current_faux.appendChild(inner_faux);
		
		// Set faux display to default or non-default style
		//if(current_select.value != '0')
		if(current_select.selectedIndex!='0')
		{
			current_faux.className = "faux-inactive";
		}
		else
		{
			current_faux.className = "faux-inactive-default";
		}
		
		// Clicking the faux select
		current_faux.onmouseup = function()
		{
			clickFaux(this);
		}
		
		addrolloverout(current_faux);

		// Skip selects with no options
		if(current_select.options.length<=0) {return};
		
		// Determine text of selected option
		var current_index = current_select.selectedIndex;
		var current_text = current_select.options[current_index].text;
		
		
		// Insert currently selected option text into faux select
		var fauxoption = document.createTextNode(current_text);
		inner_faux.appendChild(fauxoption);
		
		// Set faux width based on original
		current_faux.style.width = (selectwidth + "px");
		
		// Set inner faux width to 20px narrower
		current_faux.firstChild.style.width = (selectwidth-20) + "px";
		
		// Insert faux select before original select
		current_select.parentNode.insertBefore(current_faux,current_select);
		
		// Apply behaviour to selects
		current_select.onfocus = function()
		{
			focusSelect(this);
		}
		current_select.onblur = function()
		{
			blurSelect(this);
		}
		// if there is an existing onchange event persist it and add on
		addOnchangeEvent(current_select.id,function(){changeSelect(this)});
		
		current_select.onclick = function()
		{
			clickSelect(this);
		}
	}
}