var bLeftColLoaded=0;
var bRightColLoaded=0;
var intervalBackground=0;
var intActiveContentArea=1; //this is used to keep track of which panel is displaying (1=main listing panel, 2=image tour, 3=agent panel
var bMenuExtruded=0;
var bMenuMotionInProgress=0;
var bSearchExtruded=0;
var bSearchMotionInProgress=0;
var intMoreResults=0;
var bMotionInProgress=0;
var intervalCloseDoorOnPageLoad=0;
var intervalOpenDoorOnPageLoad=0;

var strBasePath=""; //could be http://www.picketfencerealty.com/stage/

function showHome(){

var strCurrentContentArea="#contentArea1 div.leftSection div.leftColumn div.mainListingContentArea";
var elContentArea=$(strCurrentContentArea);

var strPageToLoad="getHomePage.php";

$("#contentArea1 div.rightSection div.rightColumn").fadeOut(500);

elContentArea.fadeOut(500,
  function(){
  
		  	//show the loading message
			$("div.loadingProperty").show();
  
			$.get(
				strPageToLoad,
				function(strHTML) {
				
					//populate the main content
					elContentArea.html($(strHTML).find('div#mainContentContainer').html());
					
					//ADD THE SIDEBAR HERE\
					//populate the main content
					$("#contentArea1 div.rightSection div.rightColumn").html($(strHTML).find('div#sidebarContentContainer').html());
					
					//set up the tabs
					$('ul.hpTabs').tabs('div.hpPanes div.hpPane',{event:'mouseover', effect: 'fade', fadeOutSpeed: 400});

				
		  			//hide the loading message
					$("div.loadingProperty").hide();
					
					elContentArea.fadeIn(500);
					$("#contentArea1 div.rightSection div.rightColumn").fadeIn(500);
		
					
				},"html"); //get  
  
  });//end fadeOut
  
}

function showCommunityLinks(strCommunityName){

var strCurrentContentArea="#contentArea1 div.leftSection div.leftColumn div.mainListingContentArea";
var elContentArea=$(strCurrentContentArea);

var strPageToLoad="getCommunityLinks.php?communityName=" + strCommunityName;

$("#contentArea1 div.rightSection div.rightColumn").fadeOut(500);

elContentArea.fadeOut(500,
  function(){
  
		  	//show the loading message
			$("div.loadingProperty").show();
  
			$.get(
				strPageToLoad,
				function(strHTML) {
				
					//populate the main content
					elContentArea.html($(strHTML).find('div#mainContentContainer').html());
					
					//ADD THE SIDEBAR HERE\
					//populate the main content
					$("#contentArea1 div.rightSection div.rightColumn").html($(strHTML).find('div#sidebarContentContainer').html());
					
				
		  			//hide the loading message
					$("div.loadingProperty").hide();
					
					elContentArea.fadeIn(500);
					$("#contentArea1 div.rightSection div.rightColumn").fadeIn(500);
		
					
				},"html"); //get  
  
  });//end fadeOut
  
}



function showSingleListing(listingNumber){

	if ( bMotionInProgress==0 ){
	
		bMotionInProgress=1;		
		
		//intActiveContentArea=1; //need to slide over to it if this is set to anything but 1
		
		var strCurrentContentArea="#contentArea1 div.leftSection div.leftColumn div.mainListingContentArea";
		var elContentArea=$(strCurrentContentArea);
		
		var strContentAreaSidebar="#contentArea1 div.rightSection div.rightColumn";
		var elContentAreaSidebar=$(strContentAreaSidebar);
		
		elContentAreaSidebar.fadeOut(500);
		
		elContentArea.fadeOut(500,
		  function(){
		  
		  	//show the loading message
			$("div.loadingProperty").show();
		
			bLeftColLoaded=0;
			bRightColLoaded=0;
			
			var strPageToLoad="showListing.php?LN=" + listingNumber;
		
			$.get(
				strPageToLoad,
				function(strHTML) {
									
					elContentArea.html($(strHTML).find("div#mainContentContainer").html());
					
					elContentAreaSidebar.html($(strHTML).find("div#sidebarContentContainer").html());
					
					//preload any images
					$('#contentArea1 div.leftSection div.leftColumn div.mainListingContentArea * img').imgpreload
								({
									all: function()
									{			


											//load the images in the sidebar
											$('#contentArea1 div.rightSection div.rightColumn * img').imgpreload
														({
															all: function()
															{			
																//continue with script
																
																//hide the loading message
																$("div.loadingProperty").hide();
					
																bMotionInProgress=0;
								
																elContentArea.fadeIn(500);
					
																elContentAreaSidebar.fadeIn(500);
																
															}
														});
										
										
									}
								});
		
					
				},"html"); //get
		
		   });//elContentArea.fadeOut
		   
	} //if ( bMotionInProgress==0 )
	
	return false;
}



