//LOSE IE6 FLICKER BUG
//--------------------

try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}

//CALL FUNCTIONS ONDOMREADY
//-------------------------

function onDomReady() {
	//call functions on page load.
	headerSearchFocus();
	partnerLoginFocus();
	faq();
}

var bannerCurrent = 1;
function banner() {

	j("#bannerImgs").append(j("#banner_"+bannerCurrent));
	j("#banner_"+bannerCurrent).animate({
		"width": "665px",
		"height": "200px"
	}, function() {
		//when done
		setTimeout('banner2()', 2500);
	});
	
};

function banner2() {

	j("#banner_"+bannerCurrent).animate({
		"width": "332px",
		"height":"100px"
	}, function() {
		if (bannerCurrent == 4) {
			bannerCurrent = 1;
		} else {
			bannerCurrent = bannerCurrent+1;
		};
		banner();
	});

}

var homepageNewsInc = 0;
var homepageNewsTimeout = 0;
function homepageNews(fromNew) {

	var box = document.getElementById("latestnews");
	var titles = box.getElementsByTagName("h3");
	
	if (!fromNew) {
		//fade out old item
		if (homepageNewsInc == 0) {	
			var i = titles.length - 1;
		} else {
			var i = homepageNewsInc - 1;
		};
		Effect.Fade('newsTitle'+i, {duration: 1.0});
	};
	
	Effect.Appear('newsTitle'+homepageNewsInc, {duration: 1.0});
	
	var count = document.getElementById("newsCount").getElementsByTagName("span")[0];
	count.innerHTML = homepageNewsInc + 1;
	
	homepageNewsInc++;
	if (homepageNewsInc == titles.length) {
		homepageNewsInc = 0;
	};
	homepageNewsTimeout = setTimeout("homepageNews()",5000);
	
};

function homepageNewsNext() {

	var box = document.getElementById("latestnews");
	var titles = box.getElementsByTagName("h3");
	
	
	
};

function whitePaper(wpID, wpTitle) {

	var frmWpID = document.getElementById("frmWpID");
	if (!frmWpID.value) {
		frmWpID.value = wpID;
		document.getElementById("frmWpTitle").innerHTML = wpTitle;
	} else {
		var message = confirm("You have already selected a white paper to download. Do you wish to change this selection?");
		if (message) {
			frmWpID.value = wpID;
			document.getElementById("frmWpTitle").innerHTML = wpTitle;
		};
	};
	
	document.getElementById("frmWp").style.display = "block";	
	return false;

}

function downloadFile(dlTitle) {

	var frmDlTitle = document.getElementById("frmDlTitle");
	if (!frmDlTitle.value) {
		frmDlTitle.value = dlTitle;
		document.getElementById("frmWpTitle").innerHTML = dlTitle;
	} else {
		var message = confirm("You have already selected a file to download. Do you wish to change this selection?");
		if (message) {
			frmDlTitle.value = dlTitle;
			document.getElementById("frmWpTitle").innerHTML = dlTitle;
		};
	};
	
	document.getElementById("frmWp").style.display = "block";	
	return false;

}

function faq() {

	var ol = document.getElementsByTagName("ol");
	for (var i=0; i<ol.length; i++) {
		if (ol[i].className == "faq") {
			for (var j=0; j<ol[i].getElementsByTagName("h6").length; j++) {
				ol[i].getElementsByTagName("h6")[j].onclick = function() {
					//alert(this.parentNode.className);
					if (!this.parentNode.className || this.parentNode.className == "") {
						this.parentNode.className = "active";
					} else {
						this.parentNode.className = "";
					};
				};
			};
		};
	};
	
}

//HEADER SEARCH FOCUS FUNCTIONS
//-----------------------------

function headerSearchFocus() {

	var input = document.getElementById("header").getElementsByTagName("form")[0].getElementsByTagName("input")[0];
	input.onfocus = function() {
		if (!input.rel) {
			input.value = "";
			input.style.color = "#000";
			input.rel = "focus";
		};
	};
	input.onblur = function() {
		if (!input.value) {
			input.value = "Search website...";
			input.style.color = "#999";
			input.rel = "";
		};
	};
	
}

function partnerLoginFocus() {

	if (!document.getElementById("partnerbar").getElementsByTagName("form")[0]) {
		return false;
	} else {
	
		var username = document.getElementById("partnerbar").getElementsByTagName("form")[0].getElementsByTagName("input")[0];
		var password = document.getElementById("partnerbar").getElementsByTagName("form")[0].getElementsByTagName("input")[1];
		
		username.onfocus = function() {
			if (!username.rel) {
				username.value = "";
				username.rel = "focus";
			};
		};
		password.onfocus = function() {
			if (!password.rel) {
				password.value = "";
				password.rel = "focus";
			};
		};
		
		username.onblur = function() {
			if (!username.value) {
				username.value = "Email";
				username.rel = "";
			};
		};
		password.onblur = function() {
			if (!password.value) {
				password.value = "Password";
				password.rel = "";
			};
		};
		
	};
	
}

