// JavaScript Document

var images = new Array("contentA", "contentB", "contentC", "contentD", "contentE", "contentF", "contentG", "contentH", "contentI", "contentJ", "contentK", "contentL", "contentM", "contentN", "contentO");
var tmbs = new Array("tmbA", "tmbB", "tmbC", "tmbD", "tmbE", "tmbF", "tmbG", "tmbH", "tmbI", "tmbJ", "tmbK", "tmbL", "tmbM", "tmbN", "tmbO");

var tmbImgs = new Array("tmb1", "tmb2", "tmb3", "tmb4", "tmb5", "tmb6", "tmb7", "tmb8", "tmb9", "tmb10", "tmb11", "tmb12", "tmb13", "tmb14", "tmb15");
var tmbSrcBright = new Array("images/thumbs/tmb_A_.jpg", "images/thumbs/tmb_B_.jpg", "images/thumbs/tmb_C_.jpg", "images/thumbs/tmb_D_.jpg", "images/thumbs/tmb_E_.jpg", "images/thumbs/tmb_F_.jpg", "images/thumbs/tmb_G_.jpg", "images/thumbs/tmb_H_.jpg", "images/thumbs/tmb_I_.jpg", "images/thumbs/tmb_J_.jpg", "images/thumbs/tmb_K_.jpg", "images/thumbs/tmb_L_.jpg", "images/thumbs/tmb_M_.jpg", "images/thumbs/tmb_N_.jpg", "images/thumbs/tmb_O_.jpg");
var tmbSrcDull = new Array("images/thumbs/tmb_A.jpg", "images/thumbs/tmb_B.jpg", "images/thumbs/tmb_C.jpg", "images/thumbs/tmb_D.jpg", "images/thumbs/tmb_E.jpg", "images/thumbs/tmb_F.jpg", "images/thumbs/tmb_G.jpg", "images/thumbs/tmb_H.jpg", "images/thumbs/tmb_I.jpg", "images/thumbs/tmb_J.jpg", "images/thumbs/tmb_K.jpg", "images/thumbs/tmb_L.jpg", "images/thumbs/tmb_M.jpg", "images/thumbs/tmb_N.jpg", "images/thumbs/tmb_O.jpg");

var current = 0;

function initiateEMS() {
	//preload images
	MM_preloadImages('images/thumbs/tmb_A_.jpg','images/previous_.jpg','images/next_.jpg','images/about_.jpg','images/thumbs/tmb_D_.jpg','images/thumbs/tmb_B_.jpg','images/thumbs/tmb_C_.jpg','images/thumbs/tmb_E_.jpg','images/thumbs/tmb_F_.jpg','images/thumbs/tmb_G_.jpg','images/thumbs/tmb_H_.jpg','images/thumbs/tmb_I_.jpg','images/thumbs/tmb_J_.jpg','images/thumbs/tmb_K_.jpg','images/thumbs/tmb_L_.jpg','images/thumbs/tmb_M_.jpg','images/thumbs/tmb_N_.jpg','images/thumbs/tmb_O_.jpg');
	
	var start = Math.floor(Math.random()*15);
	var startDiv = document.getElementById(images[start]);
	
	//fade the first image in
	MM_effectAppearFade(startDiv, 2000, 0, 100, false); 
	
	//add underline to the selected thumbnail
	addLine(start);
	
	//set the currently selected image
	current = start;
}

function transition(next) {
	if(current != next && current != 15) {
	
		var currentDiv = document.getElementById(images[current]);
		var nextDiv = document.getElementById(images[next]);
		
		//take underline off current thumbnail
		removeLine(current);
		
		//put underline on new thumbnail
		addLine(next);
		
		//fade out the current image
		MM_effectAppearFade(currentDiv, 2000, 100, 0, false); 
		
		//fade in the image that has been selected
		MM_effectAppearFade(nextDiv, 2000, 0, 100, false);
		
		//set the currently selected image
		current = next;
	}
	else {
		if(current == 15) {
			//we are currently on the about page
			var currentDiv = document.getElementById("aboutDiv");
			var nextDiv = document.getElementById(images[next]);
			
			//put underline on new thumbnail
			addLine(next);
			
			//fade out the current image
			MM_effectAppearFade(currentDiv, 2000, 100, 0, false); 
			
			//fade in the image that has been selected
			MM_effectAppearFade(nextDiv, 2000, 0, 100, false);
			
			//set the currently selected image
			current = next;
		}
	}
}

function aboutTransition() {
	//transition to the about page
	if(current != 15) {
	
		var currentDiv = document.getElementById(images[current]);
		var nextDiv = document.getElementById("aboutDiv");
		
		//alert();
		
		//take underline off current thumbnail
		removeLine(current);
		
		//fade out the current image
		MM_effectAppearFade(currentDiv, 2000, 100, 0, false); 
		
		//fade in the image that has been selected
		MM_effectAppearFade(nextDiv, 2000, 0, 100, false);
		
		//set the currently selected image
		current = 15;
	}
}

function goPrevious() {
	//when user clicks the previous arrow
	if (current == 0 || current == 15) transition(14);
	else transition(current-1);
}

function goNext() {
	//when user clicks the next arrow
	if (current == 14 || current == 15) transition(0);
	else transition(current+1);
}

function addLine(num) {
	//add the underline underneath the thumbnail
	var i = tmbImgs[num];
	var img = document.getElementById(i);
	img.src = tmbSrcBright[num];
}

function removeLine(num) {
	//remove the underline from the thumbnail
	var i = tmbImgs[num];
	var img = document.getElementById(i);
	img.src = tmbSrcDull[num];
}

function hoverOn(num) {
	if(current!=num) addLine(num);
}

function hoverOff(num) {
	if(current!=num) removeLine(num);
}