function loadVirtualTour(listingNumber){

	if ( bMotionInProgress==0 ){
	
		bMotionInProgress=1;
		
		//check if the main panel is currently visible
		//resetActivePanel();
		
	  	//show the loading message
		$("div.loadingProperty").show();	
		
		var strThumbnailPageToLoad="listingImages.php?LN=" + listingNumber;
		
		$.get(
			strThumbnailPageToLoad,
			function(strHTML) {
			
				//grab the address from the existing h2
				$('div#contentArea2 div.leftSection div.leftColumn h2').html($('div#contentArea1 div.leftSection div.leftColumn h2').html());
	
				//load the main image
			  $('div.virtualTourImage').html($(strHTML).find("div#mainImageContentContainer").html());
			  
			  $('#virtualTourThumbnailHolder').html($(strHTML).find("div#thumbnailContentContainer").html());
			  			
				//preload the main image
				$('div.virtualTourImage img').imgpreload
				({
					all: function()
					{
								//preload the thumbnail images
								$('div#virtualTourThumbnailHolder ul.virtualTourThumbnailContainter li img').imgpreload
								({
									all: function()
									{			
										//make the thumbnails magic!
										setThumbnailPreview("#virtualTourThumbnailHolder ul.virtualTourThumbnailContainter li");
										
										//hide the loading message
										$("div.loadingProperty").hide();
										
										bMotionInProgress=0;	
										
										fadeLeft();
										
									}
								});
					}
				});
	
				
			},"html"); //get
			
	} //if ( bMotionInProgress==0 )
}

function fadeLeft(){

	bMotionInProgress=1;
	
  var strOldContentArea="#contentArea1";
  var elOldContentArea=$(strOldContentArea);

  var strNewContentArea="#contentArea2";
  var elNewContentArea=$(strNewContentArea);

/*
  var strNewLeftColumn="#leftColumn" + intActiveContentArea;
  var elNewLeftColumnContentArea=$(strNewLeftColumn);

  var strNewRightColumn="#rightColumn" + intActiveContentArea;
  var elNewRightColumnContentArea=$(strNewRightColumn);
*/

  elNewContentArea.fadeIn(300, function(){
  
  		if ( intActiveContentArea==1 ){

				  $('#wrapper').animate({
				    left: '-=990px',
				    "easing": "easein"
				  }, 800, function() {
			
							bMotionInProgress=0;
							intActiveContentArea=2;
						  
						    // Animation complete.
							elOldContentArea.fadeOut(300, function(){
								
					
								//these lines will allow the content to change again - should be called once user goes back to listing
								//$('#contentArea1').html($('#contentArea2').html());
					
								//$('#contentArea1').show();
								//$('#contentArea2').hide();
					
								//$('#wrapper').css('left', '32px');
					
							});
			
				  	});
			
			  		
		} else {
		
				bMotionInProgress=0;
				intActiveContentArea=2;
			  
			    // Animation complete.
				elOldContentArea.fadeOut(300);		
		
		} //if ( intActiveContentArea==1 ){
		
	});

}

function backToListings(){

  var strOldContentArea="#contentArea2";
  var elOldContentArea=$(strOldContentArea);

  var strNewContentArea="#contentArea1";
  var elNewContentArea=$(strNewContentArea);
  
  elNewContentArea.fadeIn(300,function(){
  
  		intActiveContentArea=1;

	  $('#wrapper').animate({
	    left: '32px',
	    "easing": "easein"
	  }, 800, function() {
	    // Animation complete.

		elOldContentArea.fadeOut(300, function(){
			

			//these lines will allow the content to change again - should be called once user goes back to listing
			//$('#contentArea1').html($('#contentArea2').html());

			//$('#contentArea1').show();
			//$('#contentArea2').hide();

			//$('#wrapper').css('left', '32px');

		});

	  });
	  
	 });
}

function clickMenu(){
	if(bMenuExtruded==0){
		showMenu();
	} else {
		hideMenu();
	}
}

function showMenu(){
	if(bMenuMotionInProgress==0){
		bMenuMotionInProgress=1;
		clearTimeout(intervalCloseDoorOnPageLoad);
		$('#extrudingMenu').animate({
		left: '0px',
		'easing': 'easein'
		}, 300, function() {
			//animation complete
			bMenuExtruded=1;
			bMenuMotionInProgress=0;
			});
	}
}

function hideMenu(){
	if(bMenuMotionInProgress==0){
		bMenuMotionInProgress=1;
		$('#extrudingMenu').animate({
		left: '-196px',
		'easing': 'easein'
		}, 300, function() {
			//animation complete
			bMenuExtruded=0;
			bMenuMotionInProgress=0;
			});
	}
}

function clickSearch(){
	if(bSearchExtruded==0){
		showSearch();
	} else {
		hideSearch();
	}
}