//PARTNER BAR CLICK FUNCTION
//--------------------------

function partnerbar() {
	
	var partnerbarElement = document.getElementById("partnerbar");
	Effect.toggle("partnerbar", "slide");
	
	if (partnerbarElement.style.display) {
		var url = "/inc/ajax/partnerbar.php?status=1";
	} else {
		var url = "/inc/ajax/partnerbar.php?status=0";
	};
	
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
	
	//alert(status);
	//return false;

}

//POPUP
//-----

function popUp(URL, width, height) {

	var day = new Date();
	var id = day.getTime();
	
	var offsetWidth = (screen.width / 2) - (width / 2);
	var offsetHeight = (screen.height / 2) - (height / 2);

	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width="+width+",height="+height+",left = "+offsetWidth+",top = "+offsetHeight+"');");
	return false;
	
}

//AJAX OBJECT CREATE
//------------------

var xmlHttp;
try {
	// Firefox, Opera 8.0+, Safari
	xmlHttp = new XMLHttpRequest();
} catch (e) {
	// Internet Explorer
	try	{
		xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e)	{
		try	{
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e)	{
			alert("Your browser does not support AJAX!");
		};
	};
};

//JAVASCRIPT FLASH INSERTION
//--------------------------

function flash(url, img, width, height, flashversionuser) {

    if (!flashversionuser) {
        flashtest = 6;
    } else {
        flashtest = parseInt(flashversionuser);
    };
    
    //alert("Flash installed (2=yes): "+FlashDetect.installed);
    //alert("Flash version installed: "+FlashDetect.major);    
    //alert("Testing for: "+flashtest);        

    if (FlashDetect.installed == true && FlashDetect.major >= flashtest) {
        
        document.write('<object width="'+width+'" height="'+height+'" align="middle" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000">');
        document.write('<param value="sameDomain" name="allowScriptAccess" />');
        document.write('<param value="'+url+'" name="movie" />');
        document.write('<param value="high" name="quality" />');
        //document.write('<param value="noscale" name="scale" />');
        document.write('<param value="transparent" name="wmode" />');
        document.write('<param value="lt" name="salign" />');
        document.write('<param value="#ffffff" name="bgcolor" /><embed width="'+width+'" height="'+height+'" align="middle" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" allowscriptaccess="sameDomain" wmode="transparent" bgcolor="#ffffff" salign="lt" quality="high" src="'+url+'">');
        document.write('</embed>');
        document.write('</object>');
    } else {
        document.write('<img src="'+img+'" width="'+width+'" height="'+height+'" alt="" />');
    };
    
    flashtest == null;

}

//JAVASCRIPT MOV INSERTION
//------------------------

function mov(url, width, height) {

	width = parseInt(width);
	height = parseInt(height);

	document.write('<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" height="'+height+'" width="'+width+'">');
	document.write('<param name="correction" value="full">');
	document.write('<param name="cache" value="true">');
	document.write('<param name="src" value="/media/qt/'+url+'">');
	document.write('<param name="autoplay" value="true">');
	document.write('<param name="controller" value="true">');
	document.write('<embed width="'+width+'" height="'+height+'" pluginspage="http://www.apple.com/quicktime/download/" src="/media/qt/'+url+'" type="video/quicktime" controller="true" autoplay="true" cache="true" correction="full"></embed>');
	document.write('</object>');
	
};

//ONDOM READY FUNCTION
//--------------------
function onDomReadyLoad() {

	//quit if this function has already been called
	if (arguments.callee.done) return;
	
	//flag this function so we don't do the same thing twice
	arguments.callee.done = true;
	
	//kill the timer
	if (_timer) {
		clearInterval(_timer);
		_timer = null;
	};
	
    onDomReady();
    
};

//CALL ONDOMREADY FUNCTION
//for Mozilla
if (document.addEventListener) {
	document.addEventListener("DOMContentLoaded", onDomReadyLoad, false);
};

/*for Internet Explorer*/
/*@cc_on @*/
/*@if (@_win32)
	document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
	var script = document.getElementById("__ie_onload");
	script.onreadystatechange = function() {
		if (this.readyState == "complete") {
			onDomReadyLoad(); // call the onload handler
		};
	};
/*@end @*/

//for Safari
if (/WebKit/i.test(navigator.userAgent)) {
	var _timer = setInterval(function() {
		if (/loaded|complete/.test(document.readyState)) {
			onDomReadyLoad();
		};
	}, 10);
};

//for other browsers
window.onload = onDomReadyLoad;