// JavaScript Document

  // this function is needed to work around 
  // a bug in IE related to element attributes
  function hasClass(obj) {
     var result = false;
     if (obj.getAttributeNode("class") != null) {
         result = obj.getAttributeNode("class").value;
     }
     return result;
  }  
  

 function stripe(id, evenColor, oddColor) {

    // the flag we'll use to keep track of 
    // whether the current row is odd or even
    var even = false;

    // if arguments are provided to specify the colours
    // of the even & odd rows, then use the them;
    // otherwise use the following defaults:
    var evenColor = arguments[1] ? arguments[1] : "#fff";
    var oddColor = arguments[2] ? arguments[2] : "#eee"; 
    // obtain a reference to the desired table
    // if no such table exists, abort
    var table = document.getElementById(id);
	
    if (! table) { return; }
    
    // by definition, tables can have more than one tbody
    // element, so we'll have to get the list of child
    // &lt;tbody&gt;s 
    var tbodies = table.getElementsByTagName("tbody");

    // and iterate through them...
    for (var h = 0; h < tbodies.length; h++) {
    
     // find all the &lt;tr&gt; elements... 
      var trs = tbodies[h].getElementsByTagName("tr");
      
      // ... and iterate through them
      for (var i = 0; i < trs.length; i++) {

        // avoid rows that have a class attribute
        // or backgroundColor style
        if (! hasClass(trs[i]) &&
            ! trs[i].style.backgroundColor) {
 		  
          // get all the cells in this row...
          var tds = trs[i].getElementsByTagName("td");
        
          // and iterate through them...
          for (var j = 0; j < tds.length; j++) {
        
            var mytd = tds[j];

            // avoid cells that have a class attribute
            // or backgroundColor style
            if (! hasClass(mytd) &&
                ! mytd.style.backgroundColor) {
        
              mytd.style.backgroundColor =
                even ? evenColor : oddColor;
            
            }
          }
        }
        // flip from odd to even, or vice-versa
        even =  ! even;
      }
    }
 }
 


	// please keep these lines on when you copy the source
	// made by: Nicolas - http://www.javascript-page.com
	var currentdate = 0
	var core = 0
	function StringArray (n) {
	  this.length = n;
	  for (var i =1; i <= n; i++) {
		this[i] = ' '
	  }
	}
	adimage = new StringArray(12)
	adimage[0] = 'images/siteimages/homepage/hp_ad_arts.jpg'
	adimage[1] = 'images/siteimages/homepage/hp_ad_books.jpg'
	adimage[2] = 'images/siteimages/homepage/hp_ad_each_other.jpg'
	adimage[3] = 'images/siteimages/homepage/hp_ad_experiences.jpg'
	adimage[4] = 'images/siteimages/homepage/hp_ad_ideas.jpg'
	adimage[5] = 'images/siteimages/homepage/hp_ad_ideas.jpg'
	adimage[6] = 'images/siteimages/homepage/hp_ad_internet.jpg'
	adimage[7] = 'images/siteimages/homepage/hp_ad_knowledge.jpg'
	adimage[8] = 'images/siteimages/homepage/hp_ad_music.jpg'
	adimage[9] = 'images/siteimages/homepage/hp_ad_video.jpg'
	adimage[10] = 'images/siteimages/homepage/hp_ad_whats_new.jpg'
	adimage[11] = 'images/siteimages/homepage/hp_ad_wifi.jpg'
	
	genimage = new StringArray(12)
	genimage[0] = '../images/siteimages/general/gen_images_01.jpg'
	genimage[1] = '../images/siteimages/general/gen_images_04.jpg'
	genimage[2] = '../images/siteimages/general/gen_images_09.jpg'
	genimage[3] = '../images/siteimages/general/gen_images_12.jpg'
	genimage[4] = '../images/siteimages/general/gen_images_15.jpg'
	genimage[5] = '../images/siteimages/general/gen_images_21.jpg'
	genimage[6] = '../images/siteimages/general/gen_images_23.jpg'
	genimage[7] = '../images/siteimages/general/gen_images_30.jpg'
	genimage[8] = '../images/siteimages/general/gen_images_34.jpg'
	genimage[9] = '../images/siteimages/general/gen_images_39.jpg'
	genimage[10] = '../images/siteimages/general/gen_images_05.jpg'
	genimage[11] = '../images/siteimages/general/gen_images_02.jpg'
	
	kidimage = new StringArray(12)
	kidimage[0] = '../images/siteimages/kids/kids_images_01.jpg'
	kidimage[1] = '../images/siteimages/kids/kids_images_02.jpg'
	kidimage[2] = '../images/siteimages/kids/kids_images_17.jpg'
	kidimage[3] = '../images/siteimages/kids/kids_images_04.jpg'
	kidimage[4] = '../images/siteimages/kids/kids_images_20.jpg'
	kidimage[5] = '../images/siteimages/kids/kids_images_06.jpg'
	kidimage[6] = '../images/siteimages/kids/kids_images_07.jpg'
	kidimage[7] = '../images/siteimages/kids/kids_images_08.jpg'
	kidimage[8] = '../images/siteimages/kids/kids_images_09.jpg'
	kidimage[9] = '../images/siteimages/kids/kids_images_14.jpg'
	kidimage[10] = '../images/siteimages/kids/kids_images_11.jpg'
	kidimage[11] = '../images/siteimages/kids/kids_images_12.jpg'
	
	teenimage = new StringArray(12)
	teenimage[0] = '../images/siteimages/teens/teen_images_01.jpg'
	teenimage[1] = '../images/siteimages/teens/teen_images_02.jpg'
	teenimage[2] = '../images/siteimages/teens/teen_images_03.jpg'
	teenimage[3] = '../images/siteimages/teens/teen_images_04.jpg'
	teenimage[4] = '../images/siteimages/teens/teen_images_05.jpg'
	teenimage[5] = '../images/siteimages/teens/teen_images_06.jpg'
	teenimage[6] = '../images/siteimages/teens/teen_images_07.jpg'
	teenimage[7] = '../images/siteimages/teens/teen_images_09.jpg'
	teenimage[8] = '../images/siteimages/teens/teen_images_12.jpg'
	teenimage[9] = '../images/siteimages/teens/teen_images_13.jpg'
	teenimage[10] = '../images/siteimages/teens/teen_images_14.jpg'
	teenimage[11] = '../images/siteimages/teens/teen_images_15.jpg'
	