function showSearch(){
	if(bSearchMotionInProgress==0){
		bSearchMotionInProgress=1;

		//reset the offset value		
		$("#offset").val(parseInt(0));
		
		$('#extrudingMenu2').animate({
		width: '226px',
		left: '820px',
		'easing': 'easein'
		}, 200, function() {
			//animation complete
			bSearchExtruded=1;
			bSearchMotionInProgress=0;
			});
	}
}

function hideSearch(){
	if(bSearchMotionInProgress==0){
		bSearchMotionInProgress=1;
		$('#extrudingMenu2').animate({
		width: '26px',
		left: '1014px',
		'easing': 'easein'
		}, 200, function() {
			//animation complete
			bSearchExtruded=0;
			bSearchMotionInProgress=0;
			});
	}
}

function showVirtualTourOverlay(){
// select the overlay element - and "make it an overlay" 
$("#overlay_virtualTour").overlay().load();
}

function showSearchOverlay(strType,bOpenHouses){
	
	//reset the offset value		
	$("#offset").val(parseInt(0));
	
	if(strType=='pfr'){
		$("#searchPFR").attr("checked", "checked");
		$("#searchMLS").removeAttr("checked");
	} else {
		$("#searchMLS").attr("checked", "checked");
		$("#searchPFR").removeAttr("checked");
	}
	
	//if it's an open house search, display the open house select box
	if ( bOpenHouses==1 ) {
		$("#openHouseDateContent").show();
		$("#overlay_search div.leftColumn div.details h2").text("Open House Search");
		$("#searchOpenHouses").val("1");
	} else {
		$("#openHouseDateContent").hide();
		$("#overlay_search div.leftColumn div.details h2").text("Property Search");
		$("#searchOpenHouses").val("0");
	}

	// select the overlay element - and "make it an overlay" 
	$("#overlay_search").overlay().load();
	
	//set the focus to the city field
	$("#listingCityZip").focus();
	
}

function showVirtualTourImage(listingNumber,imageNumber){

var strCurrentContentArea="div.virtualTourImage";
var elContentArea=$(strCurrentContentArea);

var strPageToLoad="listingImageMain.php?LN=" + listingNumber + "&ImgNum=" + imageNumber;

elContentArea.fadeOut(200,
  function(){

	  $('div.virtualTourImage').load(strPageToLoad,
		function() {
		
			//preload the image
			$('<img />')
			    .attr('src', $('div.virtualTourImage img').attr('src'))
			    .load(function(){
			    
		   			 elContentArea.fadeIn(300);

			    });

		});

   });
}

function setThumbnailPreview(elements){

	//Larger thumbnail preview 
	
	$(elements).hover(function() {
		$(this).css({'z-index' : '10'});
		$(this).find('img').addClass("hover").stop()
			.animate({
				marginTop: '-75px', 
				marginLeft: '-100px', 
				top: '50%', 
				left: '50%', 
				width: '160px', 
				height: '120px'
			}, 60);
		
		} , function() {
		$(this).css({'z-index' : '0'});
		$(this).find('img').removeClass("hover").stop()
			.animate({
				marginTop: '0', 
				marginLeft: '0',
				top: '0', 
				left: '0', 
				width: '100px', 
				height: '75px'
			}, 60);
	});

}

function setThumbnailPreviewAgents(elements){

	//Larger thumbnail preview 
	
	$(elements).hover(function() {
		$(this).find('img').css({'z-index' : '10'});
		$(this).find('img').addClass("hover").stop()
			.animate({
				marginTop: '-90px', 
				marginLeft: '-67.5px', 
				top: '50%', 
				left: '50%', 
				width: '120px', 
				height: '160px'
			}, 60);
		
		} , function() {
		$(this).find('img').css({'z-index' : '0'});
		$(this).find('img').removeClass("hover").stop()
			.animate({
				marginTop: '0', 
				marginLeft: '0',
				top: '0', 
				left: '0', 
				width: '67.5px', 
				height: '90px'
			}, 60);
	});

}

function resetActivePanel(){

		  if ( intActiveContentArea==2 ){
		  		backToListings();
		  }
		  
		  if ( intActiveContentArea==3 ){
		  		backToListingsFromAgents();
		  }
		  
		  intActiveContentArea=1;
		  
}

