function preloadImages() { 
  if (document.images) {
    var imgFiles = preloadImages.arguments;
    if (document.preloadArray==null) document.preloadArray = new Array();
    var i = document.preloadArray.length;
    with (document) 
	  for (var j=0; j<imgFiles.length; j++) {
	          preloadArray[i] = new Image;
        	  preloadArray[i++].src = imgFiles[j];
  		  }
   }
}

function swapImgRestore() {
  if (document.swapImgData != null)
    for (var i=0; i<(document.swapImgData.length-1); i+=2)
      document.swapImgData[i].src = document.swapImgData[i+1];
}

function swapImage() { 
  var j=0,objStr,obj,swapArray=new Array,oldArray=document.swapImgData;
  for (var i=0; i < (swapImage.arguments.length-1); i+=2) {
    objStr = swapImage.arguments[(navigator.appName == 'Netscape')?i:i+1];
    if ((objStr.indexOf('document.layers[')==0 && document.layers==null) ||
        (objStr.indexOf('document.all[')   ==0 && document.all   ==null))
      objStr = 'document'+objStr.substring(objStr.lastIndexOf('.'),objStr.length);
    obj = eval(objStr);
    if (obj != null) {
      swapArray[j++] = obj;
      swapArray[j++] = (oldArray==null || oldArray[j-1]!=obj)?obj.src:oldArray[j];
	  //alert(swapImage.arguments[i+2]);
      obj.src = swapImage.arguments[i+2];
  } }
  document.swapImgData = swapArray; //used for restore
}

function setMenuTop() {
  // This function attempts to keep the menu visible on the screen
  // at all times, regardless of how far down the page the user
  // may have scrolled.
//This fx was disabled per Scott 7/13/2004 based on the reason that our menus are so long they can no longer scroll and be visible.
//This code was commented out here instead of ripping through the 50 files that reference this - CL 
//  if(document.all)
//    if(document.all.divMenu) {
      // this version will allow the menu to slide to the top of the page
      // but will start moving it downward as soon as it would go off the top.
//      if(document.body.scrollTop>110)
//        document.all.divMenu.style.pixelTop = document.body.scrollTop - 110;
//      else
//        document.all.divMenu.style.pixelTop = 0;
        
      // this version would keep initial position relative to page top
      //document.all.divMenu.style.pixelTop = document.body.scrollTop;
//      }
}

//make blink
window.onerror = null;
 var bName = navigator.appName;
 var bVer = parseInt(navigator.appVersion);
 var NS4 = (bName == "Netscape" && bVer >= 4);
 var IE4 = (bName == "Microsoft Internet Explorer" 
 && bVer >= 4);
 var NS3 = (bName == "Netscape" && bVer < 4);
 var IE3 = (bName == "Microsoft Internet Explorer" 
 && bVer < 4);
 var blink_speed=500;
 var i=0;
 
if (NS4 || IE4) {
 if (navigator.appName == "Netscape") {
 layerStyleRef="layer.";
 layerRef="document.layers";
 styleSwitch="";
 }else{
 layerStyleRef="layer.style.";
 layerRef="document.all";
 styleSwitch=".style";
 }
}

//BLINKING
function Blink(layerName){
 if (NS4 || IE4) { 
 if(i%2==0)
 {
 eval(layerRef+'["'+layerName+'"]'+
 styleSwitch+'.visibility="visible"');
 }
 else
 {
 eval(layerRef+'["'+layerName+'"]'+
 styleSwitch+'.visibility="hidden"');
 }
 } 
 if(i<1)
 {
 i++;
 } 
 else
 {
 i--
 }
 setTimeout("Blink('"+layerName+"')",blink_speed);
}

/* Scipt added to create pop up window for messaging alerts or anything
 * Version: 20060314
 * www.jtricks.com/javascript/window/box.html
 */
// Moves the box object to be directly beneath an object.
function move_box(an, box, topOffSet, leftOffSet)
{	
    var cleft = leftOffSet;
    var ctop = topOffSet;
    var obj = an;

    while (obj.offsetParent)
    {
        cleft += obj.offsetLeft;
        ctop += obj.offsetTop;
        obj = obj.offsetParent;
    }

    box.style.left = cleft + 'px';

    ctop += an.offsetHeight + 8;

    // Handle Internet Explorer body margins,
    // which affect normal document, but not
    // absolute-positioned stuff.
    if (document.body.currentStyle &&
        document.body.currentStyle['marginTop'])
    {
        ctop += parseInt(
            document.body.currentStyle['marginTop']);
    }

    box.style.top = ctop + 'px';
}

