
/*
 * 
 * Available modes for the property view, default is Gallery
 * 
 */
 
// ADD THIS variables
var addthis_pub="moongroup";
var addthis_options = 'delicious,facebook,google,live,myspace,stumbleupon,twitter';
var addthis_test0309 = false; 

var propertyDetail_GALLERY_MODE	='gallery';
var propertyDetail_MAP_MODE 	='map';
var propertyDetail_STREET_MODE	='street';
var propertyDetail_VIDEO_MODE	='video';
 
var propertyDetail_changeEnabled=true; //used to avoid multiple calls without affecting asynchronous calls	
var propertyDetail_currentMode=propertyDetail_GALLERY_MODE;

var propertyDetail_viewMode = {};
	 	propertyDetail_viewMode.gallery	='/site/master.cfm?fuseaction=site-ajax.displayPropertyDetailGallery';
		propertyDetail_viewMode.map		='/site/master.cfm?fuseaction=site-ajax.displayPropertyDetailMap';
		propertyDetail_viewMode.street	='/site/master.cfm?fuseaction=site-ajax.displayPropertyDetailStreet';
		propertyDetail_viewMode.video	='/site/master.cfm?fuseaction=site-ajax.displayPropertyDetailVideo';
	
var propertyDetail_URL ='/site/master.cfm?fuseaction=site-ajax.displayTeamList';


var propertyDetail_options = {
								dataType: 'html',
								url: propertyDetail_URL,
								type: 'GET',	
								data: "",  
								async:true, 
								cache:false,
								/*timeout:30, */  					
								success: function(responseHtml, textStatus){
				   					 //show the content
				   					
				   					 $("#other_view").animate({ opacity: 'hide'}, 
				   					 							 { queue:"false", 
				   					 							   duration:1000, 
				   					 							   easing:"linear", 
				   					 							   complete:function(){
				   					 							     $("#other_view").html(responseHtml);	
																	 $("#other_view").animate({ opacity: 'show'}, { queue:"true", duration:1000, easing:"linear" });	
																   	 propertyDetail_changeEnabled=true; 																   	 																  
																   }
																   
									  
									});
									moveTop();
				   								   					 				   					 		   
				  				},
				  				error: function(XMLHttpRequest, textStatus, errorThrown){
				  					alert("An error occured, please try again\n"+ textStatus + ' ' + errorThrown);
				  					propertyDetail_changeEnabled=true;
				  					moveTop(); 
				  				} 	
				  											    
							  };


/*
 * 
 * Available modes for main content view, default is Property Details
 * 
 */
var propertyDetailContent_PROPERTY_DETAILS_MODE	='prop_dtls_wrapper';
var propertyDetailContent_COMPARATIVE_SALES_MODE 	='comp_sales_dtl_wrapper';
var propertyDetailContent_CALCULATORS_MODE	='calculator_dtl_wrapper';
var propertyDetailContent_SUBURB_PROFILE_MODE	='suburb_profile_dtl_wrapper';
 
var propertyDetail_existingComment;	

var propertyDetail_comment_options = {
		dataType: 'html',
		async : true,
		cache: false,
		url: '/site/master.cfm?fuseaction=site-ajax.saveComment',
		type: 'GET',	        					
		beforeSubmit: function(formArray, qForm) {
							
		},
	    success: function(response) { 	
			propertyDetail_existingComment = $('#userComments').val();
				 
	    },
	    error: function (XMLHttpRequest, textStatus, errorThrown) {
				  $("#comment_form_box").html("<span class='form_error_message'>An error occured, please try again ("+ textStatus + errorThrown + ")</span>");
					moveTop();
		}
	  };





/* function switchToMode
 * 
 * switch the result list into different modes
 * 
 */		
