// JavaScript Source for slide show with messages

// Declare Vector of File Names of Pictures in show
var imageFiles = new Array();

imageFiles[0]="slideshow/slideshow12.jpg";
imageFiles[1]="slideshow/slideshow13.jpg";
imageFiles[2]="slideshow/slideshow6.jpg";
imageFiles[3]="slideshow/slideshow8.jpg";
imageFiles[4]="slideshow/slideshow4.jpg";
imageFiles[5]="slideshow/slideshow1.jpg";
imageFiles[6]="slideshow/slideshow9.jpg";
imageFiles[7]="slideshow/slideshow10.jpg";
imageFiles[8]="slideshow/slideshow11.jpg";
imageFiles[9]="slideshow/slideshow5.jpg";
imageFiles[10]="slideshow/slideshow7.jpg";
imageFiles[11]="slideshow/slideshow2.jpg";
imageFiles[12]="slideshow/slideshow3.jpg";
imageFiles[13]="slideshow/massachusetts.jpg";
imageFiles[14]="slideshow/starburst.jpg"

function randOrd(){
return (Math.round(Math.random())-0.5); }

//imageFiles.sort( randOrd );

// Declare global variables
var slideshow_pic1;
var slideshow_pic2;
var index=0;
var flip=0;
var fadeDelay=500;

var preImages = new Array();

var hoverMessages = new Array();
var hoverLinks = new Array();
var slide_counter=0;
var slide_frequency=1;
var messageIndex=0;
var doneFlag=0;
var reallyDoneFlag=0;


function slideshow(images,show_width,show_height,delay,fadelength) {
  fadeDelay = fadelength
  var img1 = '<img src="'+images[0]+'" id="slideshow_pic1" width="'+show_width+'" height="'+show_height+'" style="position:absolute; left:0; top:0; opacity:0;filter:alpha(opacity=0)">';
  var img2 = '<img src="'+images[0]+'" id="slideshow_pic2" width="'+show_width+'" height="'+show_height+'" style="position:absolute; left:0; top:0; opacity:0;filter:alpha(opacity=0)">';
  var txt1 = document.createTextNode(img1);
  var txt2 = document.createTextNode(img2);
  var slide_id = document.getElementById("slideshow");
  slide_id.innerHTML = img1+img2; 
  slideshow_pic1 = document.getElementById("slideshow_pic1");	 
  slideshow_pic2 = document.getElementById("slideshow_pic2");
  
  // Preload Images
  for (ii=0; ii<imageFiles.length;ii++)
  {
    preImages[ii] = new Image(show_width,show_height);
    preImages[ii].src = imageFiles[ii];
  }
  
  // When the first image has loaded, Fade in the first picture
  preImages[0].onLoad=start(delay);
  
  function start(delay) {
    fadeIn(1500);
    // Rotate pictures with given delay
    setInterval("rotateImage()",delay);
  }
}

function rotateImage() {
///!!!!!!!!!!!
  //setTimeout('slide(40,0.5,-270,-900,0.5,1,470,-280,-270)',10);
  //slide(40,0.5,-270,-900,0.5,1,470,-280,-270)
  
  if (doneFlag == 0) {
    slide(40,0.5,-60,-975,0.3,0.5,475,-60,-50);
  }
  //else if (reallyDoneFlag == 0) {
  //  slideIn(40,0.5,1,-50,-975,-975);
    //reallyDoneFlag=1;
  //}
  
  if (flip==0)
  {
    //Set the invisible picture to the next picture
    index = (index+1)%imageFiles.length;
    slideshow_pic2.src=preImages[index].src;
    flip = 1;	
    fade1to2(fadeDelay);
  }
  else
  {
    index = (index+1)%imageFiles.length;
    slideshow_pic1.src=preImages[index].src;
    flip = 0;
    fade2to1(fadeDelay);		
  }  
}

function fade1to2(durr) {
  var speed = Math.round(durr/20);
  var temp;
  for (ii=1; ii<40; ii++)
  {
    var bb = ii*100/40;
    temp = 100-(ii+1)*100/40;
    setTimeout("changeOpac("+temp+","+bb+")",speed*ii);
  }
}

function fade2to1(durr) {
  var speed = Math.round(durr/20);
  var temp;
  for (ii=1; ii<40; ii++)
  {
    var bb = ii*100/40;
    temp = 100-(ii+1)*100/40;
    setTimeout("changeOpac("+bb+","+temp+")",speed*ii);
  }
}

function fadeIn(durr) {
//!!!!!!!!!!
  //setTimeout('slideIn(40,0.4,0.4,475,-65,-75)',1000);
  setTimeout('slideIn(40,0.3,.75,475,-60,-50)',1000);
  var speed = Math.round(durr/20);
  var temp;
  for (ii=1; ii<20; ii++)
  {
    var bb = ii*100/20;
    setTimeout("changeOpac("+bb+",0)",speed*ii);
  }
}


//change the opacity for different browsers 
function changeOpac(opac1,opac2) { 
  slideshow_pic1.style.opacity=opac1/100;
  slideshow_pic1.style.filter="alpha(opacity="+opac1+")"; 
  slideshow_pic2.style.opacity=opac2/100;
  slideshow_pic2.style.filter="alpha(opacity="+opac2+")"; 
}   
  


//------------------------
// Hover Code
//------------------------

function delaySlide() {
  setTimeout('slide(40,0.5,.75,470,-85,-75)',1000);
}

var lock=0;

function unlock() {
  lock=0;
}


