function resizeDivs(){
	var wh = getWH();
	myWidth = wh[0];
	myHeight = wh[1];
	var x = 438;
	if ($("#serpsearch").css("display") == "none") {
		x = 223;
	}
	if(myWidth>980){
		try{    	
			$('#sort_fsbo').css('display', 'inline');
		}
		catch(e){}
    }else{
    	$('#sort_fsbo').hide();
    }
	if ($.browser.safari) {
		$("#div_search_res").css('height', myHeight - x -13
		);
		$("#mapetc").css('height', myHeight - x - 20-13
		);
		$("#map").css('height', myHeight - x - 84-13
		);
	}
	else {
		$("#div_search_res").animate({
			height: myHeight - x-13
		});
		$("#mapetc").animate({
			height: myHeight - x - 20-13
		});
		$("#map").animate({
			height: myHeight - x - 84-13
		});
	}
	
}

function getEmFr(){
	if ($('#emailafriend').css('display') == 'block') {
		return;
	}
	$("#e_fr").empty();
	$.get("/sale-by-owner-home-services/get_html.html?file=get_serp_email_fr.html&captcha=1", {}, function(data){
		$("#e_fr").append(data);
		wh = getWH();
			$('#emailafriend').css('left', wh[0]/2-330)
					  .css('top', wh[1]/2-$('#emailafriend').height()/2).fadeIn();
	});
}
function getHotAl(){
	if ($('#hotalert').css('display') == 'block') {
		return;
	}
	$("#h_al").empty();
	$.get("/sale-by-owner-home-services/get_html.html?file=get_hot_prop_alert.html", {}, function(data){
		$("#h_al").append(data);
		wh = getWH();
		$('#hotalert').css('left', wh[0]/2-330)
					  .css('top', wh[1]/2-$('#hotalert').height()/2).fadeIn();
	});
}


function getSenators(state_code){
	jQuery.get("/ajax_senators/senators_state.xml?state_code="+state_code,{},viewSenatorsState);
}

function getRepresentativeZip(){
	jQuery.get("/ajax_senators/representatives_zip.xml?zip_code="+x_zip,{},viewRepresentativeZip);
}



function viewSenatorsState(data){
	var sen = data.documentElement.getElementsByTagName("sen");
	if (sen.length==0){
	    return;
	 }
	 
	 ht = ""
	 ht += "<table  width='100%' class='tbl3' style='font-size:100%' >"
	 ht += "<tr> <th colspan='6'>Senators in " + x_state_name +" </th></tr>" 
	 ht += "<tr>"
	 ht += "<td> <b> Name </b></td>"
     ht += "<td><b> Party </b></td>"
     ht += "<td><b> Phone </b></td>" 
     ht += "<td><b> Office </b></td>" 
     ht += "<td><b> WebSite </b></td>" 
     ht += "<td><b> Contact </b></td>"
     ht += "</tr>"
	  
	  
     for (var i=0; i<sen.length; i++){
		 
		 ht += "<tr>"
		 ht += "<td>"+sen[i].getAttribute("name") + "</td>"
		 ht += "<td>"+sen[i].getAttribute("party") + "</td>"
		 ht += "<td>"+sen[i].getAttribute("phone") + "</td>" 
		 ht += "<td>"+sen[i].getAttribute("office") + "</td>" 
		 
		 ht += "<td><a href='"+sen[i].getAttribute("web") + "' target='_blank' rel='nofollow'> WebSite </a> </td>" 
		 if (sen[i].getAttribute("contact"))
		     ht += "<td><a href='"+sen[i].getAttribute("contact") + "' target='_blank' rel='nofollow'> Contact </a></td>"
		 else 
		     ht += "<td> - </td>"
		 ht += "</tr>"

     }
	 
	document.getElementById('senators').innerHTML = ht; 
 }
 
 function viewRepresentativeZip(data){
    var sen = data.documentElement.getElementsByTagName("rep");
	if (sen.length==0){
		
	    return;
	 }
	 
	 ht = ""
	 ht += "<table  width='100%' class='tbl3' style='font-size:100%' >"
	 ht += "<tr> <th colspan='4'>Representative(s) in zipcode "+ x_zip +" </th></tr>" 
	 ht += "<tr>"
	 ht += "<td> <b> Name </b></td>"
      ht += "<td><b> Phone </b></td>" 
     ht += "<td><b>  Office </b></td>" 
     ht += "<td><b>  Link </b></td>" 
     ht += "</tr>"
	  
	  
     for (var i=0; i<sen.length; i++){
		 
		 ht += "<tr>"
		 ht += "<td>"+sen[i].getAttribute("name") + "</td>"
		 ht += "<td>"+sen[i].getAttribute("phone") + "</td>"
		 ht += "<td>"+sen[i].getAttribute("office") + "</td>" 
		 if (sen[i].getAttribute("link"))
		     ht += "<td><a href='"+sen[i].getAttribute("link") + "' target='_blank' rel='nofollow'> Link </a></td>"
		 else 
		     ht += "<td> - </td>"
		 ht += "</tr>"

     }
	 
	document.getElementById('representative').innerHTML = ht; 
 }
 