// Shows a box if it wasn't shown yet or is hidden
// or hides it if it is currently shown
function show_hide_box(an, width, height, topOffSet, leftOffSet, borderStyle)
{
    var href = an.href;
    var boxdiv = document.getElementById(href);

    if (boxdiv != null)
    {
        if (boxdiv.style.display=='none')
        {
            // Show existing box, move it
            // if document changed layout
            move_box(an, boxdiv, topOffSet, leftOffSet);
            boxdiv.style.display='block';
        }
        else
            // Hide currently shown box.
            boxdiv.style.display='none';
        return false;
    }

    // Create box object through DOM
    boxdiv = document.createElement('div');

    // Assign id equalling to the document it will show
    boxdiv.setAttribute('id', href);

    boxdiv.style.display = 'block';
    boxdiv.style.position = 'absolute';
    boxdiv.style.width = width + 'px';
    boxdiv.style.height = height + 'px';
    boxdiv.style.border = borderStyle;
    boxdiv.style.textAlign = 'right';
    boxdiv.style.padding = '2px';
    boxdiv.style.background = '#FFFFFF';
    document.body.appendChild(boxdiv);

    var offset = 0;    

    var contents = document.createElement('iframe');
    contents.scrolling = 'no';
    contents.overflowX = 'scroll';
    contents.overflowY = 'scroll';
    contents.frameBorder = '0';
    contents.style.width = width + 'px';
    contents.style.height = (height - offset) + 'px';

    boxdiv.appendChild(contents);

    move_box(an, boxdiv, topOffSet, leftOffSet);

	// Remove the following code if 'Close' hyperlink
    // is not needed.	
	var close_div = document.createElement('div');
    var close_button = document.createElement('button');	
    close_button.href = 'javascript:void(0);';
	close_button.style.fontSize = '12px';	
    close_button.onclick = function()
        { show_hide_box(an, width, height, borderStyle); }	
	close_div.style.textAlign = 'center';
	//append close button to div tag
	close_div.appendChild(close_button);	
    close_button.appendChild(document.createTextNode('Close Window'));   
	boxdiv.appendChild(close_div);
    offset = 0;
	
    // End of 'Close' hyperlink code.
	
    if (contents.contentWindow)
        contents.contentWindow.document.location.replace(
            href);
    else
        contents.src = href;

    // The script has successfully shown the box,
    // prevent hyperlink navigation.
    return false;
}

//added by Moua for rotating click button for Scott for UAM presentation
//on 9/29/2004
index1 = '';
function loadpage() { 
index1 = 0;
listofimages = new Array(4);
listofimages[0] = new Image(430,58)
listofimages[0].src = "../images/btn_telemetry.gif"
listofimages[1] = new Image(430,58)
listofimages[1].src = "../images/btn_telemetry_flash.gif"

thetimer = setTimeout("changeimage()", 600);

} 

function changeimage(){ 
index1 = index1 + 1
if (index1 == "2") { 
index1 = 0 
} 
imagesource = listofimages[index1].src
window.document.banner1.src = imagesource

thetimer = setTimeout("changeimage()", 600);

} 

function changepage() { 
	checkindex = index1;
	if ((checkindex == 0) || (checkindex == 1) || (checkindex == '')) {


		window.parent.location.reload( false )
		newlocation = "http://64.80.26.83:8090/coriolis/pgmon.php?BUID=13&PumpGroupName=Lake+Winnebago&PumpGroupID=2&CUSTDatabase=coriolis&pickday=0" 
		window.open(newlocation, "UAM")
	}
} 
//end of Moua's addition for Scott

//Please do not touch sliding menu (START)
//fading lite up menu
function lite(obj) 
{
	if(document.all&&!window.opera) 
	{
		obj.filters.blendTrans.apply(); 
		obj.filters.blendTrans.play(); 
	} 
} 	
	
var TIMER_SLIDE = null;
var IMG_URL = 'www.carmodydata.com';
//var IMG_URL = 'localhost';
var OBJ_CLICK;
var OBJ_SLIDE;
var OBJ_VIEW;
var PIX_SLIDE = 20; //this is the amount of slide/DELAY_SLIDE
var NEW_PIX_VAL;
var DELAY_SLIDE = 30; //this is the time between each call to slide
var DIV_HEIGHT = 10; //value irrelevant
var SUB_MENU_NUM =0;
var RE_INIT_OBJ = null;
var bMenu = document.getElementById("curMenu");
var MainDiv,SubDiv