function searchProperties() { //strPropertyCityZip,listingPriceRangeLow,listingPriceRangeHigh){

	if ( bMotionInProgress==0 ){
	
		  bMotionInProgress=1;
		  
		  //check if the main panel is currently visible
			resetActivePanel();
		
		  var strPageToLoad="/search_property_thumbnails.php"; // ?propertyCityZip=" + strPropertyCityZip&propertyPriceRangeLow=" + ;
		  var postFormData=$("#searchform :input").serializeArray();  //.serialize();
		
		  var strNewContentArea="#contentArea1 div.leftSection div.listingThumbnailContainer";
		  var elNewContentArea=$(strNewContentArea);
		  
			//reset the offset value in the search form
			$("#offset").val(parseInt(0)); 
			
			$("div.getMoreResultsLink").hide(); 
		    
		  elNewContentArea.fadeOut(100,function(){
		 	//display the loading message
		 	$("div.loadingSearch").show();
			
			$.post(
				strPageToLoad,
				postFormData,
				function(strHTML) {
				
					//var newXML = parseXml(xml);
				
					intMoreResults=parseInt( $(strHTML).find("div#moreRecords").text() );
					
					intResultsReturned=parseInt( $(strHTML).find("div#resultsReturned").text() );
					
					//if ( moreRecords==1 ){
						//$("div.getMoreResultsLink").show();
					//} else {
					$("div.getMoreResultsLink").hide();
					//}
					
					//if results were not returned, display message saying so
					if (intResultsReturned==0){
					
						//hide the loading message
						$("div.loadingSearch").hide(); 
						
						elNewContentArea.fadeIn(200);
						
						bMotionInProgress=0;	
					
						alert ("Your search returned no results.");	
					
					} else {
					
											
						  	//preload the images
							$(strHTML).find("div#contentContainer div.page div img.preloadMe").imgpreload
														({
															all: function()
															{	
															
																	elNewContentArea.html($(strHTML).find("div#contentContainer").html());
							
																	//show the first listing			
																	$('#contentArea1 div.leftSection div.leftColumn div.mainListingContentArea').html($(strHTML).find("div#mainContentContainer").html());
										
										
																	//and the sidebar
																	$("#contentArea1 div.rightSection div.rightColumn").html($(strHTML).find("div#sidebarContentContainer").html());

																		//hide the loading message
																		$("div.loadingSearch").hide(); 
															
																		elNewContentArea.fadeIn(200,function(){
															
																						var root = $("div.scrollable").scrollable({
																							circular: false, 
																							onSeek: function(e, i) {
																								afterSeekScrollable(i);
																							}
																						}).autoscroll({ autoplay: false }).navigator();
																								
																						//make it so that when the scrollable element is moused over, any autoscrolling stops
																									
																						$('div.scrollable').bind(
																							'mouseover',
																						    function(){
																								root.data("scrollable").stop();
																								//api.stop();
																						    }
																						  );	
																						
																						//do the same thing with the div.previousNextLinks element
																						$('div.previousNextLinks').bind(
																							'mouseover',
																						    function(){
																								root.data("scrollable").stop();
																								//api.stop();
																						    }
																						  );
																						  
																						  bMotionInProgress=0;
																
																		}); //elNewContentArea.fadeIn(200,function()
															}
														});
										

							
					} //if (intResultsReturned==0)
					
				},"html"); //post
		  }); //elNewContentArea.fadeOut(100,function()
     
  	} //if (bMotionInProgress==0)
}

<!-- Original:  Cyanide_7 (leo7278@hotmail.com) -->
<!-- Web Site:  http://www7.ewebcity.com/cyanide7 -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
num = Math.floor(num/100).toString();
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$' + num);
}
//  End -->


function loadAgentThumbnails(){

if ( bMotionInProgress==0){

	//check if the main panel is currently visible
	//resetActivePanel();

	bMotionInProgress=1;
	//intActiveContentArea=3;

	//var strPageToLoad_MP="http://picketfencerealty.dreamhosters.com/agent_thumbnails.php?office=mp";
	//var strPageToLoad_AH="http://picketfencerealty.dreamhosters.com/agent_thumbnails.php?office=ah";
	
	var strPageToLoad_MP="/agent_thumbnails.php?office=mp";
	var strPageToLoad_AH="/agent_thumbnails.php?office=ah";	
	
	bRightColLoaded=0;
	bLeftColLoaded=0;
	
	//show the loading message
	$("div.loadingProperty").show();
		
		//load the mp thumbnails
	  $('#ahAgentThumbnailHolder').load(strPageToLoad_AH,
		function() {
			
			//preload the images

			$('div#ahAgentThumbnailHolder ul.agentThumbnailContainer li img').imgpreload
			({
				all: function()
				{
					// this = jQuery image object selection
					// callback executes when all images are loaded

				  //make the thumbnails magic! 
				  setThumbnailPreviewAgents("#ahAgentThumbnailHolder ul.agentThumbnailContainer li");	
		  
		  			bLeftColLoaded=1;
				     
						if(bRightColLoaded==1) {
							//hide the loading message
							$("div.loadingProperty").hide();
							bMotionInProgress=0;
				     		fadeLeftForAgents();
				  		}		
				}
			});

		});		
		
		//load the mp thumbnails
	  $('#mpAgentThumbnailHolder').load(strPageToLoad_MP,
		function() {
			
			//preload the images

			$('div#mpAgentThumbnailHolder ul.agentThumbnailContainer li img').imgpreload
			({
				all: function()
				{
					// this = jQuery image object selection
					// callback executes when all images are loaded

				  //make the thumbnails magic! 
				  setThumbnailPreviewAgents("#mpAgentThumbnailHolder ul.agentThumbnailContainer li");	
		  
		  			bRightColLoaded=1;
				     
						if(bLeftColLoaded==1) {
							//hide the loading message
							$("div.loadingProperty").hide();
							bMotionInProgress=0;
				     		fadeLeftForAgents();
				  		}		     
				     
				}
			});

		});
		
} //if ( bMotionInProgress==0)

}