function propertyDetail_switchToMode(mode,propId){
	
	if ( propertyDetail_changeEnabled ){ 			
		
		 //hide content
		  $("#default_view").css("display","none");
		 
		 //$("#other_view").animate({ opacity: 'hide'}, { queue:"false", duration:100, easing:"linear" });	
		 
		 //display loading design
		 $("#other_view").html('<div class="preloader_wrapper_col3"><div id ="loader" class="preloader_light_32_alt"/><span>Loading</span></div></div>');    
		 //$("#other_view").animate({ opacity: 'show'}, { queue:"false", duration:100, easing:"linear" });	
		 
		propertyDetail_options.data ="propId=" + propId;
		propertyDetail_options.url  = propertyDetail_viewMode[mode];
		
		//remove all active states		
		$("#propertyGallery_mode, #propertyMap_mode, #propertyStreet_mode, #propertyVideo_mode").removeClass('active');
			
		//apply the new active based on mode selected
		propertyDetail_setCurrentMode(mode);
			
		//disable other queries
		propertyDetail_changeEnabled=false; 
		
				 
		 //make the request
		 $.ajax(propertyDetail_options); 
				
	}
				
	return false;
		
}



/* function setCurrentMode
 * 
 * sets the currentMode
 * this function will be called every time a page or piece of page gets loaded
 */	
function propertyDetail_setCurrentMode(mode){
	propertyDetail_currentMode=mode;		
	
	//attach active state
	switch (mode) {
		case propertyDetail_GALLERY_MODE:
			$("#propertyGallery_mode").addClass('active');
			break;
		case propertyDetail_MAP_MODE:	
			$("#propertyMap_mode").addClass('active');			
			break;
		case propertyDetail_STREET_MODE:
			$("#propertyStreet_mode").addClass('active');
			break;		
		case propertyDetail_VIDEO_MODE:
			$("#propertyVideo_mode").addClass('active');
			break;	
	}
	
}



/* function propertyDetailContent_switchToMode
 * 
 * switch  content into different modes
 * 
 */		
function propertyDetailContent_switchToMode(mode){
	
		
	//hide content			
	$("#"+propertyDetailContent_PROPERTY_DETAILS_MODE).css('display','none');
	$("#"+propertyDetailContent_COMPARATIVE_SALES_MODE).css('display','none');	
	$("#"+propertyDetailContent_CALCULATORS_MODE).css('display','none');
	$("#"+propertyDetailContent_SUBURB_PROFILE_MODE).css('display','none');
	
	//apply the new active based on mode selected
	propertyDetailContent_setCurrentMode(mode);
				
	return false;
		
}




/* function propertyDetailContent_setCurrentMode
 * 
 * sets the currentMode for content
 */	
function propertyDetailContent_setCurrentMode(mode){

	//remove active states
	$("#propertyDetail_secondaryDetails, #propertyDetail_secondarySuburbProfile, #propertyDetail_secondarySales, #propertyDetail_secondaryCalculators").removeClass('active');
	

	// display active state
	switch (mode) {
		case propertyDetailContent_PROPERTY_DETAILS_MODE:
			$("#"+propertyDetailContent_PROPERTY_DETAILS_MODE).css('display','block');
			$("#propertyDetail_secondaryDetails").addClass('active');	
			break;
		case propertyDetailContent_SUBURB_PROFILE_MODE:
			$("#"+propertyDetailContent_SUBURB_PROFILE_MODE).css('display','block');
			$("#propertyDetail_secondarySuburbProfile").addClass('active');	
			break;
		case propertyDetailContent_COMPARATIVE_SALES_MODE:	
			$("#"+propertyDetailContent_COMPARATIVE_SALES_MODE).css('display','block');	
			$("#propertyDetail_secondarySales").addClass('active');		
			break;
		case propertyDetailContent_CALCULATORS_MODE:
			$("#"+propertyDetailContent_CALCULATORS_MODE).css('display','block');
			$("#propertyDetail_secondaryCalculators").addClass('active');	
			break;		
	}
	
}






/* 
 *  
 * 
 * propertyDetail Gallery
 * 
 * 
 * 
 * */





/*
 * initialise carousel
 * 
 */
function propertyDetail_initGalleryCarousel(carousel) {

	
	propertyDetail_galleryCarousel=carousel;
};


/*
 * handle change of state on next carousel button
 * 
 */
function propertyDetail_nextGalleryStateHandler(carousel, button, enabling)
{

    if (enabling) {
    	$("#galleryNav #galleryNav-next").css("display","block");
                      
    } else {
        $("#galleryNav #galleryNav-next").css("display","none");
    }

}

/*
 * handle change of state on prev carousel button
 * 
 */