//DD added code
document.write('<div id="tempcontainer" class="mainDiv" style="visibility: hidden; position: absolute"></div>')
//alert that cookies are not turned on
function testSessionCookie() 
{
  document.cookie ="testSessionCookie=Enabled";
  if (getCookieValue ("testSessionCookie")=="Enabled")
    return true 
  else
    return false;
}
//return cookie value
function getCookieValue (cookieName) 
{
  var exp = new RegExp (escape(cookieName) + "=([^;]+)");
  if (exp.test (document.cookie + ";")) 
  {
    exp.exec (document.cookie + ";");
    return unescape(RegExp.$1);
  }
  else return false;
}
//write persistent cookie
function writePersistentCookie(CookieName, CookieValue, periodType, offset) {

  var expireDate = new Date ();
  offset = offset / 1;
  
  var myPeriodType = periodType;
  switch (myPeriodType.toLowerCase()) {
    case "years":
      expireDate.setYear(expireDate.getFullYear()+offset);
      break;
    case "months":
      expireDate.setMonth(expireDate.getMonth()+offset);
      break;
    case "days":
      expireDate.setDate(expireDate.getDate()+offset);
      break;
    case "hours":
      expireDate.setHours(expireDate.getHours()+offset);
      break;
    case "minutes":
      expireDate.setMinutes(expireDate.getMinutes()+offset);
      break;
    default:
      alert ("Invalid periodType parameter for writePersistentCookie()");
      break;
  }   
  document.cookie = escape(CookieName ) + "=" + escape(CookieValue) + "; expires=" + expireDate.toGMTString() + "; path=/";
}  
//change state of cookie value
function ChangeCookieState(objSubMenu, objMenuState)
{	
//	alert ('The name = ' + objSubMenu + ' value of the Cookie is "' + getCookieValue (myCookieName) + '"');
	var myCookieName = document.getElementById(objSubMenu).value;  	
//alert ('cookie name: ' + objSubMenu + ' cookie value: ' + getCookieValue (myCookieName));	
	if (testSessionCookie()) 
	{
		if (getCookieValue(myCookieName))
		{
			//cookie exists already
//			alert ('The value of the Cookie is "' + getCookieValue (myCookieName) + '"');
			writePersistentCookie(objSubMenu, objMenuState, "days", 365);
		}						
		else
		{
			//cookie does not exist so create it		
//			alert ('The value of the Cookie is "' + getCookieValue (myCookieName) + '"');
			writePersistentCookie(objSubMenu, objMenuState, "days", 365);
		}
	}
	  else
	{
//		alert ("Sorry - session cookies are currently disabled."); 
	}	
}

//START OF SLIDING MENUS
function Init(objDiv)
{	
	OBJ_CLICK = objDiv.id;
    if (TIMER_SLIDE == null)
    {
        SUB_MENU_NUM = 0;
        MainDiv = objDiv.parentNode;
        SubDiv =  MainDiv.getElementsByTagName("DIV").item(0);
        SubDiv.onclick = SetSlide;
        
        OBJ_SLIDE = MainDiv.getElementsByTagName("DIV").item(1);
        OBJ_VIEW = OBJ_SLIDE.getElementsByTagName("DIV").item(0);
				document.getElementById("tempcontainer").innerHTML=MainDiv.getElementsByTagName("DIV").item(2).innerHTML //DD added code
				DIV_HEIGHT=document.getElementById("tempcontainer").offsetHeight //DD added code
        
        for (i=0;i<OBJ_VIEW.childNodes.length;i++)
        {
            if (OBJ_VIEW.childNodes.item(i).tagName == "SPAN")
            {
                SUB_MENU_NUM ++;
            }
        }   
       
              NEW_PIX_VAL = parseInt(MainDiv.getAttribute("state")); 
    }
}

function SetSlide()
{   
	  if (window.TIMER_SLIDE) clearInterval(TIMER_SLIDE) //DD added code
      if (TIMER_SLIDE == null && this.parentNode == MainDiv)
            TIMER_SLIDE = setInterval('RunSlide()', DELAY_SLIDE);
      else
      {
          RE_INIT_OBJ = this;
          setTimeout('ReInit()', 200);
      }
}

function ReInit(obj)
{
    Init(RE_INIT_OBJ);
    TIMER_SLIDE = setInterval('RunSlide()', DELAY_SLIDE);
    RE_INIT_OBJ = null;
}