function fadeLeftForAgents(){

	var strOldContentArea="";

	if ( intActiveContentArea==2){
		
		strOldContentArea="#contentArea2";
		
	} else {

  		strOldContentArea="#contentArea1";
  	}
  	
  var elOldContentArea=$(strOldContentArea);

  var strNewContentArea="#contentArea3";
  var elNewContentArea=$(strNewContentArea);


  elNewContentArea.fadeIn(300, function(){

  		if ( intActiveContentArea==1 ){

			  $('#wrapper').animate({
			    left: '-=990px',
			    "easing": "easein"
			  }, 800, function() {
			    // Animation complete.
			    
			    intActiveContentArea=3;
		
				 elOldContentArea.fadeOut(300);
		
			  });
			  
		} else {

				intActiveContentArea=3;		
				elOldContentArea.fadeOut(300);
		
		}

  });

}

function backToListingsFromAgents(){

  var strOldContentArea="#contentArea3";
  var elOldContentArea=$(strOldContentArea);

  var strNewContentArea="#contentArea1";
  var elNewContentArea=$(strNewContentArea);
   
  elNewContentArea.fadeIn(300,function(){

		  $('#wrapper').animate({
		    left: '32px',
		    "easing": "easein"
		  }, 800, function() {
		    // Animation complete.
	
	
			intActiveContentArea=1;
			elOldContentArea.fadeOut(300);
	
		  });
	  
	 });
}

function addToWishList(LN){

	var strPageToLoad="/addToWishList.php?LN=" + LN;
	
	//show the loading message
	$("div.loadingProperty").show();

		//load the mp thumbnails
	  $('#overlay_wishList div.leftColumn div.wishListThumbnails').load(strPageToLoad,
		function() {	
		
			//show the loading message
			$("div.loadingProperty").hide();
		
			$("#overlay_wishList").overlay().load();
			
			//add action to each link
			$("#overlay_wishList div.leftColumn div.wishListThumbnails div a.wishListPropertyLink").click(
			
				    function($event){
			
				      hideWishList();
			
				    }
			);
			
		});
		
		return false;
		
}

function showWishList(){

	var strPageToLoad="/showWishList.php";
	
	//show the loading message
	$("div.loadingProperty").show();

		//load the mp thumbnails
	  $('#overlay_wishList div.leftColumn div.wishListThumbnails').load(strPageToLoad,
		function() {		
			$("#overlay_wishList").overlay().load();
			
			//show the loading message
			$("div.loadingProperty").hide();
			
			//add action to each link
			$("#overlay_wishList div.leftColumn div.wishListThumbnails div a.wishListPropertyLink").click(
			
				    function($event){
			
				      hideWishList();
			
				    }
			);
			
		});
		
}

function saveWishList(){

	//make save link hidden
	$("div#saveWishListLink").hide();	
	
	var strPageToLoad="/storeWishListInCookie.php";
	
	var strPostData="";
	
	$.post(
			strPageToLoad,
			strPostData,
			function(strHTML) {
							
				//do nothing
				
			},"html"); //post
	

		
}

function deleteWishList(){

	//make delete link hidden
	$("div#deleteWishListLink").hide();
	
	//close the wish list overlay			
	$("#overlay_wishList").overlay().close();	

	var strPageToLoad="/deleteWishList.php";
	
	var strPostData="";
	
	$.post(
			strPageToLoad,
			strPostData,
			function(strHTML) {
				
				//do nothing			
				
			},"html"); //post

}


function hideWishList(){

	$("#overlay_wishList").overlay().close();
		
}

function showAgent(AndroidDataID){

	var strPageToLoad="/showAgentContent.php?ADID=" + AndroidDataID;

	$.get(
		strPageToLoad,
		function(strHTML) {
				
			strAgentName=$(strHTML).find("div#agentName").text();

			$("#overlay_agent div.leftColumn h2").html(strAgentName);	
			
			$("#overlay_agent div.leftColumn div#agentInfoContainer").html($(strHTML).find("div#agentContent").html());
			
			$("#overlay_agent div.leftColumn div.contactAgentLink").html($(strHTML).find("div#agentLinkContent").html());
			
			//initialize the tabs
			$('ul.agentTabs').tabs('div.agentPanes > div.agentPane',{event:'click', effect: 'default'});		
			
			$("#overlay_agent").overlay().load();

			
		},"html"); //get
		
}

