var dovideo = false;
//var dovideo = false;



/** note this puts roll over on image, not href **/
function initRollovers() 
{
    //if we don't support getElementById then exit
	if (!document.getElementById) return
	
	//yes it even does preload
	var aPreLoad = new Array();
	var aImages  = new Array();
	var sTempSrc;
	
	//grab all nav images
	//if(document.getElementById("dl-c-container")) {
	//var aImages = document.getElementById("dl-c-container").getElementsByTagName("img");
	//}

    //nb if you want all images on page  you do this instead (i only wanted nav)
    var aImages = document.getElementsByTagName("img");

    
    //loop over images
	for (var i = 0; i < aImages.length; i++) 
	{	
	
	    //we use class name to find image	
		if (aImages[i].className.match('nav-roll')) 
		{
		    //grab src
			var src = aImages[i].getAttribute('src');
			
			//grab extension (neato works for gif and jpg nd png if you so feel)
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			
			//create a new attribute for rollover (for fyi = '-over')			
			var hsrc = src.replace("_off"+ftype, '_over'+ftype);
			aImages[i].setAttribute('hsrc', hsrc);
			
			//PRELOAD !!
			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;
			
			//on mouseover grab hsrc
			aImages[i].onmouseover = function() 
			{
				sTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}	
			
			//on mouse out strip out "on"
			aImages[i].onmouseout = function() 
			{
			    //alert(sTempSrc);
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_over'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		} else if (aImages[i].className.match('logo-roll')) 
		{
		    //grab src
			var src = aImages[i].getAttribute('src');
			
			//grab extension (neato works for gif and jpg nd png if you so feel)
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			
			//create a new attribute for rollover (for fyi = '-over')			
			var hsrc = src.replace("_off"+ftype, '_over'+ftype);
			aImages[i].setAttribute('hsrc', hsrc);
			
			//PRELOAD !!
			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;
			
			//on mouseover grab hsrc
			aImages[i].onmouseover = function() 
			{
				sTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}	
			
			//on mouse out strip out "on"
			aImages[i].onmouseout = function() 
			{
			    //alert(sTempSrc);
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_over'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}
}



function show_fact(whichDiv, thishref)
{
	if (document.getElementById)
	{
	    thishref.innerHTML = "Hide Fact";
	    thishref.onclick = function() 
            {
                hide_fact(whichDiv, this);
            }	
	    show_div(whichDiv);
	}
	
	return false;
}



function hide_fact(whichDiv, thishref)
{
	if (document.getElementById)
	{
	    thishref.innerHTML = "Reveal Fact";
	    thishref.onclick = function() 
            {
                show_fact(whichDiv, this);
            }
	    hide_div(whichDiv);
	}
	
	return false;
}

function show(whichDiv, thishref)
{
	if (document.getElementById)
	{
	    thishref.innerHTML = "Hide Answer";
	    thishref.onclick = function() 
            {
                return hide(whichDiv, this);
            }	
	    show_div(whichDiv);
	}
	
	return false;
}



function hide(whichDiv, thishref)
{
	if (document.getElementById)
	{
	    thishref.innerHTML = "Show Answer";
	    thishref.onclick = function() 
            {
                return show(whichDiv, this);
            }
	    hide_div(whichDiv);
	}
	
	return false;
}

function show_div(whichDiv)
{
	if (document.getElementById)
	{
	    document.getElementById(whichDiv).style.display = 'block';
	}
	
	return false;
}

function hide_div(whichDiv)
{
	if (document.getElementById)
	{
	    document.getElementById(whichDiv).style.display = 'none';
	}
	
	return false;
}



function sidebar(thislink) {
    window.open(thislink.href, 'horiz', 'width=405,height=470,toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1'); return false;
}

/** puts pop ups on hrefs that need **/  
function initPopUps() 
{
    //if we don't support getElementById then exit
	if (!document.getElementById) return;

	
	//grab all hrefs from body
    var aHref = document.getElementsByTagName("a");

    var nnn = "";
    //loop over Hrefs
    for (var i = 0; i < aHref.length; i++) 
    {	
        //nnn += aHref[i].className + "\n";
        if (aHref[i].className.match('nolink')) 
        {
           
            //horizontal image pop up
            aHref[i].setAttribute('title', "launch in new window");
            
            //on mouseover grab hsrc
            aHref[i].onclick = function() 
            {
                window.open("pop_notdone.html", 'notdone', 'width=421,height=166,toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=1'); return false;
            }	
        }
    }
    //alert(nnn);

}


function initPage() {
     //change home image
    if(document.getElementById('rnd-img'))
    {
    	var r_img = document.getElementById('rnd-img');
    	var ranNum= Math.round(Math.random()*11);
    	
    	if(ranNum < 10) ranNum = '0'+ranNum;
    	//alert(ranNum);
    	r_img.setAttribute('src', 'i/home/circle_' + ranNum + '.gif');
    }
    
    initRollovers();
    initPopUps();
    if(dovideo)
    {    
        initVideo();
    }
    
    

}

function init() {
       // quit if this function has already been called
       if (arguments.callee.done) return;

       // flag this function so we don't do the same thing twice
       arguments.callee.done = true;

       // create the "page loaded" message
       //var text = document.createTextNode("Page loaded!");
       //var message = document.getElementById("message");
       //message.appendChild(text);
       initPage();
   };

   /* for Mozilla */
   if (document.addEventListener) {
       document.addEventListener("DOMContentLoaded", init, null);
   }

   /* for Internet Explorer */
   /*@cc_on @*/
   /*@if (@_win32)
       document.write("<script defer src=ie_onload.js><"+"/script>");
   /*@end @*/

   /* for other browsers */
   window.onload = init;

/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, expires, path, domain, secure)
{
    
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "; path=/") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");

}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return false;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" + 
            ((path) ? "; path=" + path : "; path=/") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