var ranad = 60/adimage.length
	  function ranadimage() {
	  currentdate = new Date()
	  core = currentdate.getSeconds()
	  core = Math.floor(Math.random())
	  	return(adimage[core])
	}
	function writeadpic(){document.write("<img src='" +ranadimage()+ "' width='384' height='186' alt='Explore. Learn. Connect.'>")}

var rangen = 60/genimage.length
	
	function rangenimage() {
	  currentdate = new Date()
	  core = currentdate.getSeconds()
	  core = Math.floor(core/rangen)
		return(genimage[core])
	}
	function writegenpic(){document.write("<img src='"+rangenimage()+ "' width='156' id='pagepicture' alt='Your Worcester Public Library' />")}
	
var rankid = 60/kidimage.length
	
		function rankidimage() {
	  currentdate = new Date()
	  core = currentdate.getSeconds()
	  core = Math.floor(core/rankid)
		return(kidimage[core])
	}
	function writekidpic(){document.write("<img src='"+rankidimage()+ "' width='156' id='pagepicture' alt='Your Worcester Public Library' />")}
	
var ranteen = 60/teenimage.length
		function ranteenimage() {
	  currentdate = new Date()
	  core = currentdate.getSeconds()
	  core = Math.floor(core/ranteen)
		return(teenimage[core])
	}
	function writeteenpic(){document.write("<img src='"+ranteenimage()+ "' width='156' id='pagepicture' alt='Your Worcester Public Library' />")}	
	
// This is what goes on the page: <script>writegenpic();</script > 
// (   or writekidpic(); or writeteenpic();   )
// This is what goes on the page to display if the browser
// does not support scripts:
// <noscript><img src="../images/yourimagepath/yourimage.jpg" id="pagepicture" /></noscript>

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


//Ming ad rotate automatic script July 2, 2010
adImages = new Array("images/siteimages/homepage/hp_ad_arts.jpg",
					 "images/siteimages/homepage/hp_ad_books.jpg",
					 "images/siteimages/homepage/hp_ad_each_other.jpg",
					 "images/siteimages/homepage/hp_ad_experiences.jpg",
					 "images/siteimages/homepage/hp_ad_ideas.jpg",
					 "images/siteimages/homepage/hp_ad_ideas.jpg",
					 "images/siteimages/homepage/hp_ad_internet.jpg",
					 "images/siteimages/homepage/hp_ad_knowledge.jpg",
					 "images/siteimages/homepage/hp_ad_music.jpg",
					 "images/siteimages/homepage/hp_ad_video.jpg",
					 "images/siteimages/homepage/hp_ad_whats_new.jpg",
					 "images/siteimages/homepage/hp_ad_wifi.jpg")

//adURL = new Array("www.worcpublib.org", "www.worcpublib.org","www.worcpublib.org","www.worcpublib.org",
//				  "www.worcpublib.org","www.worcpublib.org","www.worcpublib.org", "www.worcpublib.org",
//				  "www.worcpublib.org","www.worcpublib.org", "www.worcpublib.org","www.worcpublib.org") 

thisAd = 0 
imgCt = adImages.length 

   
function rotate() { 
  if (document.images) { 
  thisAd++ 
  if (thisAd == imgCt) { 
  thisAd = 0 
  } 
  document.adBanner.src=adImages[thisAd] 
  setTimeout("rotate()" , imgCt *300) 
  } 
   
  } 
  //function newLocation() { 
// document.location.href = "http://www." + adURL[thisAd] 
// } 
//  adImages.push("images/siteimages/homepage/hp_ad_arts.jpg") 
//  adURL.push("www.worcpublib.org") 
