function getTruliaSalesScript(c,s){
    if (c || s){
        $("#trulia_sales").show();
        var data = {city:c,state:s};
        $.get("/ajax-trulia.html",data,
			function (data){
				var ret = getRet(data)
				displayTruliaSales(ret.js,ret.text)
			});
    }
    else {
        return false
    }
}

function displayTruliaSales(data,text){
    if(text=='ok'){
        var obj = document.getElementById("trulia_small");
        $("#loader_trulia").hide();
        var im = document.createElement("img");
		im.src = data['pic'];
		if (data['pic'].indexOf('nograph') > -1) {
			im.style.width = '395px !important';
		}
        obj.appendChild(im);
    }
}

function setPaggingEvents(){
$("a", "#top_tabs").each(function(i){ 	$(this).click( function (){
$("li", "#top_tabs").each(function(i){$(this).removeClass('current') });	
$(this).parent().addClass('current');
$.get($(this).attr('href'),
  { ajax: "1" },
  function(data){
    $("#div_search_res").empty().append( data);
  }
);
return false;
})});
}


var load_state = false;
function getAllStates(){
	     $("#list_states").slideToggle("slow", function (){
	       if ($("#list_states").is(":hidden")){
	           $("#all_states1").html("View all States");
			   $("#all_states2").html("View all States");
	       }else{
	           $("#all_states3").html("Hide States");
	           $("#all_states2").html("Hide all States");
			   $("#all_states1").html("Hide all States");
	           if (!$("#list_cities").is(":hidden")) {
	                   getAllCities();
	              }
               if (!$("#list_counties").is(":hidden")) {
                       getAllCounties();
                  }

	       }                
	     });
    	 if (load_state) return;
         load_state = true;
         u = "/services/ajax_get_list_state_usa.xml";
         $.ajax({
                type: "GET",
                url: u,
                dataType: "xml",
                success: function(xml) {
					$('#list_states img').remove()
                    $(xml).find('state').each(function(){
                         $('<li style="width:24% !important;"></li>')
                             .append($('<a href="http://'+$(this).attr('u')+'.fizber.com"></a>').html($(this).attr('n')))
                             .appendTo('#list_states ul');

                 }); //close each(
             }
         }); //close $.ajax(
}

var load_country = false;
var t_county_ = 0
var s_county_ = ""
function getAllCounties(){
         $("#list_counties").slideToggle("slow", function (){
           if ($("#list_counties").is(":hidden")){
               $("#all_counties1").html("View all Counties");
           }else{
               $("#all_counties2").html("Hide Counties");
               $("#all_counties1").html("Hide all Counties");
               if (!$("#list_cities").is(":hidden")) {
                       getAllCities();
                  }
               if (!$("#list_states").is(":hidden")) {
                       getAllStates();
                  }

           }                
         });	
         if (load_country) return;
         load_country = true;
         u = "/services/ajax_get_list_counties_state.xml?state_code=" + state_code;
         $.ajax({
                type: "GET",
                url: u,
                dataType: "xml",
                success: function(xml) {
					     $('#list_counties img').remove()
                         $(xml).find('county').each(function(){
                         u =  "http://www.fizber.com/fsbo-data-base/"+$(this).attr('u')+"-county-" + state_ready +"-real-estate-fsbo.html"
                         s_county_ += '<li style="width:24% !important;"><a href="'+u+'">'+$(this).attr('name') +'</a></li>'
                         t_county_ += 1; 
                         if (t_county_ >10){
                            $('#list_counties ul').append(s_county_);
                            s_county_ = ""
                            t_county_ = 0
                         } 

                        });$('#list_counties ul').append(s_county_); //close each(
                
             }
         }); //close $.ajax(
}

var load_cities = false;
var t_city_ = 0
var s_city_ = ""
function getAllCities(){
         $("#list_cities").slideToggle("slow", function (){
           if ($("#list_cities").is(":hidden")){
               $("#all_cities1").html("View All Cities");
           }else{
               $("#all_cities2").html("Hide Cities");
               $("#all_cities1").html("Hide All Cities");
               if (!$("#list_states").is(":hidden")) {
                      getAllStates();
                  }
               if (!$("#list_counties").is(":hidden")) {
                       getAllCounties();
                  }

           }                
         });
         if (load_cities) return;
             load_cities = true;
             u = "/services/ajax_get_list_cities_state.xml?state_code=" + state_code;
             $.ajax({
             type: "GET",
             url: u,
             dataType: "xml",
             success: function(xml) {
			 	    $('#list_cities img').remove()
                    $(xml).find('city').each(function(){
                         //  alert($(this).attr('u'));  
                         u =  "http://www.fizber.com/fsbo-data-base/"+$(this).attr('u')+"-city-" + state_ready + "-real-estate-fsbo.html"
                         s_city_ += '<li style="width:24% !important;"><a href="'+u+'">'+$(this).attr('name') +'</a></li>'
                         t_city_ += 1; 
                         if (t_city_ >100){
                            $('#list_cities ul').append(s_city_);
                            s_city_ = ""
                            t_city_ = 0
                         } 
                             

                 }); //close each(
                                             
             }
         }); //close $.ajax(
}



$(document).ready(function(){
	setPaggingEvents();
	
	
});