function propertyDetail_prevGalleryStateHandler(carousel, button, enabling)
{
	

	 if (enabling) {
    	$("#galleryNav #galleryNav-prev").css("display","block");
                      
    } else {
        $("#galleryNav #galleryNav-prev").css("display","none");
    }

}


/* function propertyDetail_openFloorplan
 *  
 * displays floorplan in popup
 *  
 * 
 */ 
function propertyDetail_openFloorplan(propertyId, fileName, fileWidth, fileHeight) {

	var filePath= '/site/doc/Property/'+propertyId+'/'+fileName;
	var thisWindowName = 'bw_floorplan';
	var scrollbarStatus = false;
	
	if ( fileWidth <= 0 || fileWidth >= 800 ) {
		fileWidth = 500; // default popup width
		if(fileWidth >= 800) scrollbarStatus = true;
	}
	
	if ( fileHeight <= 0 || fileHeight >= 800 ) {	
		fileHeight = 600; // default popup height
		if( fileHeight >= 800 ) scrollbarStatus = true;
	}
	
	var w = window.open(filePath,thisWindowName,'left=20,top=20,width='+fileWidth+',height='+fileHeight+',toolbar=false,scrollbars='+scrollbarStatus+',resizable=false,menubar=false,location=false,status=false');
	w.focus();


}



/* function propertyDetail_sendEmail
 *  
 * displaya thickbox for the user to send the current property to an email address
 *  
 * 
 * Note:requires thickbox scripts to be already loaded
 */ 
function propertyDetail_sendEmail(pagePath,openDetail,propertyID){

	var options = {
			dataType: 'json',
			url: '/site/master.cfm?fuseaction=site-ajax.validateAuth',
			type: 'GET',	 
			async:false, 
			cache:false,       					
			timeout:30, //ms
			
			success: function(response) { 	
				    	
		    	if (response.retcode == "OK")	{
		    		
		    		//display saved search window, it will not redirect on completion, it will just close
		    		subnav_show('site-ajax.displayPopupEmail&propertyID='+propertyID,0);
		    	
		    	} 					    		
		    	else{	//user is not authenticated		    		
		    		//display login window with redirection to the search on success
		    		subnav_show('site-ajax.displayLogin',1,'component','site-ajax.displayPopupEmail%26thisPagePath='+pagePath+'%26openDetail='+openDetail+'%26propertyID='+propertyID);
		    		
		    	}				  	    						 										 
		    },
		    
		    error: function(XMLHttpRequest, textStatus, errorThrown){
				alert("An error occured, please try again\n"+ textStatus + ' ' + errorThrown);
			} 	
		    
	  };	
					
	//ajax call for the popup					
	$.ajax(options);

	
	return false;
	
	
}




/* function propertyDetail_smsAgent
 *  
 * display a thickbox for the user to send a contact request to a property agent
 *  
 * 
 * Note:requires thickbox scripts to be already loaded
 */ 
function propertyDetail_smsAgent(pagePath,openDetail,staffID,propID,nType,ntoKey,nfromKey,nReferer){
		
	var options = {
			dataType: 'json',
			url: '/site/master.cfm?fuseaction=site-ajax.validateAuth',
			type: 'GET',	 
			async:false, 
			cache:false,       					
			timeout:30, //ms
			
			success: function(response) { 	
				    	
		    	if (response.retcode == "OK")	{
		    		
		    		//display saved search window, it will not redirect on completion, it will just close
		    		subnav_show('site-ajax.displayPopupSms&staffID='+staffID+'&propID='+propID,0);
		    		
		    		//Track hit
					trackme(nType,ntoKey,nfromKey,nReferer);
		    	
		    	} 					    		
		    	else{	//user is not authenticated		    		
		    	
		    		//display login window with redirection to the search on success
		    		subnav_show('site-ajax.displayLogin',1,'component','site-ajax.displayPopupSms%26thisPagePath='+pagePath+'%26openDetail='+openDetail+'%26staffID='+staffID+'%26propID='+propID);
		    		
		    	}				  	    						 										 
		    },
		    
		    error: function(XMLHttpRequest, textStatus, errorThrown){
				alert("An error occured, please try again\n"+ textStatus + ' ' + errorThrown);
			} 	
		    
	  };	
					
	//ajax call for the popup					
	$.ajax(options);

	
	return false;
	
	
}


