// JavaScript Document

function previous(){
	if(pageNum == 0){
		//pageNum = navi.length-1;
		//document.getElementById('prevButton').style.display = 'none';
	}else{
		pageNum--;
	}
	location.href = navi[pageNum] + '.php';
}


function next(){
	if(pageNum == (navi.length-1)){
		//pageNum = 0;
		//document.getElementById('nextButton').style.display = 'none';
	}else{
		pageNum++;
	}
	location.href = navi[pageNum] + '.php';
}


function showSuber(id,blanker,color){
	var temp = document.getElementById(id + 'Sub');
	if (temp.style.display != "inline"){
		hideSuber(id);
		temp.style.visibility = "visible";
		temp.style.display = "inline";
	} else {
		temp.style.visibility = "hidden";
		temp.style.display = "none";
	}
	if (blanker != undefined){
		overer(blanker);
	}
	perpetuateTimer();
}

function hideSuber(id){
	var aers = document.getElementsByTagName('div');
	for(i = 0; i < aers.length; i++){
		if((aers[i].id).indexOf('menuOpt') == 0 && (aers[i].id).indexOf('Sub') > 0){
			if(id != aers[i].id){
				aers[i].style.display = 'none';
			}
		}
	}
	aers = document.getElementsByTagName('a');
	for(i = 0; i< aers.length;i++){
		if((aers[i].id).indexOf('menuOpt') == 0){
			if((aers[i].id) != pager && (('menuOpt' + pager.charAt(3)) != aers[i].id)){
				//alert(aers[i].style.color);
				aers[i].style.backgroundColor="";
				aers[i].style.color = "";
			}
		}
	}
	clearTimeout(timer);
}

function perpetuateTimer(){
	//alert('clear');
	clearTimeout(timer);
}

function startKillTimer(){
	//alert('set');
	timer = setTimeout("hideSuber();", 1000);
}

function highlightMe(id,background,text){
	var color = document.getElementById('colorer').value;
	var temp = document.getElementById(id);
	if (temp != undefined) {
		if (background && text){
			temp.style.color = text;
			temp.style.backgroundColor = background;
			alert("custom colored");
		} else if (color == 'orange') {
			temp.style.color = "#F78F1E";
			temp.style.backgroundColor = "#FDDDBB";
		} else if (color == 'green') {
			temp.style.color = "#9DAD17";
			temp.style.backgroundColor = "#DFFFB1";
		} else if (color == 'blue') {
			temp.style.color = "#517283";
			temp.style.backgroundColor = "#CAD5D9";
		} else if (color == 'sage') {
			temp.style.color = "#82A53D";
			temp.style.backgroundColor = "#CAD5AA";
		}
	}
	return;
}

function nonhighlightMe(id,background,text){
	var temp = document.getElementById(id);
	if (background && text){
		temp.style.color = text;
		temp.style.backgroundColor = background;
		alert("custom colored");
	} else {
		temp.style.color = "white";
		temp.style.backgroundColor = "";
	}
	return;
}

function overer(id){
	var color = document.getElementById('colorer').value;
	var menu = document.getElementById('menuOpt' + id.charAt(3));
	var menuOption = document.getElementById(id);
	if(color=='orange'){
		menu.style.backgroundColor="#fdddbb";
		menu.style.color="#f78f1e";
		menuOption.style.backgroundColor="#fdddbb";
		menuOption.style.color="#f78f1e";
	}else if(color=='green'){
		menu.style.color="#9DAD17";
		menuOption.style.backgroundColor="#DFFFB1";
		menu.style.backgroundColor="#DFFFB1";
		menuOption.style.color="#9DAD17";
	}else if(color=='blue'){
		menuOption.style.backgroundColor="#CAD5D9";
		menu.style.color="#517283";
		menu.style.backgroundColor="#CAD5D9";
		menuOption.style.color="#517283";
	}else if(color=='sage'){
		menu.style.color="#82A53d";
		menuOption.style.backgroundColor="#CAD5AA";
		menu.style.backgroundColor="#CAD5AA";
		menuOption.style.color="#82A53D";
	}
}

