//*****************************
// SHOW/HIDE the Sub Navigation
//*****************************
Menu = {timer : null, current : null};
Menu.getStyle = function(name){
	if(document.getElementById) return document.getElementById(name).style;
	else if(document.all) return document.all[name].style;
	else if(document.layers) return document.layers[name];
}
Menu.show = function(name){
	if(this.timer) clearTimeout(this.timer);
	this.getStyle(name).display = "inline";
	this.current = name;
	this.main_change();
	
	return false;
}
Menu.hide = function(){
	this.timer = setTimeout("Menu.doHide()",1750);
}
Menu.doHide = function(){
	if(this.current){
		if(this.timer) clearTimeout(this.timer);
		this.getStyle(this.current).display = "none";
		this.main_changeback(this.current.substring(0,this.current.length-2)+'mn');
		this.current = null;
	}
	
	return false;
}
Menu.main_change =function(){
	var test = this.current.substring(0,this.current.length-2)+'mn';
	document.getElementById(test).className = test+'_ov';
	
	return false;
}
Menu.main_changeback =function(name){
	document.getElementById(name).className = name;
	
	return false;
}

//*****************************
// SHOW/HIDE the popDiv
//*****************************
popDiv = {timer : null, current : null, popupDiv : null, ShowDiv : null, href : null, picTimer : null, rememberPicDisplay : false};
popDiv.getStyle = function(name){
	popupDiv =  document.getElementById('popDivShadow');
	ShowDiv = document.getElementById(name);
	href = document.getElementById('popDivInfo');
}
popDiv.show = function(name){
	if(picDisplay.play == true){picDisplay.pausePlay(); this.rememberPicDisplay = true;}//pause picture randomizer so pic matches description
	if(name == null || name == ''){ name=this.current;}
	if(this.timer) clearTimeout(this.timer);
	popDiv.getStyle(name);
	popupDiv.style.display = "block";
	ShowDiv.style.display = "block";
	this.current = name;

	//DETERMINE POSITION	
	var posX = 0; //var posX = href.offsetLeft;
	var posY = 0; //var posY = href.offsetTop;
	while(href.offsetParent){
		if(href==document.getElementsByTagName('body')[0]){break}
		else{
			posX=posX+href.offsetParent.offsetLeft;
			posY=posY+href.offsetParent.offsetTop;
			href=href.offsetParent;

		}
	}
	var leftOffset = (posX+5);
	var topOffset = (posY-4);

	if ((leftOffset + popupDiv.offsetWidth)  > document.body.scrollWidth){
		leftOffset = leftOffset - popupDiv.offsetWidth +163;
	}
	//LEFT
	popupDiv.style.marginLeft = leftOffset + 'px';
	
	//TOP	
	popupDiv.style.marginTop = topOffset +12+ 'px';
}
popDiv.hide = function(){
	this.timer = setTimeout("popDiv.doHide()",1750);
}
popDiv.doHide = function(){
	if(this.current){
		if(this.rememberPicDisplay == true){picDisplay.play = true; picDisplay.nextImage(); this.rememberPicDisplay=false;}//restart picture randomizer
		if(this.timer) clearTimeout(this.timer);
		popupDiv.style.display = "none";
		ShowDiv.style.display = "none";
		this.current = null;
	}
}
//*****************************
// PICTURE DISPLAY
//*****************************
picDisplay = {timer1 : null, imageArrary: null, current : null, numPics : null, imagePath : null, oImg : null, play : true};
picDisplay.init = function(){
	this.current=0;
	this.imageArrary = new Array;
	picDisplay.randomize();
	picDisplay.nextImage();
	
	return false;
}
picDisplay.randOrd = function(){
	return (Math.round(Math.random())-0.5);
} 
picDisplay.randomize = function(){
	for(i=0;i<this.numPics;i++){this.imageArrary[i]=i;}
	this.imageArrary.sort(picDisplay.randOrd);
	this.imageArrary.sort(picDisplay.randOrd); //re-sort to magnify randomness
	this.current=0;
	
	return false;
}
picDisplay.preLoadImage = function(){
	this.oImg=new Image;
	this.oImg.onload=function(){picDisplay.Play();}
	this.oImg.onerror=function(){picDisplay.nextImage();} //use default
	this.oImg.src= this.imagePath+ (this.imageArrary[this.current]) +".jpg";//try this image based on groupID
	
	return false;
}
picDisplay.swapImage = function(){
	clearTimeout(this.timer1);
	document.getElementById('imagePic').src = this.oImg.src
	this.oImg=null;

	forgotpass1.toggle();
	this.timer1 = setTimeout("picDisplay.timeDelay();clearTimeout(this.timer1);",2000);
	
	return false;
}

picDisplay.timeDelay = function(){
	clearTimeout(this.timer1);
	if(this.play == true){
		this.timer1 = setTimeout("picDisplay.nextImage()",8000);
	}
	return false;
}
picDisplay.nextImage = function(){
	clearTimeout(this.timer1);
	this.current++;//next
	if(this.current>this.imageArrary.length){this.current=0;}//if at end of list, start over
	picDisplay.preLoadImage();//preLoad

	return false;
}
picDisplay.prevImage = function(){
	clearTimeout(this.timer1);
	this.current--;//next
	if(this.current<0){this.current=this.numPics-1;}//if at end of list, go to end (-1 to accomidate for array starts @ 0not 1
	picDisplay.preLoadImage();//preLoad
	
	return false;
}
picDisplay.Play = function(){
	clearTimeout(this.timer1);
	forgotpass1.toggle();
	this.timer1 = setTimeout("picDisplay.swapImage()",1000);
	
	var temp = document.getElementById('pausePlay');
	if(this.play == true){ //currently playing so pause
		temp.src='/images/imageRotate/btn-pause.png';
	}
	else{ //currently paused so play
		temp.src='/images/imageRotate/btn-play.png';
	}
	
	return false;
}
picDisplay.pausePlay = function(){
	var temp = document.getElementById('pausePlay');
	if(this.play == true){ //currently playing so pause
		this.play = false;
		clearTimeout(this.timer1);
		temp.src='/images/imageRotate/btn-play.png';
	}
	else{ //currently paused so play
		this.play = true;
		clearTimeout(this.timer1);
		temp.src='/images/imageRotate/btn-pause.png';
		picDisplay.nextImage();
	}
	
	return false;
}