﻿window.onload = initAll;

var xhr = false;
var imageRoot = "/images/slides/snap";
var maxImage = 694;
var currentImage = 0;

function initAll() {
    // Make sure this page is not displayed within a frame
    if (top.location != self.location) { top.location.replace(self.location); }

    var docBody = document.getElementsByTagName("body")[0];
    var navSpan = document.getElementById("navSpan");
    var foundNavL = true;
    
    if (!document.getElementById("navL")) { 
        foundNavL = false;
        var navL = document.createElement("div");
        navL.setAttribute("id", "navL");
    }
    if (!foundNavL) { navSpan.appendChild(navL); }
    
    if (window.XMLHttpRequest) { xhr = new XMLHttpRequest(); }
    else { if (window.ActiveXObject) { try { xhr = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { } }}

    if (xhr) {
	    xhr.onreadystatechange = getNavL;
	    xhr.open("GET", "/navL.html", true);
	    xhr.send(null);
    }

    document.onmouseover = rollon;
    document.onmouseout = rolloff;
    UpdateIt();
    setTimeout("updateImage()", 5000);
    // setTimeout("updateAward()", 8000);
}

function getNavL() {
	if (xhr.readyState == 4) {
		if (xhr.status == 200) {
			if (xhr.responseXML) { 
			    var tempDiv = document.createElement("div");
			    tempDiv.innerHTML = xhr.responseText;
			    var divLhtml = tempDiv.getElementsByTagName("div")["navLhtml"];
			    var navL = document.getElementById("navL");
			    navL.appendChild(divLhtml);
			}
		}
	}
}

function updateImage() {
    fileName = getImageFilename();
    document.getElementById('slide').src = fileName;
    setTimeout("updateImage()", 5000);
}

function rollon(e) {
    var targ;
    if (!e) var e = window.event;
    if (e.target) targ = e.target;
    else if (e.srcElement) targ = e.srcElement;
    if (targ.title != "") {
        document.getElementById('helpText').style.display = "block";
        document.getElementById('helpText').innerHTML = "<p>" + targ.title + "</p>";
    }
}

function rolloff() {
    if (document.getElementById('helpText').style.display == "block") document.getElementById('helpText').style.display = "none";
}

function flip(what) {
    if (what.style.display == "none")
        what.style.display = "block" 
    else 
        what.style.display="none"; 
}

function UpdateIt() {
    setTimeout("UpdateIt()", 200);
    if (navigator.appName == "Microsoft Internet Explorer")
        document.getElementById('helpText').style.top = document.body.scrollTop;
    else if (document.getElementById('helpText')!=null) {
        document.getElementById('helpText').style.top = window.pageYOffset;
    }
}

function Right(str, num)
{
  return str.substring(str.length-num);  // pull out right num
}

function getImageFilename() {
    if (--currentImage < 0) currentImage = maxImage;
    return imageRoot + Right("00000000000" + currentImage, 4) + ".jpg"
}
