//homepage features
//-----------------------------------------------------------------------

//preloads feature images
function preload(){
    if (document.images)
    {
      preload_image_object = new Image();
      // set image url
      image_url = new Array();
      image_url[0] = "images/dynamic/pre-k.jpg";
      image_url[1] = "images/dynamic/pre-k2.jpg";
      image_url[2] = "images/dynamic/pre-k3.jpg";

       var i = 0;
       for(i=0; i<=3; i++) 
         preload_image_object.src = image_url[i];
    }  
}
//algorithm for shuffling an array
function fisherYates ( myArray ) {
  var i = myArray.length;
  if ( i == 0 ) return false;
  while ( --i ) {
     var j = Math.floor( Math.random() * ( i + 1 ) );
     var tempi = myArray[i];
     var tempj = myArray[j];
     myArray[i] = tempj;
     myArray[j] = tempi;
   }
}
function featureSwitch(num){
	
	//declare multi dim array to hold features, add more declarations if adding more features
	feature = new Array();
	feature[0] = new Array();
	feature[1] = new Array();	
	feature[2] = new Array();
	
	//Add content to feature array, [i] for each feature, , add more declarations if adding more features
	feature[0][0] = '<h2><a href = "">Bright from the Start</a></h2>';	
	feature[0][1] = '<p>Long before children learn to read, they are practicing critical pre-reading skills: discovering the world of print, recognition of letters and the sounds of speech, rhyming, word play, and scribble "writing". <a href = "">See our Preschool resources &gt;&gt;</a></p>';	
	feature[0][2] = '<a href = "" class = "featurePhoto" title = ""><img src = "images/dynamic/pre-k2.jpg" alt = "" height = "262" width = "560"/></a>';	
	
	feature[1][0] = '<h2><a href = "">Bright from the Start - XYC</a></h2>';
	feature[1][1] = '<p>This is a test description. <a href = "">See our Preschool resources &gt;&gt;</a></p>';	
	feature[1][2] = '<a href = "" class = "featurePhoto" title = ""><img src = "images/dynamic/pre-k.jpg" alt = "" height = "262" width = "560"/></a>';
	
	feature[2][0] = '<h2><a href = "">Bright from the Start - ABC</a></h2>';
	feature[2][1] = '<p>This is another test description. <a href = "">See our Preschool resources &gt;&gt;</a></p>'; 
	feature[2][2] = '<a href = "" class = "featurePhoto" title = ""><img src = "images/dynamic/pre-k3.jpg" alt = "" height = "262" width = "560"/></a>';

	//grab the elements to we can insert content
	contentL = document.getElementById("features-l");
	contentR = document.getElementById("features-r");

	//99 used for the load condition
	if(num == 99){
		//shuffles array onload
		fisherYates(feature);
		contentL.innerHTML = feature[0][2];
		contentR.innerHTML = feature[0][0] + feature[0][1];
	}else{
		//we are using user clicks to move the feature forward or back
		contentL.innerHTML = feature[num][2];
		contentR.innerHTML = feature[num][0] + feature[num][1];
	}
	
	//grab element for next link
	nextJS = document.getElementById("nextJS");
	
	//what happens when user clicks forward or back, add more cases if adding more features
	switch(num){
		case 1:
			nextJS.onclick = function () { featureSwitch(2)};
			nextJS.style.display = "inline";
		break;
		case 2:
			nextJS.style.display = "none";
		break;
		default:
			nextJS.onclick = function () { featureSwitch(1)};
		break;
	}
	
		
	//reset circle color to grey
	document.getElementById("zero").style.color = "#666666";
	document.getElementById("one").style.color = "#666666";
	document.getElementById("two").style.color = "#666666";
	
	//set the circle color for the current selection, add more cases if adding more features
	switch(num){
		case 99: 
			document.getElementById("zero").style.color = "#DA7D37";
		break;
		case 0: 
			document.getElementById("zero").style.color = "#DA7D37";
		break;
		case 1: 
			document.getElementById("one").style.color = "#DA7D37";
		break;
		case 2: 
			document.getElementById("two").style.color = "#DA7D37";
		break;
	}
}


//article tools 
//-----------------------------------------------------------------------
function emailArt(){
	
}
function shareArt(){
	
}


