// JavaScript Document

var totalDivs=0;
opacity = 0;
var currentDiv=0;
var tickspeed=8000;

function getDiv(i) {
	var count=0;
	var bb = document.getElementById("billboard");
	var child = bb.firstChild;
	while(child != null) {
		if (child.nodeType == 1) {
			count++;
		}
		if (count==i+1)
			return child;
		else
			child = child.nextSibling;
	}
	return null;
}

function nextBoard() {
	var child = getDiv(currentDiv);
	child.style.display="none";
	currentDiv=(currentDiv<totalDivs-1)? currentDiv+1 : 0;
	child = getDiv(currentDiv);
	child.style.display="block";	
	setTimeout("nextBoard()", tickspeed);	
	fadeIn(20);
}

function startbb() {
	var bb = document.getElementById("billboard");
	
	if(bb != null)
	{
		var child = bb.firstChild;
		while(child != null) {
			if (child.nodeType == 1) {
				child.style.display="none";
				totalDivs++;
			}
			child = child.nextSibling;
		}
		if (totalDivs>0) {
			currentDiv=Math.floor(Math.random()*totalDivs); 
			bb.className=bb.className.replace(" hide", "");
			
			setTimeout("nextBoard()", 0);	
		}
	}
}

function submitForm(containerElement) {
      var theForm = document.createElement("form");
      	  theForm.action = 'https://webproc.mnscu.edu/admissions/?campusId=206';
          theForm.method = "post";
          theForm.innerHTML = document.getElementById(containerElement).outerHTML;
      var formToSubmit = document.body.appendChild(theForm);
          formToSubmit.submit();
}

function CancelForm(containerElement) {
      var theForm = document.createElement("form");
      	  theForm.action = 'http://beta.saintpaul.edu/Pages/ApplyNow.aspx';
          theForm.method = "post";
          theForm.innerHTML = document.getElementById(containerElement).outerHTML;
      var formToSubmit = document.body.appendChild(theForm);
          formToSubmit.submit();
}

function fadeIn(opacity)
{
	var child = getDiv(currentDiv);
	if (getDiv(currentDiv)) {
		if (opacity <= 100) {
			if (child.style.MozOpacity!=null) {
				child.style.MozOpacity = (opacity/100)+.001;
			} else if (child.style.opacity!=null) {
				child.style.opacity = (opacity/100)+.001;
			} else if (child.style.filter!=null) {
				child.style.filter = "alpha(opacity="+opacity+")";
			}
			opacity += 25;
			window.setTimeout("fadeIn("+opacity+")", 100);
		}
	}
}
   
if (window.addEventListener) {window.addEventListener("load", startbb, false);}
else if (window.attachEvent) {window.attachEvent("onload", startbb);}
else if (document.getElementById) {window.onload=startbb;}