function RunSlide()
{
	OBJ_MENU = document.getElementById(OBJ_CLICK);
    if (OBJ_VIEW.getAttribute("state") == 0)
    {
		OBJ_MENU.style.background = 'url(http://' + IMG_URL + '/images/btn_main_top.gif)';
        NEW_PIX_VAL += PIX_SLIDE;
		//minus a 7 to adjust the li height for the div  
		OBJ_SLIDE.style.height = NEW_PIX_VAL - 18;

        if (NEW_PIX_VAL >= DIV_HEIGHT) //DD modified code
        {
            clearInterval(TIMER_SLIDE);
            TIMER_SLIDE = null;
            OBJ_VIEW.style.display = 'inline';
            OBJ_VIEW.setAttribute("state","1")
            MainDiv.setAttribute("state",NEW_PIX_VAL);
			//write session cookies here
			ChangeCookieState(OBJ_CLICK, '1');
        }
    } else
    {		
		OBJ_MENU.style.background = 'url(http://' + IMG_URL + '/images/btn_main_top_down.gif)';
        OBJ_VIEW.style.display = 'none';
        NEW_PIX_VAL -= PIX_SLIDE;
        if(NEW_PIX_VAL > 0)OBJ_SLIDE.style.height = NEW_PIX_VAL;
        if (NEW_PIX_VAL <= 0)
        {
            NEW_PIX_VAL = 0;
            OBJ_SLIDE.style.height = NEW_PIX_VAL
            clearInterval(TIMER_SLIDE);
            TIMER_SLIDE = null;
            OBJ_VIEW.setAttribute("state","0")
            MainDiv.setAttribute("state",NEW_PIX_VAL);
			//write session cookies here, store a -1 because a value of 0 returns a false
			ChangeCookieState(OBJ_CLICK, '-1');
        }
    }
}

function onloadfunction()
{	
	var tempMain, OBJ_MENU;
	for (var i=1; i<=7; i++)
	{		
		tempMain = String('sub' + i);		
		if (document.getElementById(tempMain))
		{			
			OBJ_MENU = document.getElementById(tempMain);
//alert('cookie checked out!  cookie value = >' + (getCookieValue(tempMain) == '1') + '<>' + (testSessionCookie() == false) + '<>' + (getCookieValue(tempMain) == false) + '<>' + (getCookieValue(tempMain) != '0') + '<');
			if (getCookieValue(tempMain) == false) 
			{
				//first time coming into the page with no cookie set yet so show all menus
				OBJ_MENU.style.background = 'url(http://www.carmodydata.com/images/btn_main_top.gif)';
				MainDiv = document.getElementById(tempMain).parentNode;
				OBJ_SLIDE = MainDiv.getElementsByTagName("DIV").item(1);
				OBJ_VIEW = OBJ_SLIDE.getElementsByTagName("DIV").item(0);					
				OBJ_VIEW.style.display = 'inline';		
				OBJ_VIEW.setAttribute("state","1");
				MainDiv.setAttribute("state",0);
				//set cookie to one
				writePersistentCookie(tempMain, 1, "days", 365);
			}
			else if (getCookieValue(tempMain) == '1' || testSessionCookie() == false)
			{				
				//either cookie is set to 1 or user does not have cookies turned on
				OBJ_MENU.style.background = 'url(http://' + IMG_URL + '/images/btn_main_top.gif)';
				MainDiv = document.getElementById(tempMain).parentNode;
				OBJ_SLIDE = MainDiv.getElementsByTagName("DIV").item(1);
				OBJ_VIEW = OBJ_SLIDE.getElementsByTagName("DIV").item(0);										
				OBJ_VIEW.style.display = 'inline';		
				OBJ_VIEW.setAttribute("state","1");
				MainDiv.setAttribute("state",0);
				//set cookie to one
				writePersistentCookie(tempMain, 1, "days", 365);
			}			
			else
			{
				//chose to keep this collapsed
				//OBJ_MENU.style.background = 'url(http://www.carmodydata.com/images/btn_main_top_down.gif)';
				OBJ_MENU.style.background = 'url(http://' + IMG_URL + '/images/btn_main_top_down.gif)';
			}
		}
	}
}

//call this code each time the page loads
if (window.addEventListener)
window.addEventListener("load", onloadfunction, true)
else if (window.attachEvent)
window.attachEvent("onload", onloadfunction)
else if (document.getElementById)
window.onload=onloadfunction
// END OF SLIDING MENUS(END OF JS)