// JavaScript Document
var fadebox = "<div class='FadeFrame' id='FadeFrame'>Loading...<br />Please Wait...<br /><img src='/homelife/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='/homelife/images/loading1.gif' height='32' width='32' alt='Loading' border='0' /></div>";


jQuery(document).ready(function(){


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


  jQuery(".prevclientslide").click(function(){
		clearInterval(clientintervalid);																		 
		jQuery("#lblautoscroll").fadeOut("normal");
		prevSlide();																 
  });
	
	jQuery(".scrollpagejump").click(function(){
		clearInterval(clientintervalid);	
		jQuery("#lblautoscroll").fadeOut("normal");
		var pagenum = jQuery(this).attr("pg");
		slideJump(pagenum);																 
  });
	
	function submit_contact_form(){
		jQuery(fadesendbox).appendTo("#ContactForm");
		jQuery("#ContactForm").fadeTo(1000, 1, function() {		
			jQuery.post("/homelife/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 objBeds =document.getElementById("cboLSBeds")
		var objBath =document.getElementById("cboLSBaths")

		objBeds.selectedIndex = 0;
		objBath.selectedIndex = 0;

		jQuery("#optListType0").attr("checked","checked");		
		jQuery("#txtLSPriceMin").attr("value","");
		jQuery("#txtLSPriceMax").attr("value","");
		jQuery("#txtLSMLSNum").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.2, function() {		
			jQuery.post("/homelife/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 = '/homelife/include/popmap.php?id='+propertyid+'&link='+linkid+'&rent='+rentalid;
	}
	else {
		mapwindow=window.open('/homelife/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 = '/homelife/gallery.php?id='+propertyid+'&rent='+rentalid;
	}
	else {
		gallwindow=window.open('/homelife/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 = jQuery('#scrollcontainer span.active');
		//var page = jQuery(this).attr("pg");
	  var $next = jQuery('#scrollbox'+page);

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

		//jQuery(".scrollpage span").removeClass("pageactive");
		//jQuery(".scrollpage #page"+page).addClass("pageactive");
		jQuery("#boxSlideCount").html(page+" of 10");

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

		var page = $next.attr("pg");
		//jQuery(".scrollpage span").removeClass("pageactive");
		//jQuery(".scrollpage #page"+page).addClass("pageactive");
		jQuery("#boxSlideCount").html(page+" of 10");
		
		$active.removeClass('active');	
		$next.css({opacity: 0.0});
		$next.addClass('active');
		$next.animate({opacity: 1.0}, 750);
	}

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

		var page = $prev.attr("pg");
//		jQuery(".scrollpage span").removeClass("pageactive");
		//jQuery(".scrollpage #page"+page).addClass("pageactive");
		jQuery("#boxSlideCount").html(page+" of 10");

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

	jQuery(function() {
			clientintervalid = setInterval( "nextSlide()", 8500 );
	});
	
	function stop_slideshow() {
		clearInterval(clientintervalid);	
		jQuery("#boxSlideCount").html("stop");	
	}	
	function start_slideshow() {
		clientintervalid = setInterval( "nextSlide()", 8500 );	
		nextSlide();	
	}
