self.moveTo(0,0);
self.resizeTo(screen.availWidth,screen.availHeight);
$(document).ready(function(){
	$('#contactForm').submit(function(){
		$('#contactForm #loading').show();
		var action = $(this).attr('action');
		$("#feedback").slideUp(750,function() {
		$('#feedback').hide();
		$('#submit').attr('disabled','disabled');
 
		$.post(action, { 
			name: $('#name').val(),
			email: $('#email').val(),
			phone: $('#phone').val(),
			referrer: $('#referrer').val(),
			appointment: $('#appointment').val(),
			visitDate: $('#visitDate').val(),
			message: $('#message').val()
		},
			function(data){
				$('#submit').removeAttr('disabled');
				document.getElementById('feedback').innerHTML = data;
				$('#feedback').slideDown('slow');
				$('#contactForm #loading').hide();
				if(data.indexOf('Thanks') > 0){$('#contactForm').clearForm();}
			}
		);

		});
		return false;
 
	});
	$('#datepicker').datepicker({altField: '#visitDate'});

// The below function repeatedly gets called, to do the rotating
function show_next_randomQuote(t){
	$(t).fadeOut('slow');
 
	var next_randomQuote = $(t).siblings('.randomQuote:random');
	if(!next_randomQuote.attr('class')){
		next_randomQuote = $('#randomQuotes li.randomQuote:first');
	}
	next_randomQuote.fadeIn('slow');
 
	showing = next_randomQuote;	
}

	showing = $('#randomQuotes li.randomQuote:first'); // Initiate the 'showing' variable as the first rotating_item
	showing.siblings('li').hide(); // Hide all other rotating_items
	setInterval("show_next_randomQuote(showing)", 12000); // Set the rotate time to 12 seconds
	
	$("#homeSlider").loopedSlider({
		autoStart: 10000,
		restart: 15000,
		containerClick: false
	});

	$("#smileGallery").loopedSlider({
		autoStart: 10000,
		restart: 15000,
		containerClick: false
	});

    $("#officeTour").flash(
        { 
          src: 'slideshow.swf',
          width: 660,
          height: 440
        },
        {version: 8}
    );
	isOpenPreview();
	$("a[href^='http:']:not([href*='" + window.location.host + "'][target='_blank'])").live('click', function(){$(this).attr('target','_blank');});
	$("img" && !".slidesContainer").lazyload();
});

// Below is the code that picks an item at random to display
$.jQueryRandom = 0;  
$.extend($.expr[":"],  
{  
    random: function(a, i, m, r) {  
        if (i === 0) {  
            $.jQueryRandom = Math.floor(Math.random() * r.length);  
        } 
        return i == $.jQueryRandom;  
    }  
}); 
 


$.fn.clearForm = function() {
  return this.each(function() {
 var type = this.type, tag = this.tagName.toLowerCase();
 if (tag == 'form'){
   return $(':input',this).clearForm();}
 if (type == 'text' || type == 'password' || tag == 'textarea'){
   this.value = '';}
 else if (type == 'checkbox' || type == 'radio'){
   this.checked = false;}
 else if (tag == 'select'){
   this.selectedIndex = -1;}
  });
};

this.isOpenPreview = function(){	
	/* CONFIG */
		
		xOffset = -10;
		yOffset = -200;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.isOpen").hover(function(e){
		this.t = this.title;
		this.title = "";	
		/* var c = (this.t != "") ? "<br/>" + this.t : ""; */
		$("body").append("<div id='isOpen'><img src='./images/closed.gif' alt='we are closed' ></div>");								 
		$("#isOpen")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("slow");						
    },
	function(){
		this.title = this.t;	
		$("#isOpen").remove();
    });	
	$("a.isOpen").mousemove(function(e){
		$("#isOpen")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};