function showEmailToAFriend(LN,bWishList){
	//set the hidden field to the listing number
	$("#LN_emailFriend").val(LN);
	
	//set the hidden field to indicate if the wish list is to be sent or not
	$('#emailFriend_wishList').val(bWishList);
	
	//alert(bWishList);	
	
	if (bWishList==1){
		$('#emailMessage').text("Here are the properties I found on PicketFenceRealty.com that I thought you would like.");
	} else {
		$('#emailMessage').text("Here is a property I found on PicketFenceRealty.com that I thought you would like.");
	}
	
	//reload the captcha
	document.getElementById('captcha_emailFriend').src = '/securimage/securimage_show.php?' + Math.random();
	
	//reset the captcha code field
	$("#captcha_code_emailFriend").val("");
	
	$("#overlay_emailFriend").overlay().load();
	
	//move the focus to the first field
	$("#recipEmail").focus();
	
}

function emailToAFriend(){

	//check for completeness
	var bComplete=1;
	
	if ( $("#recipEmail").val()=="" ){
		alert("Please enter your friend's email address.");
		bComplete=0;
	}

	if ( bComplete==1 && $("#senderEmail").val()=="" ){
		alert("Please enter your email address.");
		bComplete=0;
	}
	
	if ( bComplete==1 && $("#emailMessage").val()=="" ){
		alert("Please type a message.");
		bComplete=0;
	}
	
	if ( bComplete==1 && $("#captcha_code_emailFriend").val()=="" ){
		alert("Please type the code that appears.");
		bComplete=0;
	}
	
	if ( bComplete==1 ){
	
		$("#overlay_emailFriend").overlay().close();
	
		var strPageToLoad="/emailFriend.php";
	 	var postFormData=$("#emailform :input").serializeArray();
	 	$.post(strPageToLoad,postFormData,function(strHTML){
	 	
			var intSuccess=parseInt( $(strHTML).find("div#successCode").text() );
			
			if ( intSuccess==1  ){
		 		alert('Your message has been sent.');
		 	} else {
		 		$("#overlay_emailFriend").overlay().load();
		 		var strErrorDesc=$(strHTML).find("div#errorDesc").text();
		 		alert(strErrorDesc);
		 	}
		 	 	
	 	},'html');
 	
 	}
 	
 	return false;

}

function showMoreInfo(LN,strMode,bWishList){
	//set the hidden field to the listing number
	$("#LN_moreInfo").val(LN);
	
	//set the hidden field to indicate if the wish list is to be sent or not
	$('#moreInfo_wishList').val(bWishList);
	
	//determine the mode (moreInfo or showing) and change h2 and message body accordingly
	if ( strMode=="moreInfo" ){
		$("#overlay_moreInfo div.leftColumn h2").text("Request More Information");
		if ( bWishList==1 ){
			$("#moreInfo_emailMessage").text("I would like more information on these properties I found on PicketFenceRealty.com.");
		} else {
			$("#moreInfo_emailMessage").text("I would like more information on this property I found on PicketFenceRealty.com.");
		}
	} else {
		$("#overlay_moreInfo div.leftColumn h2").text("Request a Showing");
		if ( bWishList==1 ){		
			$("#moreInfo_emailMessage").text("I would like to request a showing on these properties I found on PicketFenceRealty.com.");
		} else {
			$("#moreInfo_emailMessage").text("I would like to request a showing on this property I found on PicketFenceRealty.com.");
		}
	}
	
	//determine if this is a pfr listing or other
	var officeID=$("div.listingOfficeID").text();
	
	if ( officeID==8269 || officeID==8296 ) {
	
		//hide the office to contact
		$("#selectOfficeContent").hide();
		
	
	} else {
	
		//show the office to contact
		$("#selectOfficeContent").show();
	
	}
	
	if ( bWishList == 1 ) {
		$("#selectOfficeContent").show();
	}
	
	//reload the captcha
	document.getElementById('captcha_moreInfo').src = '/securimage/securimage_show.php?' + Math.random();
	
	//reset the captcha code field
	$("#captcha_code_moreInfo").val("");
	
	$("#overlay_moreInfo").overlay().load();
	
	//move the focus to the first field
	$("#moreInfo_senderName").focus();
	
}

