var slideShowSpeed = 10000
//var crossFadeDuration = 3
var crossFadeDuration = 4

var pic0 = new Array("./images/fc-2011.jpg");
var pic2 = new Array("./images/wm-2011.jpg");
var pic3 = new Array("./images/fowler-excellence-award.jpg");
var pic4 = new Array("./images/jai-award.jpg");


var Pic = new Array(pic0,pic3,pic4,pic2)

var text0 = new Array("<h4>Fashion Camp 2011</h4><p>Texas Tech University hosts Fashion camp every summer.</p><p><a href='./fashion_camp/' class='learn-more'>More News</a></p>");
var text1 = new Array("<h4>Dr. Deborah Fowler received the President's Excellence in Teaching Award in 2011</h4><p>She also won the Spencer Wells Excellence in Teaching Award in 2010 and was name a Member of the Texas Tech Teaching Academy in 2010.</p>");
var text2 = new Array("<h4>2011 Outstanding Dissertation Award</h4><p>Dr. Tun Min (Catherine) Jai received the 2011 Outstanding Dissertation Award of the International Textile and Apparel Association.</p>");
var text3 = new Array("<h4>Students Visit: Modular Development &amp; Store Layout</h4><p>Graduate retail management students have completed macro space projects for the past three years for Walmart.  The projects were hardware and paint (2009), cosmetics (2010), and deli (2011).  The students begin the project early may and present at the home office in Bentonville in August. In addition to the presentation, students interview for corporate-level positions, attend seminars, and tour facilities.</p>");

var Captions = new Array(text0,text1,text2);

var t
var j = 0
var p = Pic.length

var preLoad = new Array()
for (i = 0; i < p; i++){
   preLoad[i] = new Image()
   preLoad[i].src = Pic[i]
}

function runSlideShow(){
	//Code to check if the user is on a Mac running IE
	//If so then just get a single random image
	if (navigator.platform.indexOf('Mac')>=0 && navigator.appVersion.indexOf('MSIE') >= 0)
	{
		var RandomNumber = Math.round(Math.random() * Pic.length);
		document.images.SlideShow.src = preLoad[RandomNumber].src;
		document.getElementById("fader").innerHTML = Captions[RandomNumber];
		return(0);
	}
   fadeText();
   if (document.all){
      document.images.SlideShow.style.filter="blendTrans(duration=2)"
      document.images.SlideShow.style.filter="blendTrans(duration=crossFadeDuration)"
      document.images.SlideShow.filters.blendTrans.Apply()      
   }
   document.images.SlideShow.src = preLoad[j].src
   if (document.all){
      document.images.SlideShow.filters.blendTrans.Play()
   }
   j = j + 1
   if (j > (p-1)) j=0
}


//  captions:
//  Your messages wich may contain regular html tags
//  Use only single quotes [ ' ] in your html. If you need 
//  a double quote in the message itself use an escape 
//  sign like this: [ \" ]  (not including the brackets)

var bgcolor = "#ffffff"; // background color, must be valid browser hex color (not color names)
var fcolor = "#000000";  // foreground or font color
var steps = 20; // number of steps to fade

// Do Not Edit Below This Line
var colors = new Array(steps);
getFadeColors(bgcolor,fcolor,colors);
var color = 0;
var text = 0;
var step = 1;

// fade: magic fader function
function fadeText() {
	var text_out = "<font color='" + colors[color] + "'>" + Captions[text] + "</font>";

	// actually write message to document
//	if (document.all) fader.innerHTML = text_out; // document.all = IE only
//	if (document.layers) { document.fader.document.write(text_out); document.fader.document.close(); } // document.layers = Netscape only
	document.getElementById("fader").innerHTML = text_out;

// select next fader color
	color += step; 

	// completely faded in?
	if (color >= colors.length-1) {
		step = -1; // traverse colors array backward to fade out
	}

	// completely faded out?
	if (color == 0) {
		step = 1; // traverse colors array forward to fade in again
	
		// select next message
		text += 1;
		if (text == Captions.length) text = 0; // loop back to first message
	}

	if (color == colors.length-2 && step == -1) {
		return;
	} else {
		setTimeout("fadeText()", 10);
	}
}

// getFadeColors: fills Colors (predefined Array)
// with color hex strings fading from ColorA to ColorB

// note: Colors.length equals the number of steps to fade
function getFadeColors(ColorA, ColorB, Colors) {
	len = Colors.length; 
	
	// strip '#' signs if present 
	if (ColorA.charAt(0)=='#') ColorA = ColorA.substring(1);
	if (ColorB.charAt(0)=='#') ColorB = ColorB.substring(1);
	
	// substract rgb compents from hex string 
	var r = HexToInt(ColorA.substring(0,2));
	var g = HexToInt(ColorA.substring(2,4));
	var b = HexToInt(ColorA.substring(4,6));
	var r2 = HexToInt(ColorB.substring(0,2));
	var g2 = HexToInt(ColorB.substring(2,4));
	var b2 = HexToInt(ColorB.substring(4,6));
	
	// calculate size of step for each color component
	var rStep = Math.round((r2 - r) / len);
	var gStep = Math.round((g2 - g) / len);
	var bStep = Math.round((b2 - b) / len);
	
	// fill Colors array with fader colors
	for (i = 0; i < len-1; i++) {
		Colors[i] = "#" + IntToHex(r) + IntToHex(g) + IntToHex(b);
		r += rStep;
		g += gStep;
		b += bStep;
	}
	Colors[len-1] = ColorB; // make sure we finish exactly at ColorB
}

// IntToHex: converts integers between 0-255 into a two digit hex string.
function IntToHex(n) {
	var result = n.toString(16);
	if (result.length==1) result = "0"+result;
	return result;
}

// HexToInt: converts two digit hex strings into integer.
function HexToInt(hex) {
	return parseInt(hex, 16);
}
setInterval(runSlideShow, slideShowSpeed);