function offerer(id){
	var color = document.getElementById('colorer').value;
	var menu = document.getElementById('menuOpt' + id.charAt(3));
	var menuOption = document.getElementById(id);
	if(id != pager && (('menuOpt' + pager.charAt(3)) != id)){
		if(color=='orange'){
			menuOption.style.backgroundColor="white";
			menuOption.style.color="#f78f1e";
		}else if(color=='green'){
			menuOption.style.backgroundColor="white";
			menuOption.style.color="#9DAD17";
		}else if(color=='blue'){
			menuOption.style.backgroundColor="white";
			menuOption.style.color="#517283";
		}else if(color=='sage'){
			menuOption.style.backgroundColor="white";
			menuOption.style.color="#82A53D";
		}
	}
}

function changeHeaderPlease(){
	var color = document.getElementById('colorer').value;
	var topper = document.getElementById('company_top');
	var selector = document.getElementById(pager);
	//alert(pager + ' ' + pager.charAt('3'));
	var temper = document.getElementById('menuOpt' + pager.charAt(3));
	//alert(pager);
		if(pageNum == 0){
			document.getElementById('prevButton').style.visibility = 'hidden';
			document.getElementById('barer').style.visibility = 'hidden';
		}else if(pageNum == (navi.length-1)){
			document.getElementById('nextButton').style.visibility = 'hidden';
			document.getElementById('barer').style.visibility = 'hidden';
		}
	if(color=='orange'){
		topper.className = "top_orange";
		selector.style.color = "#000000";
		selector.style.backgroundColor = "#FDDDBB";
		if(temper != undefined){
			temper.style.color = "#F78F1E";
			temper.style.backgroundColor = "#FDDDBB";
		}
	}else if(color=='blue'){
		topper.className="top_blue";
		selector.style.color = "#517283";
		selector.style.backgroundColor = "#CAD5D9";
		if(temper != undefined){
			temper.style.color = "#517283";
			temper.style.backgroundColor = "#CAD5D9";
		}
	}else if(color=='green'){
		topper.className="top_green";
		selector.style.color = "#9DAD17";
		selector.style.backgroundColor = "#DFE3B1";
		if(temper != undefined){
			temper.style.color = "#9DAD17";
			temper.style.backgroundColor = "#DFE3B1";
		}
	}else if(color=='sage'){
		topper.className="top_sage";
		selector.style.color = "#82a53d";
		selector.style.backgroundColor = "#CAD5AA";
		if(temper != undefined){
			temper.style.color = "#82a53d";
			temper.style.backgroundColor = "#CAD5AA";
		}
	}
}

var hex, textNews, textCount, textIndex, divT;
function textStart(){
	hex = 176; // Initial color value.
	//to be taken from the database later if required
	// target='_blank' will open the link in a new page
	//reference the site above for sequences to certain characters like '`' = &#180; and the accent over the e = &#233;
	textNews = ["<strong>LATEST NEWS</strong> | </strong><a href='#' class='divNewsItems' id='newsCon0'></a>",
			"<strong>LATEST NEWS</strong> | </strong><a href='#' class='divNewsItems' id='newsCon1'></a>"]
	textCount = textNews.length;
	textIndex = 0;
	divT = document.getElementById("divNews");
	divT.innerHTML = textNews[0];
}

function fadetext(dir){
	var divN = document.getElementById("newsCon" + textIndex);
	if(dir == 'down'){
	  	if(hex>71) { //If color is not black yet  //51
		hex-=8; // increase color darkness
		divN.style.color="rgb("+hex+","+hex+","+hex+")";
		setTimeout("fadetext('down');",100);
	  }
	  else{
		setTimeout("fadetext('up');", 3000);
	  }
	}else if(dir == 'up'){
	  if(hex<=176) { //If color is not black yet  //212
		hex+=8; // increase color darkness
		divN.style.color="rgb("+hex+","+hex+","+hex+")";
		setTimeout("fadetext('up');", 100);
	  }else{
		if(textIndex == (textCount-1)){
			textIndex = 0;
		}else{
			textIndex = textIndex + 1;
		}
		document.getElementById('divNews').innerHTML = textNews[textIndex];
		setTimeout("fadetext('down');", 500);
	  }
	}else{
		alert('broken');
		hex=212; //212
	}

}