function emailMoreInfo(){
	//check for completeness
	var bComplete=1;

	if ( bComplete==1 && $("#moreInfo_senderName").val()=="" ){
		alert("Please enter your name.");
		$("#moreInfo_senderName").focus();
		bComplete=0;
	}
	
	if ( bComplete==1 && $("#moreInfo_senderEmail").val()=="" ){
		alert("Please enter your email address.");
		$("#moreInfo_senderEmail").focus();
		bComplete=0;
	}
	
	if ( bComplete==1 && $('input[name=moreInfo_contactPreference]:checked').val()=="Phone" && $("#moreInfo_senderPhone").val()=="" ){
		alert("Please enter your phone number or select email as the contact preference.");
		$("#moreInfo_senderPhone").focus();
		bComplete=0;
	}
	
	if ( bComplete==1 && $("#moreInfo_emailMessage").val()=="" ){
		alert("Please type a message.");
		$("#moreInfo_emailMessage").focus();
		bComplete=0;
	}
	
	if ( bComplete==1 && $("#captcha_code_moreInfo").val()=="" ){
		alert("Please type the code that appears.");
		$("#captcha_code_moreInfo").focus();
		bComplete=0;
	}
	
	if ( bComplete==1 ){
	
		$("#overlay_moreInfo").overlay().close();
	
		var strPageToLoad="/moreInformation.php";
	 	var postFormData=$("#moreinfoform :input").serializeArray();
	 	$.post(strPageToLoad,postFormData,function(strHTML){
	 	
			var intSuccess=parseInt( $(strHTML).find("div#successCode").text() );
			
			if ( intSuccess==1  ){
		 		alert('Your message has been sent.');
		 	} else {
		 		
		 		var strErrorDesc=$(strHTML).find("div#errorDesc").text();
				//otherwise display the error message
				$("#overlay_moreInfo").overlay().load();	 		
	 			alert(strErrorDesc);
	 			return false;
	 			
		 	} //if ( intSuccess==1  )
		 	 	
	 	},'html');
 	
 	} //if ( bComplete==1 )
 	
 	return false;

}

function showContactAgent(AgentID){

	//set the hidden field to the agent's Android Data ID
	$("#agentID").val(AgentID);
	
	$("#contactType_office").val("0");
	
	$("#officeID").val("");
	
	$("div#overlay_contactAgent div.leftColumn h2").text("Contact Agent");
	
	
	//reload the captcha
	document.getElementById('captcha_contactAgent').src = '/securimage/securimage_show.php?' + Math.random();
	
	//reset the captcha code field
	$("#captcha_code_contactAgent").val("");
	
	$("#overlay_contactAgent").overlay().load();
	
	//move the focus to the first field
	$("#contactAgent_senderName").focus();
	
}


function contactAgent(){
	
	//check for completeness
	var bComplete=1;

	if ( bComplete==1 && $("#contactAgent_senderName").val()=="" ){
		alert("Please enter your name.");
		$("#contactAgent_senderName").focus();
		bComplete=0;
	}

	if ( bComplete==1 && $("#contactAgent_senderEmail").val()=="" ){
		alert("Please enter your email address.");
		$("#contactAgent_senderEmail").focus();
		bComplete=0;
	}
	
	if ( bComplete==1 && $("#contactAgent_emailMessage").val()=="" ){
		alert("Please type a message.");
		$("#contactAgent_emailMessage").focus();
		bComplete=0;
	}
	
	if ( bComplete==1 && $('input[name=contactAgent_contactPreference]:checked').val()=="Phone" && $("#contactAgent_senderPhone").val()=="" ){
		alert("Please enter your phone number or select email as the contact preference.");
		$("#contactAgent_senderPhone").focus();
		bComplete=0;
	}
	
	if ( bComplete==1 && $("#captcha_code_contactAgent").val()=="" ){
		alert("Please type the code that appears.");
		$("#captcha_code_contactAgent").focus();
		bComplete=0;
	}
	
	if ( bComplete==1 ){
	
		$("#overlay_contactAgent").overlay().close();
	
		var strPageToLoad="/contactAgent.php";
	 	var postFormData=$("#contactagentform :input").serializeArray();
	 	$.post(strPageToLoad,postFormData,function(strHTML){
	 	
			var intSuccess=parseInt( $(strHTML).find("div#successCode").text() );
			
			if ( intSuccess==1  ){
		 		alert('Your message has been sent.');
		 	} else {
		 		$("#overlay_contactAgent").overlay().load();
		 		var strErrorDesc=$(strHTML).find("div#errorDesc").text();
		 		alert(strErrorDesc);
		 	}
		 	 	
	 	},'html');
 	
 	}
 	
 	return false;

}

function contactOffice(strOffice){

	//set the hidden field to the office ID
	$("#officeID").val(strOffice);
	
	$("#contactType_office").val("1");
	
	$("div#overlay_contactAgent div.leftColumn h2").text("Contact Office");
	
	
	//reload the captcha
	document.getElementById('captcha_contactAgent').src = '/securimage/securimage_show.php?' + Math.random();
	
	//reset the captcha code field
	$("#captcha_code_contactAgent").val("");
	
	$("#overlay_contactAgent").overlay().load();
	
	//move the focus to the first field
	$("#contactAgent_senderName").focus();
	
}