//menu
//-----------------------------------------------------------------------
function highlightPro(){
	if (!document.all){
		node2 = document.getElementById("nav");	
 
		node2.onmouseover=function() {
			document.getElementById("bg").style.backgroundImage = "url("+uriPath+")";
			document.getElementById("bg").style.color = "white";	
		}
		node2.onmouseout=function() {
			document.getElementById("bg").style.backgroundImage = "none";
			document.getElementById("bg").style.color = "#333333";
	   }
	}
}
function reset2(){
	if (!document.all){
		node = document.getElementById("pro");
		node.onmouseover=function() {
			document.getElementById("bg").style.backgroundImage = "url("+uriPath+")";
			document.getElementById("bg").style.color = "white";
		}	
		node.onmouseout=function() {
			document.getElementById("bg").style.backgroundImage = "none";
			document.getElementById("bg").style.color = "#333333";		
		}
	}
}	
startList = function() {

if (document.all&&document.getElementById) {
	navRoot = document.getElementById("mNav");
	for (i=0; i<navRoot.childNodes.length; i++) {
		node = navRoot.childNodes[i];
		if (node.nodeName=="LI" && node.id == "pro") {
			node.onmouseover=function() {
			document.getElementById("bg").style.backgroundImage = "url("+uriPath+")";
				document.getElementById("bg").style.color = "white";
				this.className+=" over";
				
  			}
  			node.onmouseout=function() {
	 			this.className=this.className.replace(" over", "");
				document.getElementById("bg").style.backgroundImage = "none";
				document.getElementById("bg").style.color = "#333333";
 
   			}
   		}
  	}
 }

}
preload();

//session cookies
function createCookie(name, value, days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0; i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}


//rotating images - placed at the top to run before images are encountered
//-----------------------------------------------------------------------

function rotateImage(){
	var img = [];

	img[0] = "/themes/rr_new/images/dynamic/rotating/DavidCarter_RR.jpg";
	img[1] = "/themes/rr_new/images/dynamic/rotating/MarcBrown_RR.jpg";
	img[2] = "/themes/rr_new/images/dynamic/rotating/Meddaugh_RR.jpg";
	img[3] = "/themes/rr_new/images/dynamic/rotating/Reinhart_Sabuda_RR.jpg";
	img[4] = "/themes/rr_new/images/dynamic/rotating/Sabuda_RR.jpg";
	img[5] = "/themes/rr_new/images/dynamic/rotating/Sciezska_RR.jpg";
	img[6] = "/themes/rr_new/images/dynamic/rotating/Shannon_RR.jpg";
	img[7] = "/themes/rr_new/images/dynamic/rotating/Viorst_RR.jpg";

	//generate random #
	var i=Math.floor(Math.random()*8)
	var imgPath = img[i];
	document.write("<img id = 'rotateHead' src='"+imgPath+"' height = '210' width = '560' alt = ''/>");
}


function rotateImage2(){
	var img = [];

	img[0] = "/themes/rr_new/images/dynamic/rotating/bardofavon.jpg";
	img[1] = "/themes/rr_new/images/dynamic/rotating/bigmamas.jpg";
	img[2] = "/themes/rr_new/images/dynamic/rotating/pecosbill.jpg";
	img[3] = "/themes/rr_new/images/dynamic/rotating/whenthewindstops.jpg";

	//generate random #
	var i=Math.floor(Math.random()*4)
	var imgPath = img[i];
	document.write("<img id = 'rotateHead' src='"+imgPath+"' height = '210' width = '560' alt = ''/>");
}

function rotateImage3(){
	var img = [];

	img[0] = "/themes/rr_new/images/dynamic/rotating/DavidCarter_RR.jpg";
	img[1] = "/themes/rr_new/images/dynamic/rotating/MarcBrown_RR.jpg";
	img[2] = "/themes/rr_new/images/dynamic/rotating/Meddaugh_RR.jpg";
	img[3] = "/themes/rr_new/images/dynamic/rotating/Reinhart_Sabuda_RR.jpg";
	img[4] = "/themes/rr_new/images/dynamic/rotating/Sabuda_RR.jpg";
	img[5] = "/themes/rr_new/images/dynamic/rotating/Sciezska_RR.jpg";
	img[6] = "/themes/rr_new/images/dynamic/rotating/Shannon_RR.jpg";
	img[7] = "/themes/rr_new/images/dynamic/rotating/Viorst_RR.jpg";
	img[8] = "/themes/rr_new/images/dynamic/rotating/bardofavon.jpg";
	img[9] = "/themes/rr_new/images/dynamic/rotating/bigmamas.jpg";
	img[10] = "/themes/rr_new/images/dynamic/rotating/pecosbill.jpg";
	img[11] = "/themes/rr_new/images/dynamic/rotating/whenthewindstops.jpg";

	//generate random #
	var i=Math.floor(Math.random()*12)
	var imgPath = img[i];
	document.write("<img id = 'rotateHead' src='"+imgPath+"' height = '210' width = '560' alt = ''/>");
}




// Stylesheet Switcher for text sizes / text only
var tsize= '1em';
var mNavSpace= '100px';
function getTextSize() {
	size = readCookie('textSize');
	if (size == 1){
		tsize='1em';
		mNavSpace='100px';
	}else if (size == 2){
		tsize='1.1em';
		mNavSpace='40px';
	}else if (size == 3){
		tsize='1.2em';
		mNavSpace='25px';
	}
	return null;
}

getTextSize();
//document.write('\n<style type="text/css">\nbody{font-size:'+tsize+';}\n #main li.tSizes{padding:2px 0px 0px '+mNavSpace+';}\n</style>\n');