

/*
 * Interfuse : Last edit 2010-06-28 NB
 */

$(document).ready(function(){
	if(17 == 1 || 17 == 17 || 17 == 31 ){
		setupMenu('side');
	}
	else {
		setupMenu('top');
	}
	hideLabledForms();
	styleradioBoxes();
	
	ajaxImgTitle();
})

window.onload =	function() {
	sponsorResize();
}

var selfLabledForms = new Array();
function hideLabledForms(){
	$('span.textField').each(function(){
		var pos = selfLabledForms.length;
		selfLabledForms[pos] = this;
		selfLabledForms[pos].input = this.getElementsByTagName('input')[0];
		selfLabledForms[pos].label = this.getElementsByTagName('label')[0];
	})

	for(var i = 0; selfLabledForms.length > i; i++){
		selfLabledForms[i].input.loc = i;
		selfLabledForms[i].input.onfocus = function(){
			selfLabledForms[this.loc].label.style.display = 'none';
		}
		selfLabledForms[i].input.onblur = function(){
			if(this.value == ''){
				selfLabledForms[this.loc].label.style.display = 'block';
			}
		}
	}
}

var radioBoxes = new Array();
function styleradioBoxes(){
	$('.radioField').each(function(){
		var pos = radioBoxes.length;
		radioBoxes[pos] = this;
		radioBoxes[pos].state = 0;
		radioBoxes[pos].dataNode = this.getElementsByTagName('input')[0];
	})
	for (var i = 0; radioBoxes.length > i; i++) {
		radioBoxes[i].style.background = "url('/_fuse/120/17/_/check.gif') no-repeat center";
		radioBoxes[i].style.position = 'relative';
		radioBoxes[i].style.padding = '1px';
		radioBoxes[i].style.width = '1.1em';
		radioBoxes[i].style.marginRight = '1.1em';
		radioBoxes[i].dataNode.loc = i;
		radioBoxes[i].dataNode.style.position = 'absolute';
		radioBoxes[i].dataNode.style.left = '-9999px';
		radioBoxes[i].onclick = function() {
			this.dataNode.focus();
			if(this.dataNode.checked == false){
				this.dataNode.checked = true;
			}
			for (var i = 0; radioBoxes.length > i; i++) {
				if(radioBoxes[i].dataNode.checked){
					radioBoxes[i].style.backgroundImage = "url('_fuse/120/17/_/checkSelected.gif')";
				}
				else {
					radioBoxes[i].style.backgroundImage = "url('_fuse/120/17/_/check.gif')";
				}
			}
		}
		radioBoxes[i].dataNode.onfocus = function() {
			for (var i = 0; radioBoxes.length > i; i++) {
				if(i == this.loc){
					radioBoxes[i].style.border = 'dotted 1px #000';
					radioBoxes[i].style.padding = '0px';
				}
				else {
					radioBoxes[i].style.border = 'none';
					radioBoxes[i].style.padding = '1px';
				}
			}
		}
		radioBoxes[i].dataNode.onblur = function() {
			for (var i = 0; radioBoxes.length > i; i++) {
				radioBoxes[i].style.border = 'none';
				radioBoxes[i].style.padding = '1px';
			}
		}
	}
}

function userControlsToggle(type) {
	if (type == 'over' && userControls.myState == 'hidden') {
		userControls.myState = 'showing';
		myIndex = animate.length;
		animate[myIndex] = function(){
			var thisIndex = myIndex;
			userControls.top = userControls.top + userControls.speed;
			if(userControls.top < -userControls.myHeight/2){
				userControls.speed+=10;
			}
			else if(userControls.speed > 15) {
				userControls.speed-=10;
			}
			if (userControls.top < 0) {
				userControls.style.top = userControls.top + 'px';
			}
			else {
				userControls.top = 0;
				userControls.style.top = '0px'
				userControls.speed = 10;
				userControls.myState = 'shown';
				animate.splice(thisIndex, 1);
			}
		}
	}
	if (type=='out' && userControls.myState == 'shown') {
		userControls.myState = 'hidding';
		myIndex = animate.length;
		animate[animate.length] = function(){
			var thisIndex = myIndex;
			userControls.top = userControls.top - userControls.speed;
			if(userControls.top > -userControls.myHeight/2){
				userControls.speed+=10;
			}
			else if(userControls.speed > 15) {
				userControls.speed-=10;
			}
			if (userControls.top > -userControls.myHeight) {
				userControls.style.top = userControls.top + 'px';
			}
			else {
				userControls.top = -userControls.myHeight;
				userControls.style.top = -userControls.myHeight + 'px';
				userControls.speed = 10;
				userControls.myState = 'hidden';
				animate.splice(thisIndex, 1);
			}
		}
	}
}

