window.onload = loadFunctions;

function loadFunctions() {
	newWinLinks();
	initPage();
	navRoll();
	rotate();
	}

function navRoll() {
	var allLinks = document.getElementsByTagName("a");
	
	for (var i=0; i<allLinks.length; i++) {
		if (allLinks[i].className.indexOf("menuLink") > -1) {
			allLinks[i].onclick = function() {return false;}
			allLinks[i].onmouseover = toggleMenu;
		}
	}
}

function toggleMenu() {
	var startMenu = this.href.lastIndexOf("/")+1;
	var stopMenu = this.href.lastIndexOf(".");
	var thisMenuName = this.href.substring(startMenu,stopMenu);

	document.getElementById(thisMenuName).style.display = "block";

	this.parentNode.className = thisMenuName;
	this.parentNode.onmouseout = toggleDivOff;
	this.parentNode.onmouseover = toggleDivOn;	
}

function toggleDivOn() {
	document.getElementById(this.className).style.display = "block";
}

function toggleDivOff() {
	document.getElementById(this.className).style.display = "none";
}


function newWinLinks() {
	for (var i=0; i<document.links.length; i++) {
		if (document.links[i].className == "newWin") {
			document.links[i].onclick = newWindow;
		}
	}
}

function newWindow() {
	var dentistryWindow = window.open(this.href,"dentistryWin","width=600,height=675,toolbar=yes,left=0,top=50,resizable=yes,scrollbars=yes,addressbar=yes");
	dentistryWindow.focus();
	return false;
}


function initPage() {
	var now = new Date();
	var lastVisit = new Date(cookieVal("pageVisit"));
	var expireDate = new Date();
	expireDate.setMonth(expireDate.getMonth()+6);
	
	document.cookie = "pageVisit=" + now + ";expires=" + expireDate.toGMTString();
	var allGrafs = document.getElementsByTagName("p");
	
	for (var i=0; i<allGrafs.length; i++) {
		if (allGrafs[i].id.indexOf("New-") != -1) {
			newCheck(allGrafs[i],allGrafs[i].id.substring(4));
		}
	}	
	
	function newCheck(grafElement,dtString) {
		var yyyy = parseInt(dtString.substring(0,4),10);
		var mm = parseInt(dtString.substring(4,6),10);
		var dd = parseInt(dtString.substring(6,8),10);
		var lastChgd = new Date(yyyy,mm-1,dd);
			
		if (lastChgd.getTime() > lastVisit.getTime()) {
			grafElement.className = (grafElement.className == "") ? "newImg" : "newImg " + grafElement.className;
		}
	}
}

function cookieVal(cookieName) {
	var thisCookie = document.cookie.split("; ");

	for (var i=0; i<thisCookie.length; i++) {
		if (cookieName == thisCookie[i].split("=")[0]) {
			return thisCookie[i].split("=")[1];
		}
	}
	return "1 January 1970";
}

var adImages = new Array("images/reading1.gif","images/reading2.gif","images/reading3.gif");
var thisAd = 0;

function rotate() {
	thisAd++;
	if (thisAd == adImages.length) {
		thisAd = 0;
	}
	document.getElementById("adBanner").src = adImages[thisAd];

	setTimeout("rotate()", 3 * 1000);
}

			
						
