// JavaScript Document

// Vertically centers the <h1> and logo in the header
function adjustHeader(){
	//var containerHeight = jQuery("#headInnerWrap").height();
	var logoHeight = jQuery("#logoBox").height();
	var logoWidth = jQuery("#logoBox").width();
	var headingHeight = jQuery("#logoHeader h1").height();
	var headingWidth = 747 - logoWidth;
	var headingMargin = logoWidth + 20;
	var padTop = 21;
	
	if (logoHeight > headingHeight){
		padTop = ((logoHeight - headingHeight)/2)+10;
		padTop = Math.round(padTop);
	}
	
	jQuery("#logoBox").css({ "float": "left", "display": "inline", "width": logoWidth, "margin-right": "20px" });
	jQuery("#logoHeader h1").css({ "float": "left", "display": "inline", "width": headingWidth, "padding-top": padTop });
}

// Drop menu for main navigation
function initalF(){
	toShow();
	prepareLinks();
}

var whoison = false;

function prepareLinks(){
	var links = document.getElementsByTagName("a");
	for (var i=0; i<links.length; i++){
		if(links[i].className == "firstLevel"){
			links[i].onmouseover = function(){
				var myTitle = this.getAttribute("name");
				var menuNum = myTitle.charAt(myTitle.length - 1);
				toShow('smenu' + menuNum);
				whoison = false;
			}
			links[i].onmouseout = function(){
				whoison = true;
				setTimeout("toHide()",1200);
			}
		}
		if(links[i].className == ""){
		//if(links[i].focus = true){
			links[i].onmouseover = function(){
				whoison = false;
			}
			links[i].onmouseout = function(){
				whoison = true;
				setTimeout("toHide()",1200);
			}
		}
	}
}

function toShow(id) {
	var d = document.getElementById(id);
		for (var i = 1; i<=10; i++) {
			if (document.getElementById('smenu'+i)) {
				document.getElementById('smenu'+i).style.display='none';
			}
		}
	if (d) {d.style.display='block';}
}

function toHide(){
	if (whoison != false){
		toShow();
	}
}


$(document).ready(function() {
	// Use jQuery to remove properties from <font> tags and reformat the copyright table
	$("font").attr({ face: "", color: "", size: "", style: "" });
	$("#contentInnerTable div").attr({ align: "" });
	
	// Remove image from Main Page content well
	$("#contentInnerTable table img[vspace=10]").css({ "display": "none" });
	
	// Change bg color for image on weather bar
	//$("table#contentInnerTable table table td[rowspan=2]").attr({ "bgcolor": "" });
	
	// Fix the formatting of the copyright area
	$("#copyrightWrap table").attr({ border: "0", width: "90%" });
	$("td.disclaimer").css({ "line-height": "16px" });
	$("td.disclaimer a:first").css({ "float": "left", "margin-right": "5px" });
	$("td.disclaimer a:first img").replaceWith('<img alt="AgentAdvantage" border="0" src="/images/elements/logo-aa-dark.gif"/>');
	
	// Add dollar signs before Min and Max fields in the QuickSearch box
	$("div.quickSearchMinPrice").prepend("<span>\$</span>");
	$("div.quickSearchMaxPrice").prepend("<span>\$</span>");

	// Auto-populate the City field in the QuickSearch box
	var myCity = "Type a City...";
	$("div.quickSearchCity input").attr({value: myCity});
	$("div.quickSearchCity input").focus(function(){
  	if(this.value == myCity)
    	this.value = '';
  	});
	$("div.quickSearchCity input").blur(function(){
  	if(this.value == '')
    	$("div.quickSearchCity input").attr({value: myCity});
  	});

	adjustHeader();
	initalF();
	
});
