/*------------------------CONGRESSMAN MOORE OFFICIAL SITE-----------------------
-- File: Functions.js (standard Javascript Functions)
-- Description: Included in every page, standard functions used throughout the 
-- site.
-- Created: 5/25/06
-- Author: Kenny Johnston
-- Updates:
-- 1.0 Moved all functions imbedded in HTML to this file (kj)
------------------------------------------------------------------------------*/
	var interval = 5; // delay between rotating images (in seconds)
	var random_display = 0; // 0 = no, 1 = yes
	interval *= 1000;

	var image_index = 0;
	image_list = new Array();
	image_list[image_index++] = new imageItem("/Resources/images/topbarimageHEADER-1.jpg");
	image_list[image_index++] = new imageItem("/Resources/images/topbarimageHEADER-2.jpg");
	image_list[image_index++] = new imageItem("/Resources/images/topbarimageHEADER-3.jpg");
	image_list[image_index++] = new imageItem("/Resources/images/topbarimageHEADER-4.jpg");
	image_list[image_index++] = new imageItem("/Resources/images/topbarimageHEADER-5.jpg");
	var number_of_image = image_list.length;

/*------------------------------------------------------------------------------
-- START FUNCTION: Print Function (depreciated)
------------------------------------------------------------------------------*/
var gAutoPrint = false; // Flag for whether or not to automatically call the print function
function printSpecial(){
 if (document.getElementById != null){
   var html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"\n"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n<head>';
   if (document.getElementsByTagName != null){
      var headTags = document.getElementsByTagName("head");
      if (headTags.length > 0){
        html += headTags[0].innerHTML;  
        html += '<link rel="stylesheet" type="text/css" href="/Resources/styles/print.css"/>\n</head>\n<body><div id="wrapper">\n';  
        var printReadyElem = document.getElementById("wrapper");  
        if (printReadyElem != null){
          html += printReadyElem.innerHTML;}
        else{
          alert("Could not find the printReady section in the HTML");
          return;}
        html += '\n</div></body>\n</html>';
        var printWin = window.open("","printSpecial");
        printWin.document.open();
        printWin.document.write(html);
        printWin.document.close();
        if (gAutoPrint){
          printWin.print();
        }
      }
    }
  }
 else{
    alert("Sorry, the print ready feature is only available in modern browsers.");
 }
}
/*------------------------------------------------------------------------------
-- END FUNCTION
------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------
-- START FUNCTION: to create related list in IE
------------------------------------------------------------------------------*/
startList = function() {
if (document.all&&document.getElementById) {
  navRoot = document.getElementById("linkbar");
  if (navRoot==null){
  }
  else{ for (i=0; i<navRoot.childNodes.length; i++) {
    node = navRoot.childNodes[i];
      if (node.nodeName=="LI") {
        node.onmouseover=function() {this.className+=" over";}
        node.onmouseout=function() {this.className=this.className.replace(" over", "");}
      }
    }
  }
  }
}
/*------------------------------------------------------------------------------
-- END FUNCTION
------------------------------------------------------------------------------*/

function imageItem(image_location) {
	this.image_item = new Image();
	this.image_item.src = image_location;
}

function get_ImageItemLocation(imageObj) {
	return(imageObj.image_item.src)
}

function generate(x, y) {
	var range = y - x + 1;
	return Math.floor(Math.random() * range) + x;
}

function getNextImage() {
	if (random_display) {
	image_index = generate(0, number_of_image-1);
	}
	else {
	image_index = (image_index+1) % number_of_image;
	}
	var new_image = get_ImageItemLocation(image_list[image_index]);
	return(new_image);
}

function rotateImage(place) {
	var new_image = getNextImage();
	document[place].src = new_image;
	var recur_call = "rotateImage('"+place+"')";
	setTimeout(recur_call, interval);
}

/*------------------------------------------------------------------------------
-- START FUNCTION: Code to execute on load
------------------------------------------------------------------------------*/
function init(){
	startList();
	rotateImage('headerimage');
}
/*------------------------------------------------------------------------------
-- END FUNCTION: 
------------------------------------------------------------------------------*/