function getClimateInfo(){
	$.get("/ajax_house/get_climate.html?" + prms,{},function(data){
		$("#div_climate").html(data)
	});
	getClimateInfo = function (){};
}
function getNeighInfo(){
	getSenators(x_state_code);
	getRepresentativeZip();
	getNeighInfo = function (){};
}

function calcSort(el){
	var up = "http://static.fizber.com/images/sort-down.gif";
	var down = "http://static.fizber.com/images/sort-up.gif";
	var img;
	var elms_priop = {'id': 'DESC', 'price': 'DESC', 'city': 'ASC', 'num_bedrooms': 'DESC', 'num_bathrooms': 'DESC'};
	try{
		var obj = document.getElementById("sort_" + currSortByEl);
		obj.className = "";
		obj.removeChild(obj.childNodes[1]);
	}
	catch(e){}
	
	if(currSortByEl == el){
		if(currSortBy.indexOf(" ASC")!=-1){
			currSortBy = currSortBy.replace("ASC","") + "DESC";
		}else{
			currSortBy = currSortBy.replace("DESC","") + "ASC";
		}
	}else{
		currSortByEl = el;
		currSortBy = el + " " + elms_priop[el];
	}
	
	if(currSortByEl == "city"){
		if(currSortBy.indexOf(" ASC")!=-1){
			img = up;
		}else{
			img = down;
		}
	}else{
		if(currSortBy.indexOf(" ASC")!=-1){
			img = down;
		}else{
			img = up;
		}
	}
	var obj = document.getElementById("sort_" + currSortByEl);
	obj.className = "current";
	obj.innerHTML = obj.innerHTML + "   <img src='" + img + "' border=0>";
}

function init_ads() {
	var options1 = {
	'pubId' : 'pub-7971623650776759',
	'query' : s_qry,
	'format' : 'wide',
	'number' : 3,
	'container' : 'adcontainer1',
	'colorText': '#111111', 
	'colorTitleLink': '#21567B', 
	'colorDomainLink': '#999999', 
	'colorBackground': '#FFFFFF', 
	'colorBorder': '',
	'channel': '4017327667'
	};
	var dynamicAd = new google.ads.search.Ad(options1);
}

function loadMaps() {
	  google.load("maps", "2.x", {"callback" : loadMap});
	  google.load('ads.search', '1', {"callback": init_ads});
	  //google.setOnLoadCallback();
}

$(document).ready(function (){
	
	$(window).resize(resizeDivs);
	resizeDivs();
	$("#showsearch").click(function(){
		if ($("#serpsearch").css("display") == "none") {
			x = 465;
			$("#div_search_res").height($(window).height() - x);
			$("#mapetc").height($(window).height() - x - 20);
			$("#serpsearch").slideToggle("fast", resizeDivs);
		}else{
			$("#serpsearch").slideToggle("fast", function(){
				resizeDivs();
			});
		}
	});
	$("#optionscl").click(function(){
		$("#serpsearch").slideToggle("fast", function(){
			resizeDivs();
		});
		
	});
	
	$("#optionscl_").click(function(){
		$("#serpsearch").slideToggle("fast",  function(){
			resizeDivs();
		});
	});
	if(showsearch_cl){
		$("#showsearch").click();
	}
	try{
		calcSort(currSortByEl);
	}catch(e){}
	
	load_js("/static/js/gmaps/gmaps_reb_search.js?r=1");
	load_js(maps_url);

});