var mainNav;
var navItem = new Array();
function setupMenu(type){
	$('ul.mainNav').each(function(){
			mainNav = this.getElementsByTagName('ul');
			this.style.position = 'relative';
			this.style.zIndex = '999';
	})
	zIndex = 99999;
	for(var i = 0; mainNav.length > i; i++){
		mainNav[i].style.position = 'absolute';
		mainNav[i].style.zIndex = '' + zIndex;
		mainNav[i].style.left = '80%';
		mainNav[i].style.top = '20%';
		mainNav[i].style.padding = '0';
		mainNav[i].style.visibility = 'hidden'
		mainNav[i].style.display = 'none';
		
		navItem[i] = mainNav[i].parentNode;
		navItem[i].style.position = 'relative';
		navItem[i].style.zIndex = ''+zIndex;
		navItem[i].navChild = mainNav[i];
		navItem[i].onmouseover = function(){
			this.navChild.style.display = 'block';
			$(this).siblings().each(function(){
				try {
					this.navChild.style.visibility = 'hidden';
					clearTimeout(this.timeout);
				}
				catch(e){
					// do nothing!!!
				}
			})
			clearTimeout(this.timeout);
			pLeft = $(this).offset().left;
			pWidth = $(this).width();
			cWidth = $(this.navChild).width();
			sWidth = $(window).width();
			sLeft = $(window).scrollLeft();
			
			if (this.navChild.rootNav == true) {
				if(pLeft + cWidth > sLeft + sWidth){
					this.navChild.style.left = ((sLeft + sWidth) - (pLeft+cWidth)) + 'px';
				}
				else {
					this.navChild.style.left = '0px';
				}
			}
			else {
				if (pLeft + (pWidth * 0.8) + cWidth > sWidth && pLeft > (cWidth * 0.8)) {
					this.navChild.style.left = '-80%';
				}
				else {
					this.navChild.style.left = '80%';
				}
			}
			this.navChild.style.visibility = 'visible';
		};
		
		navItem[i].onmouseout = function(){
			var self = this;
			this.timeout = window.setTimeout(function(){
				self.navChild.style.display = 'none';
				self.navChild.style.visibility = 'hidden';
			}, 100)
		};
		zIndex--;
	}
	if(type == 'top'){
		$('ul.mainNav').children('li').children('ul').each(function(){
				this.style.left = '0px';
				this.style.top = '100%';
				this.rootNav = true;
		})
	}
}

function sponsorResize(){
	var silver = $('ul.silver');
	var bronze = $('ul.bronze');
	
	var largeItem;
	var smallItem;
	
	
	if(silver.length > 0 && bronze.length > 0){
		silver.each(function(){
			silver = this;
			silverHeight = silver.offsetHeight;
		});
		bronze.each(function(){
			bronze = this;
			bronzeHeight = bronze.offsetHeight;
		});
		
		if (silverHeight > bronzeHeight){
			largeItem = silver;
			largeItem.height = silverHeight;
			
			smallItem = bronze;
			smallItem.height = bronzeHeight;
		}
		else if (bronzeHeight > silverHeight) {
			largeItem = bronze;
			largeItem.height = bronzeHeight;
			
			smallItem = silver;
			smallItem.height = silverHeight;
		}
		else {
			smallItem = null;
			largeItem = null;
		}
		
		if (smallItem != null && largeItem != null) {
			padding = (largeItem.height - smallItem.height) / 2;
			if (padding % 1 == 0) {
				smallItem.style.padding = (padding+10) + 'px 0';
			}
			else {
				padding = Math.floor(padding);
				smallItem.style.padding = (padding+10) + 'px 0 ' + (padding+11) + 'px 0';			
			}
		}
	}
}

var imgList = new Array();
var qString = '';
function ajaxImgTitle(){
	var img = document.getElementsByTagName('img');
	for (i = 0; i < img.length; i++) {
		srcStr = img[i].src.split('/');
		fileStr = srcStr[srcStr.length - 1].slice(0, srcStr[srcStr.length - 1].length - 5);
		
		if (isNaN(fileStr.charAt(0)) == false) {
			imgVar = fileStr.split('_');
			if (imgVar.length == 2 && isNaN(imgVar[1]) == false) {
				j = imgList.length;
				imgList[j] = img[i];
				imgList[j].imgID = imgVar[1];
				if (j == 0) {
					qString = imgVar[1];
				}
				else {
					qString = qString + "," + imgVar[1]
				}
			}
		}
	}
	
	
	loadXMLDoc();
}
	
function loadXMLDoc(){
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
			//document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
			var qArray = xmlhttp.responseText.split("#!#");
			for (u = 0; u < qArray.length; u++){
				tempArray = qArray[u].split("#,#");
				for (i = 0; i < imgList.length; i++){
					if(tempArray[1] == imgList[i].imgID){
						imgList[i].title = tempArray[0];
						i = 999999;
					}
				}
			}

		}
	}
	xmlhttp.open("GET","/_fuse/120/imgDesc.asp?imgID="+qString,true);
	xmlhttp.send();
}