//////////////////////MENU SWITCH/////////////////////////////
function SwitchMenu(obj){
	if(document.getElementById){
		var el = document.getElementById(obj);
		var ar = document.getElementById("masterdiv").getElementsByTagName("span"); 
		if(el.style.display != "block"){ 
			for (var i=0; i<ar.length; i++){
				if (ar[i].className=="submenu2") 
					ar[i].style.display = "none";
			}
			el.style.display = "block";
		}else{
			el.style.display = "none";
		}
	}
}
function SwitchMenu2(obj){
	if(document.getElementById){
		var el = document.getElementById(obj);
		var ar = document.getElementById("masterdiv").getElementsByTagName("span"); 
		if(el.style.display != "block"){ 
			for (var i=0; i<ar.length; i++){
				if (ar[i].className=="submenu") 
					ar[i].style.display = "none";
			}
			el.style.display = "block";
		}else{
			el.style.display = "none";
		}
	}
}
//////////////////////IMG FADING SCRIPT//////////////////
var img_on_top="img2";
var has_run_init_funcs=0;
function initial_img_fader_actions(){
	if(has_run_init_funcs==0){
		var sec_div=document.getElementById('img2');
		sec_div.style.position='absolute';
		sec_div.style.top=116; //findPos(document.getElementById('img1'),'y');
		sec_div.style.left=0; //findPos(document.getElementById('img1'),'x');
		opacity('img2', 100, 0, 10, 'img2');
		has_run_init_funcs=1;
	}
}

function opacity(id, opacStart, opacEnd, millisec, prev_id) {
	//millisec=millisec+2000;
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

	var cur_pic=document.getElementById(id);
	var last_pic=document.getElementById(prev_id);

	cur_pic.style.zIndex=101;
	last_pic.style.zIndex=100;
	//alert(last_pic);

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
    setTimeout("changeOpac(0,'" + prev_id + "')", millisec);
}

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 findPos(obj,coord) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
		if(coord=="x"){
			return [curleft];
		}else{
			return [curtop];
		}
	}
}

function fade_img(image_path,next){
	var prev;
	if(next=='img1'){
		var cur_pic=document.getElementById(next);	
		var last_pic=document.getElementById('img2');	
		image_on_top="img2";
		prev="img2";
	}else if(next=='img2'){
		var cur_pic=document.getElementById(next);	
		var last_pic=document.getElementById('img1');	
		image_on_top="img1";
		prev="img1";
	}

	cur_pic.src=image_path;
	setTimeout("opacity('" + next + "', 0, 100, 500, '" + prev + "')", 750);

	return image_on_top;
}
////////////////////////////////////////////////
/////////////////SUB NAV FUNCTIONS//////////////
function window_size(ret){
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
			winW = window.innerWidth;
			winH = window.innerHeight;
		}
		if (navigator.appName.indexOf("Microsoft")!=-1) {
			winW = document.body.offsetWidth;
			winH = document.body.offsetHeight;
		}
	}
	if (winW <= 695){
		winW = 695;
	}
	if(ret=="h"){
		return winH;
	}else if(ret=="w"){
		return winW;
	}
}

function add_sub(el,num){
	var winW = window_size('w');
	var winH = window_size('h');

	if(el!=null && num!=null){
		var fake_array=eval("n"+num);
		var mn=document.getElementById(el);
		var sn=document.getElementById("sub");
		if(fake_array.length>0){
			var nsn='<table cellpadding="0" cellspacing="0">\n';
			for(x=0;x<fake_array.length;x++){
				nsn=nsn+'\t<tr>\n';
				if(fake_array[x+1]=="JAVASCRIPT:SEARCH"){
					nsn=nsn+'\t\t<td height="25" class="sub_off" onClick="var cords=\'center\'; final_popup(\'search_advanced.php\',\'absolutes/\',\'$popup=1;\',\'home_detail_popup\',cords,1);" onMouseOver="this.className=\'sub_over\';" onMouseOut="this.className=\'sub_off\';"><a href="Javascript:" class="hilite">';
				}else{
					nsn=nsn+'\t\t<td height="25" class="sub_off" onClick="make_link(\''+fake_array[x+1]+'\');" onMouseOver="this.className=\'sub_over\';" onMouseOut="this.className=\'sub_off\';"><a href="'+fake_array[x+1]+'" class="hilite">';
				}
				nsn=nsn+fake_array[x]+'</a></td>\n';
				if((x+2)!=fake_array.length){
					nsn=nsn+'\t</tr><tr><td style="height:1px; background-color:#747474;"></td></tr>';
				}else{
					nsn=nsn+'\t</tr>';
				}

				x++;
			}
			var cur_cell = document.getElementById("sub_nav"+num);
			var snw = document.getElementById("snw"+num);
			var tablecell = document.getElementById("tablecell"+num);

			var tbc_x = getXY(tablecell,"x");
			var tbc_y = getXY(tablecell,"y");

			//var half_width=((cur_cell.width-sn.width)/2);
			nsn=nsn+'</table>\n';
			sn.innerHTML=nsn;

			sn.style.left=tbc_x-(cur_cell.offsetWidth)+21; //tablecell.offsetLeft+((winW-695)/2)+snw.offsetWidth-15; 
			sn.style.top=tbc_y; //tablecell.offsetTop+140;

				//mn.offsetLeft+document.sub_nav25+((winW-695)/2);
				//sn.style.left=tablecell.offsetLeft+num+((winW-695)/2)+((snw.offsetWidth-120)/2); //mn.offsetLeft+document.sub_nav25+((winW-695)/2);
				//alert(tablecell.offsetLeft++' '+((winW-695)/2)+' '+((snw.offsetWidth-120)/2));
		
		}else{
			var sn=document.getElementById("sub");
			sn.innerHTML='';
			sn.style.left=0;
			sn.style.top=0;
		}
	}else{
		var sn=document.getElementById("sub");
		sn.innerHTML='';
		sn.style.left=0;
		sn.style.top=0;
	}
}
function remove_sub(){
	var sn=document.getElementById("sub");
	sn.innerHTML='';
	sn.style.left=0;
	sn.style.top=0;
}

function getXY(oElement,coord){
	if(coord=="y"){
		var iReturnValue = 0;
		while( oElement != null ) {
			iReturnValue += oElement.offsetTop;
			oElement = oElement.offsetParent;
		}
	}else if(coord=="x"){
		var iReturnValue = 0;
		while( oElement != null ) {
			iReturnValue += oElement.offsetLeft;
			oElement = oElement.offsetParent;
		}
	}
	return iReturnValue;
}

function make_link(url) {
	window.location.href = url; 
}
//////////////////////////////////////////////////