/*
	There are more navigation scripts in the footer.html file
*/

function toggleTriangle(id) {
	var button = document.getElementById(id+'_b');
	var obj = document.getElementById(id);
	
	var cornerR = document.getElementById('botR');
	var cornerL = document.getElementById('botL');
	var bottomSpan = document.getElementById('bottomSpan');
	
	var wrap = document.getElementById('wrap');
	
	if(obj.style.display=="" || obj.style.display == 'none'){
		obj.style.display = 'block';
		obj.colSpan = '2';
		button.className = 'triangleD';
		
		cornerR.style.top = wrap.clientHeight-40+'px';
		cornerL.style.top = wrap.clientHeight-40+'px';
		bottomSpan.style.top = wrap.clientHeight-40+'px';
		
		return;
	}
	
	button.className = 'triangle';
	obj.style.display = 'none';
	
	cornerR.style.top = wrap.clientHeight-40+'px';
	cornerL.style.top = wrap.clientHeight-40+'px';
	bottomSpan.style.top = wrap.clientHeight-40+'px';
	
	return;	
}


function toggle(id){
	var obj = document.getElementById(id);
	if(obj.style.display=="" || obj.style.display == 'none'){
		obj.style.display = 'block';
		return;
	}
	
	obj.style.display = 'none';
	return;	
}

/*slider functions*/
var int = setInterval("",1000);
function startSlide(direction){
	clearInterval(int);
	clearInterval(autoSlide);
	int = setInterval("slide("+direction+")",10);
}

function startAutoSlide(){
	var surface = document.getElementById("surface");
	var pos = surface.offsetLeft;
	var width = surface.clientWidth;
	
	if(Math.abs(pos)<(width-surface.parentNode.clientWidth)/2){
		direction = -1;
	}else if(Math.abs(pos)>(width-surface.parentNode.clientWidth)/2){
		direction = 1;
	}
	
	autoSlide = setInterval("slide("+direction+",1)",50);
}

function stopSlide(direction){
	clearInterval(int);
	setTimeout("slide("+direction+")",20);
	setTimeout("slide("+direction+")",35);
	setTimeout("slide("+direction+")",50);
	setTimeout("slide("+direction+")",70);
	setTimeout("slide("+direction+",2)",95);
	setTimeout("slide("+direction+",2)",120);
	setTimeout("slide("+direction+",2)",150);
	setTimeout("slide("+direction+",2)",180);
	setTimeout("slide("+direction+",1)",250);
	setTimeout("slide("+direction+",1)",300);
	setTimeout("slide("+direction+",1)",350);
	startAutoSlide();
	int = null;
}

function slide(direction,speed){
	if(speed==null){
		speed = 3;
	}
	var surface = document.getElementById("surface");
	var pos = surface.offsetLeft;
	var width = surface.clientWidth;
	
	if(direction==-1){
		if(Math.abs(pos)<(width-surface.parentNode.clientWidth)){
			surface.style.left = pos+(direction*speed)+"px";
		}
	}else{
		if(pos<5){
			surface.style.left = pos+(direction*speed)+"px";
		}
	}
}

function setupSurface() {
	var surface = document.getElementById("surface");
	var width = 0;
	var links = new Array();
	links = surface.getElementsByTagName("a");
	
	for(var x=0;x<links.length;x++){
		width = width+links[x].clientWidth;
	}
	
	//set the width of the surface to the width of the contents
	surface.style.width = width+(links.length*30)+'px';
}


var interval = setInterval("adjust_left_edge()",500);
function adjust_left_edge() {
	var page = document.getElementById('wrap');
	var foot = document.getElementById('footer');
	//document.getElementById('footer').innerHTML = '<p style="text-align: right;">'+document.body.clientWidth+'</p>';
	if(document.body.clientWidth<1000){
		page.style.left = "500px";
		foot.style.left = "500px";
	}else{
		page.style.left = "50%";
		foot.style.left = "50%";
	}
}

function flyout_open(get){
	var flyout = document.getElementById('fly_'+get);
	var menu = document.getElementById('menu_'+get);
	
	if(flyout.style.display == 'none' || flyout.style.display == ""){
		changeOpac(0,'fly_'+get);
		flyout.style.display = 'block';
		flyout.style.left = (menu.parentNode.offsetLeft+24)+'px';
		menu.className = 'hover'; //hover or none
		
		flyout_fade_in(get);
	}
}

function flyout_close(get,a_tag){
	var flyout = document.getElementById('fly_'+get);
	var menu = document.getElementById('menu_'+get);
	flyout.style.display = 'none';
	menu.className = "";

}

function flyout_fade_out(get,a_tag) {
	for(var i=10; i<=100; i=i+10){
		setTimeout("changeOpac("+(93-i)+",'fly_"+get+"')",i*2);
		if(i==100){
			setTimeout("flyout_close('"+get+"','"+a_tag+"')",i*2);
		}
	}
	
}

function flyout_fade_in(get) {
	for(var i=10; i<100; i=i+10){
		setTimeout("changeOpac("+(3+i)+",'fly_"+get+"')",i*2);
	}	
}

//Set the timer for hiding menu
function delayHideMenu(menuID,a_tag) {
	delayhide=setTimeout("flyout_fade_out('"+menuID+"','"+a_tag+"')",100);
}

//Reset the timer for hiding the menu
function clearHideMenu() {
	if (typeof delayhide!="undefined") {
		clearTimeout(delayhide);
	}
}

function changeOpac(opacity, id) { 
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100); 
	object.MozOpacity = (opacity / 100); 
	object.KhtmlOpacity = (opacity / 100); 
	object.filter = "alpha(opacity=" + opacity + ")"; 
}


function imgSwap(){
	var num = Math.floor(Math.random()*14+1);
	var newImg = "/images/swaps/swap" + num + ".jpg";
	document.write("<img src='" + newImg + "' id=imageSwap />");
	}

