$(document).ready(function() {                

	// email protector
	$("span.mailto").each(function(){
		exp = $(this).text().search(/\((.*?)\)/) != -1 ? new RegExp(/(.*?) \((.*?)\)/) : new RegExp(/.*/);
		match = exp.exec($(this).text());
		addr = match[1] ? match[1].replace(/ at /,"@").replace(/ dot /g,".") : match[0].replace(/ at /,"@").replace(/ dot /g,".");
		link = match[2] ? match[2] : addr;
		subject = $(this).attr('title') ? "?subject="+$(this).attr('title').replace(/ /g,"%20") : "";
		$(this).after('<a href="mailto:'+addr+subject+'">'+ link + '</a>');
		$(this).remove();
	});    
	
	// Open links in new window when rel="external" is applyed to a tag
	$('a[rel="external"]').click(function(){
		this.target = "_blank";
	});

  
  //validation
  $("#contact-form").validate();
  $("#appraisal-form").validate();
  //cycle banner
    $('body#house-page ul#houses').cycle({
      fx: 'fade',
      timeout:5000,
      pause: 1,
      speed: 600,
      next:   'a.forward', 
      prev:   'a.back'
    });
    
    $('body#home-page ul#houses, body#testimonials-page ul#houses').cycle({
      fx: 'fade',
      timeout:5000,
      pause: 1,
      speed: 600,
      before:  onBefore, 
      after:   onAfter
    });
    function onAfter() { 
      $(this).find('.house_information').stop().animate({bottom:'0', opacity:'1'},{queue:true,duration:300});
    };
    function onBefore() {
      $(this).find('.house_information').stop().animate({bottom:'-80px', opacity:'.2'},{queue:true,duration:300});
    };
    
    
    $('#free_market_appraisal a').click(function() { 
      $.blockUI({ css: { 
          border: 'none', 
          padding: '15px',
					top: '5%',
          backgroundColor: '#000', 
          '-webkit-border-radius': '10px', 
          '-moz-border-radius': '10px', 
          opacity: .8,
          color: '#fff',
          width: '400px',
          height: '500px'
      },
      message: $('#free_market_appraisal_form')
      
       });
       $('.blockOverlay').attr('title','Click to Close').click($.unblockUI);
    });    
    
    
    $('#join_our_mailing_list a').click(function() { 
      $.blockUI({ css: { 
          border: 'none', 
          padding: '15px',
					top: '0',
          backgroundColor: '#000', 
          '-webkit-border-radius': '10px', 
          '-moz-border-radius': '10px', 
          opacity: .8,
          color: '#fff',
          width: '400px',
          height: '450px'
      },
      message: $('#mailing_list_form')
      
       });
       $('.blockOverlay').attr('title','Click to Close').click($.unblockUI);
    });
  
});