function getSchools(){

	var schoolDistrict=$("#listingSchoolDistrict").val();
	
	var IsFound = /^-?\d+$/.test(schoolDistrict);
	
	if (IsFound) {
		$('#listingSchool').html('<option value="">Any</option>');
		$('#listingSchool').load('getSchools.php?schoolDistrict=' + schoolDistrict);
	} else {
		$('#listingSchool').html('<option value="">Any</option>');
		$("#listingSchoolDistrict").val('');	
	}
}

function getMoreResults(){

	if ( bMotionInProgress==0 ) {
	
		bMotionInProgress=1;
	
		//increment the offset value
		if ( parseInt($("#offset").val()) == 0 ){
			$("#offset").val(parseInt(40));
		} else {
			$("#offset").val(parseInt($("#offset").val()) + 5);
		}
		
		//show the loading message
		$("div.loadingSearch").show();
		//$("div#loading").show(); 
	
	 	var strPageToLoad="/search_property_thumbnails_more.php"; // ?propertyCityZip=" + strPropertyCityZip&propertyPriceRangeLow=" + ;
	 	var postFormData=$("#searchform :input").serializeArray();  //.serialize();
	 	
		$("div.getMoreResultsLink").hide(); 	 	
	 	
		$.post(
			strPageToLoad,
			postFormData,
			function(strHTML) {
			
				parseMoreResultsHTML(strHTML);
				bMotionInProgress=0;
				
			},
			"html"
		);//post
		
	} //if bMotionInProgress==0

}


function parseMoreResultsHTML(strHTML){

 	// get handle to scrollable API
	var api = $(".scrollable").data("scrollable");
	
	intMoreResults=parseInt( $(strHTML).find("div#moreRecords").text() );
					
	intResultsReturned=parseInt( $(strHTML).find("div#resultsReturned").text() );
	
	//intMoreResults=parseInt( $(strHTML).find("div#moreRecords").text() );
	
  //find every Tutorial and print the author
  $(strHTML).find("div.page").each(function()
  {
	//alert($(this).text());
	 api.addItem($(this).clone());  
  
  });
   
  	//preload the images
	$(strHTML).find("div.page div img.preloadMe").imgpreload
								({
									all: function()
									{	

										//hide the loading message
										$("div.loadingSearch").hide();
									   api.end();
									
									}
								});

}

//UTILITY FUNCTION TO FIX IE PROBLEM - NOT BEING USED CURRENTLY
function parseXml(xml) {  
	if (jQuery.browser.msie) {  
		var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");  
		xmlDoc.loadXML(xml);  
		xml = xmlDoc;  
	}  
	return xml;  
}  


function afterSeekScrollable(index){
	
	if ( intMoreResults==1 ) {	
	
			//if this is the last page, display the notification for more data	
			
			//get the api	
			var api = $(".scrollable").data("scrollable");
			
			//alert(api.getSize());
			
			if ( index == ( api.getSize() - 1 ) ){
				$("div.getMoreResultsLink").show();
			} else {
				$("div.getMoreResultsLink").hide();
			}
	
	}
	
}

function resetSearchForm(){

	//set the form fields
	$("#offset").val(parseInt(0));
	$("#searchMLS").attr("checked", "checked");
	$("#searchPFR").removeAttr("checked");
	$("#searchType").val("searchMLS");
	$("#listingBedrooms").val("");
	$("#listingSchoolDistrict").val("");
	$("#listingSchool").val("");
	$("#listingPriceRangeLow").val("");
	$("#listingPriceRangeHigh").val("");

}

function searchByVillage(strVillageName){

	//reset the search form
	resetSearchForm();

	$("#listingCityZip").val(strVillageName);
	
	$("#searchOpenHouses").val("0");
	
	searchProperties();

}

function openHouseSearchByVillage(strVillageName){

	//reset the search form
	resetSearchForm();
	
	$("#listingCityZip").val(strVillageName);

	//set the hidden field to indicate open house search
	$("#searchOpenHouses").val("1");
	
	//search any future dates
	$('input[name=openHouseDate]').val("ANY")
	
	searchProperties();

}

function removeFromWishList(LN,elementID){

	var strPageToLoad="/removeFromWishList.php";
	
	var strPostData="LN=" + LN;

	//remove it from the page right away to prevent being clicked again	

	$("#" + elementID).parent().parent().remove();	

	//use POST to submit to URL
		
	$.post(
			strPageToLoad,
			strPostData,
			function(strHTML) {
			
				//don't do anything
				//alert(strHTML);
				
			},"html"); //post

	return false;
}

function openDoorOnPageLoad(){
	clearTimeout(intervalOpenDoorOnPageLoad);
	//open the menu
	clickMenu();
	intervalCloseDoorOnPageLoad=setTimeout("closeDoorOnPageLoad()", 4000);
}

function closeDoorOnPageLoad(){
	clearTimeout(intervalCloseDoorOnPageLoad);
	if ( bMenuExtruded==1 ){
		clickMenu();
	}
}
