var topnav = document.getElementById("topnav");
if (topnav != null) {
	topnav.style.position = "relative";
	topnav.style.left = "50%";
	topnav.style.marginLeft = "-" + (topnav.clientWidth / 2) + "px";
}

var footernav = document.getElementById("footernav");
if (footernav != null) {
	footernav.style.position = "relative";
	footernav.style.left = "50%";
	footernav.style.marginLeft = "-" + (footernav.clientWidth / 2) + "px";
}

//fit IE footer issue
function fixIEfooter() {
	if (document.getElementById("footer-wrapper") != null && document.getElementById("footer") != null) {
		document.getElementById("footer-wrapper").style.position = "static";
		document.getElementById("footer").style.position = "static";
		document.getElementById("footer-wrapper").style.position = "relative";
		document.getElementById("footer").style.position = "relative";
	}
}

//attach function to onload
if (window.attachEvent) {window.attachEvent('onload', fixIEfooter);}
else if (window.addEventListener) {window.addEventListener('load', fixIEfooter, false);}
else {document.addEventListener('load', fixIEfooter, false);} 


//for the forum
function VerifyCaptchaAjax(thisform, textinput) {
	var http = new Array();
	if (http[0] != null) {
		http[0].abort();
	}
	if(navigator.appName == "Microsoft Internet Explorer") {
	  http[0] = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
	  http[0] = new XMLHttpRequest();
	}
	http[0].open("GET", "testcaptcha.asp?q=" + textinput, true);
	http[0].onreadystatechange=function() {
		if(http[0].readyState == 4) {
			if (http[0].responseText == "1") {
				thisform.submit();
			} else {
				//reload image
				document.getElementById("imgCaptcha").src = "images/blank.gif";
				alert("Vertification code is incorrect. Please try again.");
				setTimeout(" document.getElementById('imgCaptcha').src = 'captcha.asp?id=' + uniqid(); ", 500);
				thisform.captchacode.focus();
			}
		}
	}
	http[0].send(null);
	return false;
}

//unique number generator
function uniqid()
{
	var newDate = new Date;
	return newDate.getTime();
}


//scrolling for the video playlists
var scrollInterval = null;
var scrollAmount = null;
var scrollFactor = 5;
function smoothScrollDiv(elementid, amount) {
	if (!scrollInterval) {
		scrollInterval = setInterval( "scrollDiv('" + elementid + "', " + amount + ")", 30 );
	}
}
function scrollDiv(elementid, amount) {
	if (scrollAmount == null) {
		scrollAmount = amount;
		scrollThisTime = scrollAmount/scrollFactor;
		scrollAmount = scrollAmount - Math.round(scrollThisTime);
	} else if (scrollAmount < 1 && scrollAmount > -1) {
		scrollAmount = null;
		scrollThisTime = 0;
		clearInterval(scrollInterval);
		scrollInterval = null;
		checkScrollButtonStatus(elementid,"videoplaylistup","videoplaylistdown");
	} else {
		scrollThisTime = scrollAmount/scrollFactor;
		if (scrollThisTime < 1 && scrollThisTime > 0) {
			scrollThisTime = 1;
		} else if (scrollThisTime > -1 && scrollThisTime < 0) {
			scrollThisTime = -1;
		}
			scrollAmount = scrollAmount - Math.round(scrollThisTime);
	}
	element = document.getElementById(elementid);
	element.scrollTop += Math.round(scrollThisTime);
}
function checkScrollButtonStatus(elementid, upelementid, downelementid) {
	element = document.getElementById(elementid);
	upelement = document.getElementById(upelementid);
	downelement = document.getElementById(downelementid);
	
	if ( element.clientHeight + element.scrollTop >= element.scrollHeight ) { //at the bottom
		downelement.style.display = "none";
	} else if ( element.clientHeight + element.scrollTop < element.scrollHeight ) {
		downelement.style.display = "block";
	}
	
	if ( element.scrollTop == 0 ) { //at the top
		upelement.style.display = "none";
	} else if ( element.scrollTop > 0) {
		upelement.style.display = "block";
	}
}
if ( document.getElementById("videoplaylist") ) {	//if playlist exits, set the buttons
	checkScrollButtonStatus("videoplaylist","videoplaylistup","videoplaylistdown");
}


//scrolling for the horizontal video playlists
var scrollIntervalH = null;
var scrollAmountH = null;
var scrollFactorH = 5;
function smoothScrollDivH(elementid, amount) {
	if (!scrollIntervalH) {
		scrollIntervalH = setInterval( "scrollDivH('" + elementid + "', " + amount + ")", 30 );
	}
}
function scrollDivH(elementid, amount) {
	if (scrollAmountH == null) {
		scrollAmountH = amount;
		scrollThisTime = scrollAmountH/scrollFactorH;
		scrollAmountH = scrollAmountH - Math.round(scrollThisTime);
	} else if (scrollAmountH < 1 && scrollAmountH > -1) {
		scrollAmountH = null;
		scrollThisTime = 0;
		clearInterval(scrollIntervalH);
		scrollIntervalH = null;
		checkScrollButtonStatusH(elementid,"videoplaylistleft","videoplaylistright");
	} else {
		scrollThisTime = scrollAmountH/scrollFactorH;
		if (scrollThisTime < 1 && scrollThisTime > 0) {
			scrollThisTime = 1;
		} else if (scrollThisTime > -1 && scrollThisTime < 0) {
			scrollThisTime = -1;
		}
			scrollAmountH = scrollAmountH - Math.round(scrollThisTime);
	}
	element = document.getElementById(elementid);
	element.scrollLeft += Math.round(scrollThisTime);
}
function checkScrollButtonStatusH(elementid, upelementid, downelementid) {
	element = document.getElementById(elementid);
	upelement = document.getElementById(upelementid);
	downelement = document.getElementById(downelementid);
	
	if ( element.clientWidth + element.scrollLeft >= element.scrollWidth ) { //at the bottom
		downelement.style.display = "none";
	} else if ( element.clientWidth + element.scrollLeft < element.scrollWidth ) {
		downelement.style.display = "block";
	}
	
	if ( element.scrollLeft == 0 ) { //at the top
		upelement.style.display = "none";
	} else if ( element.scrollLeft > 0) {
		upelement.style.display = "block";
	}
}
if ( document.getElementById("innervideoplaylisthorizontal") ) {	//if playlist exits, force the UL list to be the right width
	ulelement = document.getElementById("innervideoplaylisthorizontal");
	listlength = 0;
	for (i=0; i < ulelement.childNodes.length; i++) {
		 listlength += 165; //width of each element with padding
	}
	
	if (ulelement.childNodes.length == 1) {	//center the li if there's only one
		ulelement.childNodes[0].style.marginLeft = "165px";
		 listlength += 165;
	} else if (ulelement.childNodes.length == 2) { // center if there's only two
		ulelement.childNodes[0].style.marginLeft = "82px";
		 listlength += 82;
	}
	
	//set the UL to be the right length
	ulelement.style.width = listlength + "px";
}
if ( document.getElementById("videoplaylisthorizontal") ) {	//if playlist exits, set the buttons
	checkScrollButtonStatusH("videoplaylisthorizontal","videoplaylistleft","videoplaylistright");
}