// JavaScript Document

var images = new Array("contentA", "contentB", "contentC", "contentD", "contentE", "contentF", "contentG");
var tmbs = new Array("tmbA", "tmbB", "tmbC", "tmbD", "tmbE", "tmbF", "tmbG");

var tmbImgs = new Array("tmb1", "tmb2", "tmb3", "tmb4", "tmb5", "tmb6", "tmb7");

var current = 0;

function initiateEMS() {
	//preload images
	MM_preloadImages('images/cNext_.gif','images/cPrev_.gif');
	
	// var start = Math.floor(Math.random()*7);
	var startDiv = document.getElementById(images[0]);
	
	//fade the first image in
	MM_effectAppearFade(startDiv, 1000, 0, 100, false);
	
	//add underline to the selected thumbnail
	addLine(0);
	
	//set the currently selected image
	current = 0;
}

function transition(next) {
	//alert(current);
	if(current != next && current != 7) {
	
		var currentDiv = document.getElementById(images[current]);
		var nextDiv = document.getElementById(images[next]);
		
		//highlight off current thumbnail
		removeLine(current);
		
		//highlight on new thumbnail
		addLine(next);
		
		//fade out the current image
		MM_effectAppearFade(currentDiv, 1000, 100, 0, false); 
		
		//fade in the image that has been selected
		MM_effectAppearFade(nextDiv, 1000, 0, 100, false);
		
		//set the currently selected image
		current = next;
	}
	else {
		if(current == 7) {
			//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, 1000, 100, 0, false); 
			
			//fade in the image that has been selected
			MM_effectAppearFade(nextDiv, 1000, 0, 100, false);
			
			//set the currently selected image
			current = next;
		}
	}
}

function aboutTransition() {
	//transition to the about page
	if(current != 7) {
	
		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, 1000, 100, 0, false); 
		
		//fade in the image that has been selected
		MM_effectAppearFade(nextDiv, 1000, 0, 100, false);
		
		//set the currently selected image
		current = 7;
	}
}

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

function goNext() {
	//when user clicks the next arrow
	if (current == 6 || current == 7) 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 = "images/cSel.gif";
}

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

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

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