// START: Vertical Scroller
var scrollerdelay = '3000'; //delay between msg scrolls. 4000=4 seconds.
var distance = "1"; //distance of movement between frames
var framerate = "50"; //time in between movement
if(document.all) { //IE's animation is faster
	var distance = "1";
	var framerate = "50";
}
var messages=new Array();
var gotMessages = 0;
var msgCount = 0;
var shock = 0;

function getMessages() {
	var p = document.getElementById("msgs");
	var divs = p.getElementsByTagName("div");
	
	for(j=0; j<divs.length; j++) {
		if(divs[j].className == "message") {
			messages.push(divs[j].innerHTML);
		}
	}
	gotMessages = 1;
	p.innerHTML = "";
}

function initMessage() {
	var spot = document.getElementById("msgs");
	spot.innerHTML = "";
	var d = document.createElement("div");
	d.innerHTML = messages[msgCount];
	d.id = "scrollie";
	d.style.position = "absolute";
	d.style.top = spot.offsetHeight + "px";
	spot.appendChild(d);
	msgCount++;
	if(msgCount > (messages.length-1)) { msgCount = 0; }
}

function moveAway() {
	var d = document.getElementById("scrollie");
	var y = d.style.top.slice(0,-2);
	y = y-distance;
	d.style.top = y + "px";
	if(Math.abs(y) < d.offsetHeight) { 
		var t = window.setTimeout(moveAway, framerate); 
	} else {
		initMessage();
		moveMessage();
	}
}
	
function moveMessage() {
	var d = document.getElementById("scrollie");
	var y = d.style.top.slice(0,-2);
	y = y-distance;
	d.style.top = y + "px";
	if(y > 0) {
		var t = window.setTimeout(moveMessage, framerate);
	} else {
		var s = window.setTimeout(moveAway, scrollerdelay);
	}
}

function startscroll() {
	if(!gotMessages) {
		getMessages(); 
		initMessage();
		moveMessage();
	} else {
		moveAway(); 
	}
	//var s = window.setTimeout(startscroll, scrollerdelay);
}
// END: Vertical Scroller
// START: Next-Generation Marquee
var scrlSpeed=1
// decreasing speed for mozilla
scrlSpeed=(document.all)? scrlSpeed : Math.max(1, scrlSpeed-1)

function initScroll(booyah,object){
	if (document.getElementById(booyah) != null){
		var contObj=document.getElementById(booyah);
		var obj=document.getElementById(object);
		contObj.style.visibility = "visible";
		contObj.scrlSpeed = scrlSpeed; 
		widthContainer = contObj.offsetWidth;
		obj.style.left=parseInt(widthContainer)+"px";
		widthObject=obj.offsetWidth;
		interval=setInterval("objScroll('"+ booyah +"','"+ object +"',"+ widthContainer +")",20);
		contObj.onmouseover = function(){
			contObj.scrlSpeed=0;
		}
		contObj.onmouseout = function(){
			contObj.scrlSpeed=scrlSpeed;
		}	
	}
}
function objScroll(booyah2,object,widthContainer){
	var contObj=document.getElementById(booyah2);
	var obj=document.getElementById(object);
	widthObject=obj.offsetWidth;
	if (parseInt(obj.style.left)>(widthObject*(-1))){
		obj.style.left=parseInt(obj.style.left)-contObj.scrlSpeed+"px";
	} else {
		obj.style.left=parseInt(widthContainer)+"px";
	}
} 

// END: Next-Generation Marquee

// Fix for IE, as it doesn't support CSS tables properly

/*
This function loads other functions once the page has loaded
*/

setActions = function()
{
	ieUser = getInternetExplorerVersion();
	if (ieUser != -1){
		
		// Check if the user has IE 7 or below (assuming IE 8 will do this - but who knows?)
		if (ieUser < 8){
				doHeight();
		}
	}
}

/*
End load other functions
*/


/*
Height resizer
*/

/*
function doHeight()
{
	var bodyHeight
	var center_squareHeight
	var containerHeight


	// Work out the heights of all 3 divs
	bodyHeight = document.body.offsetHeight
	center_squareHeight = document.getElementById("center_square").offsetHeight
	containerHeight = document.getElementById("container").offsetHeight
	
		
	// Calculations for white center_square
	// Calculate the margin the center_square should have
	center_squareMargin = Math.floor((bodyHeight - center_squareHeight) / 2)
	
	// Set a new top margin
	document.getElementById("center_square").style.marginTop = (center_squareMargin - 0)  + "px"


	// Calculations for container in white center_square
	
	// Calculate the margin the container should have
	containerMargin = Math.floor((center_squareHeight - containerHeight) / 2)
	
	// Set a new top margin
	document.getElementById("container").style.marginTop = (containerMargin - 0)  + "px"	
	
}
*/

/*
End Height resizer
*/


/*
IE Browser detect from MSDN.com
*/

function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}

/*
End IE browser detect
*/

// on page load we initiate scrolling and pagecenterer
window.onload=function(){	
	initScroll("scrlContainer", "scrlContent");
	startscroll();
	setActions();
}

// on page resize we load the page centerer function
window.onresize=setActions;


// START: IE :hover fix for css dropdown menu
sfHover = function() {
	var sfEls = document.getElementById("navbar").getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+="sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp("sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