/*
function propertyDetail_prepareComment(propId) {

		// *** Handles user comment box
		propertyDetail_setExistingComment();
		$("#comment_buttons").css('display','none');
	    $('#comments_form').ajaxForm( propertyDetail_comment_options );   
	    
	      
	    // submit comment
	    $("#comment_btn_submit").click(function() {
	    	//$("#comment_form").ajaxSubmit(propertyDetail_comment_options);
	    	propertyDetail_submitComment(<cfoutput>#attributes.propid#</cfoutput>);
	        $('#userComments').removeClass('userCommentsEdit');
	        $("#comment_buttons").css('display','none');
			propertyDetail_setExistingComment();
	        return false;
	    });
		
	    // cancel comment
	    $("#comment_btn_cancel").click(function() {
	          $('#userComments').removeClass('userCommentsEdit');
	          $('#userComments').val(propertyDetail_existingComment);
	          $("#comment_buttons").css('display','none');
	          return false;
	    });
	    
	
	    // autogrow for comments box
	    $('textarea#userComments').autogrow({
			maxHeight: 300,
			minHeight: 30,
			lineHeight: 16
		});


		// *** Handles user comment box
		propertyDetail_setExistingComment();
		$("#comment_buttons").css('display','none');
	    $('#comments_form').ajaxForm( propertyDetail_comment_options );   
	    
	      
	    // bind submit comment
	    $("#comment_btn_submit").click(function() {
	    	//$("#comment_form").ajaxSubmit(propertyDetail_comment_options);
	    	propertyDetail_submitComment(propId);
	        $('#userComments').removeClass('userCommentsEdit');
	        $("#comment_buttons").css('display','none');
			propertyDetail_setExistingComment();
	        return false;
	    });
		
	    // bind cancel comment
	    $("#comment_btn_cancel").click(function() {
	          $('#userComments').removeClass('userCommentsEdit');
	          $('#userComments').val(propertyDetail_existingComment);
	          $("#comment_buttons").css('display','none');
	          return false;
	    });
	    
	
	    // autogrow for comments box
	    $('textarea#userComments').autogrow({
			maxHeight: 300,
			minHeight: 30,
			lineHeight: 16
		});
		
}


function propertyDetail_setExistingComment() {
	
	propertyDetail_existingComment = $('#userComments').val(); 
}

		
function propertyDetail_submitComment(propId) {

	$("#comment_form").ajaxSubmit(propertyDetail_comment_options);
	if(propertyDetail_existingComment != ""){
		$("span.comment_"+propId).css("display","block");
		$("span.comment_"+propId).attr('title',propertyDetail_existingComment);
	} else {
		$("span.comment_"+propId).css("display","none");
	}
}
*/


/* function propertyDetail_login
 *  
 * displaya thickbox for the user to login if not authenticated already
 *  
 * 
 * Note:requires thickbox scripts to be already loaded
 */ 
 
 /*
function propertyDetail_editComment(pagePath) {
		
	var options = {
			dataType: 'json',
			url: '/site/master.cfm?fuseaction=site-ajax.validateAuth',
			type: 'GET',	 
			async:false, 
			cache:false,       					
			timeout:30, //ms
			
			success: function(response) { 	
				    	
		    	if (response.retcode == "OK")	{
		    		
		    		propertyDetail_showEditComment();
		    	
		    	} 					    		
		    	else{	//user is not authenticated		    		
		    	
		    		//display login window with redirection to the search on success
		    		subnav_show('site-ajax.displayLogin',1,'global',pagePath);
		    		
		    		
		    	}				  	    						 										 
		    },
		    
		    error: function(XMLHttpRequest, textStatus, errorThrown){
				alert("An error occured, please try again\n"+ textStatus + ' ' + errorThrown);
			} 	
		    
	  };	
					
	//ajax call for the popup					
	$.ajax(options);

	
	return false;
	
	
}

function propertyDetail_showEditComment() {
	$('#userComments').addClass('userCommentsEdit');
	$('#comment_buttons').css('display','inline');
		    		
}

*/
