var SlideShowSpeed = 3000;

var Picture = new Array();
var Link = new Array();
var Caption = new Array();
//var iss = 1;
var iss = (Math.floor(Math.random()*24)) + 1
var tss = 0;


//Set the images
Picture[1] = './images/rotating_images/big_tree_registry.jpg';
Picture[2] = './images/rotating_images/disaster_response.jpg';
Picture[3] = './images/rotating_images/education.jpg';
Picture[4] = './images/rotating_images/eoc.jpg';
Picture[5] = './images/rotating_images/fia.jpg';
Picture[6] = './images/rotating_images/forest_legacy.jpg';
Picture[7] = './images/rotating_images/health_and_disease.jpg';
Picture[8] = './images/rotating_images/nursery.jpg';
Picture[9] = './images/rotating_images/plt.jpg';
Picture[10] = './images/rotating_images/sustainable.jpg';
Picture[11] = './images/rotating_images/training.jpg';
Picture[12] = './images/rotating_images/tree_improvement.jpg';
Picture[13] = './images/rotating_images/tree_planting.jpg';
Picture[14] = './images/rotating_images/wildland_fire.jpg';
Picture[15] = './images/rotating_images/wildlife_protection.jpg';
Picture[16] = './images/rotating_images/wood_technology.jpg';
Picture[17] = './images/rotating_images/wildland_emerg_resp.jpg';
Picture[18] = './images/rotating_images/conservation_ed.jpg';
Picture[19] = './images/rotating_images/did-you-know.jpg';
Picture[20] = './images/rotating_images/fire_dept.jpg';
Picture[21] = './images/rotating_images/flmplanning.jpg';
Picture[22] = './images/rotating_images/landowner.jpg';
Picture[23] = './images/rotating_images/tfs_news.jpg';
Picture[24] = './images/rotating_images/bmp_waterquality.jpg';


var pss = Picture.length-1;
//Set the captions
Link[1] = "./article.aspx?id=1336"
Link[2] = "./article.aspx?id=1537"
Link[3] = "./article.aspx?id=172"
Link[4] = "./article.aspx?id=1720"
Link[5] = "./article.aspx?id=109"
Link[6] = "./article.aspx?id=115"
Link[7] = "./article.aspx?id=1168"
Link[8] = "./article.aspx?id=1165"
Link[9] = "http://plttexas.tamu.edu"
Link[10] = "./default.aspx?dept=sustain"
Link[11] = "https://tiwa.tamu.edu"
Link[12] = "./article.aspx?id=1686"
Link[13] = "http://texastreeplanting.tamu.edu"
Link[14] = "./default.aspx?dept=frp"
Link[15] = "./article.aspx?id=1180"
Link[16] = "./article.aspx?id=151"
Link[17] = "./article.aspx?id=1542"
Link[18] = "./article.aspx?id=1967"
Link[19] = "./article.aspx?id=1657"
Link[20] = "./article.aspx?id=1536"
Link[21] = "./article.aspx?id=2012"
Link[22] = "./default.aspx?dept=landowner"
Link[23] = "./default.aspx?dept=news&news_coll=eNews&id=3748"
Link[24] = "./article.aspx?id=71"



function runSlideShow() {
	if (document.images.PictureBox){
	document.images.PictureBox.src = Picture[iss]; }
	if (document.all){
	document.getElementById("PictureBoxLink").href = Link[iss];
	document.images.PictureBox.style.filter="blendTrans(duration=2)";
	document.images.PictureBox.filters.blendTrans.Apply();}
	if (document.all) document.images.PictureBox.filters.blendTrans.Play();
	iss = iss + 1;	
	SlideShowSpeed = 5000;
	if (iss > pss) {iss=1;}
	tss=setTimeout('runSlideShow()', SlideShowSpeed);
}

function stopslideshow() {
	if (tss) {
		tss = clearTimeout(tss);
	}
}

function unpauseslideshow() {
	tss=setTimeout('runSlideShow()', SlideShowSpeed);
}

function nextslide() {
	stopslideshow();
	document.images.PictureBox.src = Picture[iss];
	iss = iss + 1;
	if (iss > pss) {iss=1;}
	tss=setTimeout('runSlideShow()', SlideShowSpeed);
}

function previousslide() {
	stopslideshow();
	if (iss == 2 ) { iss = pss; }
	else if(iss == 1) { iss = pss-1; }
	else { iss = iss - 2;} 
	document.images.PictureBox.src = Picture[iss];
	iss = iss + 1;
	if (iss > pss) {iss=1;}
	tss=setTimeout('runSlideShow()', SlideShowSpeed);
}

function getURLParam(strParamName){
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if (aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return unescape(strReturn);
} 


window.onload = function(e) {
	if (getURLParam("dept") == ""){
		runSlideShow();	
	}
}