var prms, house, house_text,  google_adr , cur_h_id , houseZip, crd , city_prep, st;


function load_tab(a,type){
	$("#div_" + type).load("/ajax_house/get_" + type + ".html?" + prms + "");
	urchinTracker('/detail_view/tab_'+type+'.html');
	a.onclick = function(){ $("#asvert").show();showInfo2(bottom_tabs,type,true); return false;};
	$("#asvert").show();
	showInfo2(bottom_tabs,type,true);
}
var cur_tab = "general_info";
function load_tab_2(a,type){
	urchinTracker('/detail_view/tab_'+type+'.html');
	$("#div_" + type).append($("<iframe frameborder='0'>")
		.attr('src', "/ajax_house/get_" + type + ".html?" + prms)
		.attr('id', 'ifr_' +type)
		.css('width', '100%')
		.css('height', '200')
		.css('border', 'none'))
	a.onclick = function(){$("#asvert").hide(); showInfo2(bottom_tabs,type,true); return false;};
	$("#asvert").hide();
	showInfo2(bottom_tabs,type,true);
}
function setHeight(h,type){
	$("#ifr_"+type).height(h)
}

function func_resize(){
	if(cur_tab != "general_info"){
		try{
			atr = document.getElementById("ifr_"+cur_tab).contentWindow ? document.getElementById("ifr_"+cur_tab).contentWindow : frames["ifr_"+cur_tab].window;
			setHeight(atr.hhh(),cur_tab);
		}catch(e){}
	}
	eval("setTimeout(func_resize, 1000)");
}

var efra = new Array('referers_email','captcha_uid','referers_name','friends_email',
'friends_name','listing','captcha','message');
function email_friend(houseID){
	if ($('#emailafriend').css('display') == 'block') {
		return;
	}
	$("#e_fr_dv").empty();
	$.get("/sale-by-owner-home-services/get_html.html?file=get_dv_email_fr.html&captcha=1&hid=" + houseID, {}, function(data){
		$("#e_fr_dv").append(data);
		$('#emailafriend').css('left', $(window).width()/2-330)
					  .css('top', $(window).height()/2-$('#emailafriend').height()/2).fadeIn();
		 
	});
                       
}


function ajax_house_score(house_id,score_type){
      $.getJSON('/ajax_safety/ajax_get_'+score_type+'_score.html',
	        {house_id:house_id},
            function ajax_view_score(json){
				if (json["score"] == "N/A") {
					score = 0;
				}
				else {
					score = parseInt(json["score"])/2;
				};
		         if (score%10>3){
		             $('#score_'+json["type"]+' b:eq('+parseInt(score/10)+')').removeClass("star3").removeClass("star2").addClass("star2")
		         }
		         $('#score_'+json["type"]+' b:lt('+parseInt(score/10)+')').each(function(){
		            $(this).removeClass("star3").removeClass("star2").addClass("star1")
		         });
			    $('#score_'+json["type"]).show();
			}	
       )
}

function ajax_count_stars(zip){
	$.get("/services/ajax_get_count_stars.html?zip="+escape(zip),{},
		function(data){
			eval("var count_stars = " + data)
			if (count_stars["cnt"]==0){
			    return;
			 }
		   $('#found_celebreties').html("<p style='margin-top:5px;'>We found "+count_stars["cnt"]+" celebrities in this area</p>")
		   .show();
		});
};

function clickVt(type, pr_vt, obj){
	obj.parentNode.id=type;
	$.get('/ajax_info_useful.html', {'type': type, 'vote': (pr_vt)?'yes':'no'}, 
		function(data){
			ret=getRet(data);
			$("#" + type).html(ret.text)});
}

var src_tmout;
var ph_postion;
var ph_stop;
var el_id = 1;
var nids = "#right_src";
function ddd(){
	
	if (ph_count > 5) {
		if(el_id==1 && ph_postion == 0){
			el_id = -1;
			nids = "#left_src";
		}else
		if(el_id==-1 && ph_postion == ph_stop){
			el_id = 1;
			nids = "#right_src";
		}
		$(nids).click()
		ph_postion -= el_id;
		src_tmout = setTimeout(ddd, 2000)
	}
}
	

$(document).ready(
	function(){
		//scroll
		$.easing.backout = function(x, t, b, c, d){
			var s=1.70158;
			return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
		};
		ph_postion = ph_count - 5;
		ph_stop = ph_postion
		$('#screen_src').scrollShow({
			view:'#view_src',
			content:'#images_src',
			easing:'backout',
			wrappers:'crop',
			navigators:'a[id]',
			navigationMode:'sr',
			circular:true,
			itemSize:{height:60,width:72},
			start:0
		}).mouseover(function(){
			clearTimeout(src_tmout);
		}).mouseout(function(){
			src_tmout= setTimeout(ddd, 2000);
		}).show();
		src_tmout= setTimeout(ddd, 2000);
		
		//ful scr gal
		$('#mynews a').lightbox();
		
		//realtor_st
		$.get('/ajax_house/ajax_get_stager_realtor_zip.html?zip='+houseZip,{},function(data){
			$("#realtor_stager").append(data);
		})
		
		//street view
		$.get('/sv-is-available.ajax', crd, 
			function(data){
				var ret=getRet(data);
				if(ret.js.isSv){
					$("#tab_street_view").css('display', 'inline');
				}
			}	
			);
		//was info helpful
		
		var p1='<span id="wih_';
		var p2 = '" style="display:none"><span class="tip">Was this information helpful?</span> &nbsp;&nbsp;&nbsp; <b class="opt washelp_up" onclick="clickVt(\'wih_';
		var p3 = '\',1, this)"></b>Yes &nbsp;&nbsp;&nbsp; <b class="opt washelp_down" onclick="clickVt(\'wih_';
		var p4 = '\',0, this);"></b>No </span>';
		var c = bottom_tabs.length, i;
		for(i=0;i<c;i++){
			$("#washelp_area").append(p1 + bottom_tabs[i] + p2 + bottom_tabs[i] + p3 + bottom_tabs[i] + p4);
		}		
		$("#wih_general_info").show();
		//view count
		if (userHouseStat === undefined){
			var userHouseStat = false;
		}
		
		$.get("/ping_house.html",{house_id: cur_h_id,house_stat:userHouseStat,referer:document.referrer});
		
		//trulia
		try{
			$("table[@name=zebra] tr:nth-child(odd)").addClass("odd");
		}catch(e){}		
				
		ajax_house_score(cur_h_id,'school');
		ajax_house_score(cur_h_id,'safety');
		ajax_house_score(cur_h_id,'job');
		ajax_count_stars(houseZip);
		
		setTimeout(func_resize, 3000);
	}
);
