// JavaScript Document
var fadebox = "<div class='FadeFrame' id='FadeFrame'>Loading...<br />Please Wait...<br /><img src='/images/loading1.gif' height='32' width='32' alt='Loading' border='0' /></div>";
var fadesendbox = "<div class='FadeFrame' id='FadeFrame'>Sending...<br />Please Wait...<br /><img src='/images/loading1.gif' height='32' width='32' alt='Loading' border='0' /></div>";


jQuery(document).ready(function(){


  $(".nextclientslide").click(function(){
		clearInterval(clientintervalid);		
		$("#lblautoscroll").fadeOut("normal");
		nextSlide();																 
  });


  $(".prevclientslide").click(function(){
		clearInterval(clientintervalid);																		 
		$("#lblautoscroll").fadeOut("normal");
		prevSlide();																 
  });
	
	$(".scrollpagejump").click(function(){
		clearInterval(clientintervalid);	
		$("#lblautoscroll").fadeOut("normal");
		var pagenum = $(this).attr("pg");
		slideJump(pagenum);																 
  });
	
	function submit_contact_form(){
		jQuery(fadesendbox).appendTo("#ContactForm");
		jQuery("#ContactForm").fadeTo(1000, 1, function() {		
			jQuery.post("/include/postcontact.php",
						 jQuery("#frmContactUs").serialize(),
						 function(data) {
								jQuery("#ContactForm").fadeTo(100, 1);
								jQuery("#ContactForm").html(data);
								jQuery("#FadeFrame").remove();
								jQuery(".btnSubmitContact").click(submit_contact_form);
						 }
			);
		});
	};
	
	jQuery(".btnSubmitContact").click(submit_contact_form);


	function clear_listing_search() {
		var objType =document.getElementById("cboLSType")
		var objBeds =document.getElementById("cboLSBeds")
		var objBath =document.getElementById("cboLSBaths")
		
		
		objType.selectedIndex = 0;
		objBeds.selectedIndex = 0;
		objBath.selectedIndex = 0;
		
		$("#txtLSPriceMin").attr("value","");
		$("#txtLSPriceMax").attr("value","");
		document.frmListingSearch.submit();
	}
	
	jQuery(".btnClearSearch").click(clear_listing_search);
	
	
	//HST CALCULATORS
	function hst_calc_homeowner() {
		var houseprice = 0;
		var hsttotal = 0;
		var rebateamt = 0;
		var hstpaid = 0;
		var pstamt = 0;
		var gstamt = 0;
		var finalprice = 0;
		
		houseprice = parseFloat(jQuery("#HomePrice").attr("value"));
		if (houseprice > 525000) {
			hsttotal = houseprice * 0.12;
			rebateamt = 26250;
		} else if (houseprice > 450000) {
			hsttotal = houseprice * 0.12;
			rebateamt = houseprice * 0.05;
		} else if (houseprice > 0) {
			hsttotal = houseprice * 0.12;
			pstamt = houseprice * 0.05;
			gstamt = pstamt * 0.36;			
			rebateamt = pstamt + gstamt;
		}
		hstpaid = hsttotal - rebateamt;
		
		finalprice = parseFloat(houseprice + hstpaid);
		
		jQuery("#HSTPaid").attr("value",hstpaid.toFixed(2));
		jQuery("#HSTRebate").attr("value",rebateamt.toFixed(2));
		jQuery("#FinalPrice").attr("value",finalprice.toFixed(2));
	};
	jQuery(".btnCalcHstHome").click(hst_calc_homeowner);
	
	
	function run_currency_exchange() {
		
		jQuery("#ExchangeFrame").fadeTo(500, 0.25, function() {		
			jQuery.post("/include/currencyform2.php",
					 jQuery("#frmExchConvert").serialize(),
					 function(data) {
							jQuery("#ExchangeFrame").html(data);
							jQuery("#ExchangeFrame").fadeTo(500, 1);
							jQuery(".lnkExchange").click(run_currency_exchange);
					 }
			);
		});
		
	};
	jQuery(".lnkExchange").click(run_currency_exchange);
});


var mapwindow = '';
var gallwindow = '';

function popup_map(propertyid, linkid, rentalid) {

	if (!mapwindow.closed && mapwindow.location) {
		mapwindow.location.href = '/include/popmap.php?id='+propertyid+'&link='+linkid+'&rent='+rentalid;
	}
	else {
		mapwindow=window.open('/include/popmap.php?id='+propertyid+'&link='+linkid+'&rent='+rentalid,'name','height=500,width=650,scrollbars=no');
		if (!mapwindow.opener) mapwindow.opener = self;
	}
			
	if (window.focus) {mapwindow.focus()}
	

}

function popup_gallery(propertyid, rentalid ) {

	if (!gallwindow.closed && gallwindow.location) {
		gallwindow.location.href = '/gallery.php?id='+propertyid+'&rent='+rentalid;
	}
	else {
		gallwindow=window.open('/gallery.php?id='+propertyid+'&rent='+rentalid,'name','height=575,width=875,scrollbars=no');
		if (!gallwindow.opener) gallwindow.opener = self;
	}
			
	if (window.focus) {gallwindow.focus()}
	

}

	var clientintervalid;
	
	function slideJump(page) {
    var $active = $('#scrollcontainer span.active');
		//var page = $(this).attr("pg");
	  var $next = $('#scrollbox'+page);

		if ( $next.length == 0) $next =  $('#scrollcontainer span:first'); 

		$(".scrollpage span").removeClass("pageactive");
		$(".scrollpage #page"+page).addClass("pageactive");

		$active.removeClass('active');	
		$next.css({opacity: 0.0});
		$next.addClass('active');
		$next.animate({opacity: 1.0}, 750);
	}
	
	function nextSlide() {
    var $active = $('#scrollcontainer span.active');
	  var $next = $active.next();
		
		if ( $next.length == 0) $next =  $('#scrollcontainer span:first'); 

		var page = $next.attr("pg");
		$(".scrollpage span").removeClass("pageactive");
		$(".scrollpage #page"+page).addClass("pageactive");

		$active.removeClass('active');	
		$next.css({opacity: 0.0});
		$next.addClass('active');
		$next.animate({opacity: 1.0}, 750);
	}

	function prevSlide() {
    var $active = $('#scrollcontainer span.active');
	  var $prev = $active.prev();
		
		if ( $prev.length == 0) $prev =  $('#scrollcontainer span:last'); 

		var page = $prev.attr("pg");
		$(".scrollpage span").removeClass("pageactive");
		$(".scrollpage #page"+page).addClass("pageactive");

		$active.removeClass('active');	
		$prev.css({opacity: 0.0});
		$prev.addClass('active');
		$prev.animate({opacity: 1.0}, 750);
	}

	$(function() {
			clientintervalid = setInterval( "nextSlide()", 9500 );
	});
