
function updateMLSresultsCallBack(page_index, paging_container) {
	var x = jQuery("#paginate_nav").html();
	var url_params = location.href.split('?');
	//hide bottom pagination nav
	jQuery("#paginate-bottom").empty();
	//add ajax spinner
	jQuery("#mls_search_results").html("<center><p style='clear:both'>Loading Sarasota Search Results...<br /><img style='border:0px;' src='"+true_mls.url+"/ajax-spinner.gif' /></center></p>").load(true_mls.ajax_url+"mls-viewer-ajax.php?"+url_params[1],{offset:page_index});
	
	//ugly hack for pagination on bottom
	jQuery("#paginate-bottom").html(x).find("a").removeAttr("id").click(function(e){
		e.preventDefault();
		var page_number = jQuery(this).html();
		jQuery("#paginate_" + page_number).trigger("click");
	});
	
}

function initListingDetailModal(mls_id) {
							
	jQuery("#email_btn").click(function(e) {
		e.preventDefault();
		jQuery("#mls_modal").load(true_mls.ajax_url+"mls-email-ajax.php").modal({position: ["10%",""]});
	});

	jQuery("#map_btn").click(function(e) {
		//Google Maps API ABQIAAAASZOg_lWMefsYjTlTWtxVzRSx5Ad_Eb26zIIwL7wxeHKSLC4IxBSDShVxJwJdDzVKztvry6uTuFPI5A
		e.preventDefault();
		var html_text = '<div id="map_canvas" style="width:100%; height:400px;"></div>';
		jQuery("#mls_modal").html(html_text).modal();
		initialize_google_map(mls_lat,mls_lon);
	});
	jQuery("#streetview_btn").click(function(e) {
		e.preventDefault();
		var html_text = '<div id="streetview_canvas" style="width:100%; height:400px;"></div>';
		jQuery("#mls_modal").html(html_text).modal();
		initialize_street_view(mls_lat,mls_lon);
	});
	jQuery("#birdeye_btn").click(function(e) {
		e.preventDefault();
		var html_text = '<div style="width:550px; height:400px;"><div style="position:relative; height:390px;"  id="birds_eye"></div></div>';
		jQuery("#mls_modal").html(html_text).modal();
		initialize_birds_eye(mls_lat,mls_lon);
	});	
	jQuery('#send_email_btn').live("click", function(e) {
			e.preventDefault();
			var email_address = jQuery('#sendto').val();
			var mls_email_key = email_address + mls_id;
			mls_email_key = mls_email_key.replace('@','__');
			mls_email_key = mls_email_key.replace('.','_');
			if (window[mls_email_key] != true) {
				window[mls_email_key] = true;
				jQuery('#ajax_modal_status').empty().load(true_mls.ajax_url+"mls-email-ajax.php",{sendto: email_address, mls_id: mls_id}).fadeIn('fast').fadeTo(2800,1).fadeOut('fast');
			} else {
				jQuery('#ajax_modal_status').empty().html("<span style='color:red;'>An email has already been send to the specified address.</span>").fadeIn('fast').fadeTo(2800,1).fadeOut('fast');
			}
		   //use jquery load to add ajax response from script and pass mls and email as array params
	});

}


function initialize_google_map(lat,lon) {
    var latlng = new google.maps.LatLng(Number(lat), Number(lon));
    var myOptions = {
      zoom: 13,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.HYBRID
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
	var marker = new google.maps.Marker({
      position: latlng, 
      map: map, 
      title:mls_id
  });   
  }
  
  function initialize_street_view(lat,lon) {
	var panorama = new google.maps.StreetViewPanorama(document.getElementById("streetview_canvas"));
	panorama.setPosition(new google.maps.LatLng(Number(lat), Number(lon)));


  }
  
  function initialize_birds_eye(lat,lon) {
	var map = null;
	var mls_home = new VELatLong(Number(lat), Number(lon));
	map = new VEMap('birds_eye');
    map.LoadMap(mls_home, 17);
	map.SetBirdseyeScene(mls_home);
	var pushpin = new VEShape(VEShapeType.Pushpin, mls_home);
    pushpin.SetTitle('mls_id');
	map.AddShape(pushpin);
	
	jQuery("#MSVE_Map div").click(function(e) {
		alert('Yo!');
	});


  }
  