function slideIn(fps,t1,t2,x0,x1,x2) {
  var hover = document.getElementById("hover");
/*
  var fps=50;
  var t1=.5;
  var t2=1;
  var x0=470;
  var x1=-85;
  var x2=-75;
*/
  var n1=Math.round(fps*t1);
  var n2=Math.round(fps*t2);
  lock=1;
  setTimeout("unlock()",1000*(t1+t2));

  initialMessage()

// First Slope
  for (var ii=0; ii<n1; ii++) {
    var pos = x0 + (x1-x0)*ii/n1;
	var pos_str = pos.toString()+"px";
	setTimeout('setpos('+pos+',40)',t1*1000*ii/n1);
  }

// Second Slope
  for (var ii=0; ii<n2; ii++) {
    var temp = ii*60/n2;
    var trans = 40+Math.round(temp);
    var pos = x1 + (x2-x1)*ii/n2;
	var pos_str = pos.toString()+"px";
	setTimeout('setpos('+pos+','+trans+')',t1*1000+t2*1000*ii/n2);
  }
}


function slide(fps,to1,xo1,xo2,ti1,ti2,xi0,xi1,xi2) {

  slide_counter = (slide_counter+1)%slide_frequency;
  if (slide_counter == 0 && slide_frequency > 0) {
  var hover = document.getElementById("hover");
 

  var no1=Math.round(fps*to1);
  var ni1=Math.round(fps*ti1);
  var ni2=Math.round(fps*ti2);
  lock=1;
  setTimeout("unlock()",1000*(to1+ti1+ti2));

 //Exit Slope
  for (var ii=0; ii<no1; ii++) {
    var trans = 100-ii*50/no1;
    var pos = xo1 + (xo2-xo1)*ii/no1;
	var pos_str = pos.toString()+"px";
	setTimeout('setpos('+pos+','+trans+')',to1*1000*ii/no1);
  }

  setTimeout('changeMessage()',to1*1000);
  //changeMessage(hoverMessages[messageIndex])
// First Entrence Slope
  for (var ii=0; ii<ni1; ii++) {
    var pos = xi0 + (xi1-xi0)*ii/ni1;
	var pos_str = pos.toString()+"px";
	setTimeout('setpos('+pos+',40)',to1*1000+ti1*1000*ii/ni1);
  }

// Second Entrence Slope
  for (var ii=0; ii<ni2; ii++) {
    var temp = ii*60/ni2;
    var trans = 40+Math.round(temp);
    var pos = xi1 + (xi2-xi1)*ii/ni2;
	var pos_str = pos.toString()+"px";
	setTimeout('setpos('+pos+','+trans+')',to1*1000+ti1*1000+ti2*1000*ii/ni2);
  }
  }

}

function initialMessage() {
  // Set next message index
  messageIndex = 0;
  // Set the Message 
  var hover_text = document.getElementById("hover_text");
  hover_text.innerHTML = hoverMessages[messageIndex];
  var hover_cover = document.getElementById("hover_cover");
  hover_cover.style.cursor="pointer";
  if (hoverLinks[messageIndex]=="") {
    hover_cover.style.cursor="default";
  }
}

function changeMessage() {
  // Set next message index
  //if ((messageIndex+1)==hoverMessages.length)
  //  doneFlag = 1;
    
  messageIndex = (messageIndex+1)%hoverMessages.length;
  var hover_cover = document.getElementById("hover_cover");
  hover_cover.style.cursor="pointer";
  if (hoverLinks[messageIndex]=="") {
    hover_cover.style.cursor="default";
  }
  
  // Set the Message 
  var hover_text = document.getElementById("hover_text");
  hover_text.innerHTML = hoverMessages[messageIndex];
}

function  link() {
if (hoverLinks[messageIndex] != "") {
//  document.location.href=hoverLinks[messageIndex];
  newwindow=window.open(hoverLinks[messageIndex]);
  if (window.focus) {newwindow.focus()}
}
}

function setpos(pos_in,trans) {
  var pos_in_str = pos_in.toString();
  pos_in_str = pos_in_str +"px";
  var hover_l = document.getElementById("hover");
  hover_l.style.left=pos_in_str;
  
  var temp=trans/100;
  var alpha = Math.round(temp*85);
  var opac=alpha/100;  
  var hover_back_middle = document.getElementById("hover_back_middle");
  hover_back_middle.style.opacity=opac;
  hover_back_middle.style.filter="alpha(opacity="+alpha+")";

  alpha = Math.round(temp*50);
  opac=alpha/100;    
  var hover_back_upper = document.getElementById("hover_back_upper");
  hover_back_upper.style.opacity=opac;
  hover_back_upper.style.filter="alpha(opacity="+alpha+")";
  var hover_back_lower = document.getElementById("hover_back_lower");
  hover_back_lower.style.opacity=opac;
  hover_back_lower.style.filter="alpha(opacity="+alpha+")";
  
  alpha = Math.round(temp*100);
  opac=alpha/100;    
  var hover_text = document.getElementById("hover_text");
  hover_text.style.opacity=opac;
  hover_text.style.filter="alpha(opacity="+alpha+")";
  
}

function fadeout(steps,durr) {
  for (var ii=0; ii<steps; ii++) {
    var trans = 100-ii*100/steps;
    setTimeout('setpos(-75,'+trans+')',ii*durr*1000/steps);
  }
}

function fadeElement(ident,trans_in,trans_out,steps,durration) {
//   setTimeout("chageOpac_hover(\"hover_back_middle\","+trans_in+")",300);
  if (lock == 0) {
    for (var ii=0; ii<steps; ii++) {
      var trans = trans_in + Math.round((trans_out-trans_in)*ii/steps);
	  setTimeout("chageOpac_hover(\""+ident+"\","+trans+")",durration*ii/steps);
    }   
  }
}

function chageOpac_hover(ident,alpha) {
  var opac=alpha/100; 
  var el = document.getElementById(ident);
  el.style.opacity=opac;
  el.style.filter="alpha(opacity="+alpha+")";
}