
// image pre-loader function 
jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}
	

$(document).ready(function () {
							
	
	$("#locations").change(function () {
          window.location.href = $("#locations option:selected").val();
    });
    $("#services").change(function () {
          window.location.href = $("#services option:selected").val();
    });
    $("#physicians").change(function () {
          window.location.href = $("#physicians option:selected").val();
    });
	
	
	// Pre-load some images on the page
	/*
	$.preloadImages(
		"/img/homepage.doctor.2.jpg", 
		"/img/homepage.doctor.3.jpg",
		"/img/homepage.doctor.4.jpg",
		"/img/homepage.doctor.5.jpg"
	);
	*/ 
	
	
	// Timer for rotating the homepage mast text
	
	var counter1 = 1;
	
	$.fn.textRotator = function() {

		$(".intro-text").fadeOut("slow");
		
		counter1++;
		if (counter1 > $(".intro-text").length) {
			counter1 = 1;
		}
		// alert(counter1);
		$("#intro-text-" + counter1).fadeIn("slow");
		setTimeout('$(document).textRotator();', 20000);
	};
	
	setTimeout('$(document).textRotator();', 20000);
	
	
	// next text link 
	$(".next-text-link").click( function() {
		delete timer1;
		visible = $(".intro-text:visible").attr('id').replace('intro-text-','');
		next = parseInt(visible)+1;
		if (next > $(".intro-text").length) {
			next = 1;
		}
		$(".intro-text").fadeOut("slow");
		$("#intro-text-" + next).fadeIn("slow");
		counter1 = next;
	});

	
	// Timer for rotating the homepage mast images
	
	var timer2;
	
	$.fn.imageRotator = function(starter) {
		
		timer2 = setTimeout( function() {
			
			$(".mast-image").fadeOut("slow");
			
			var next = starter + 1;
			if (next > $(".mast-image").length) {
				next = 1;
			}
				
			$("#mast-image-" + next).fadeIn("slow");
			$(document).imageRotator(next);
			
		}, 10000);
	};
	
	$(document).imageRotator(1);
	
	
	
	
	
	/*
	var timer;
						   		
	$.fn.featureRotator = function(starter) {
		timer = setTimeout( function() {
			
			$(".intro-img").fadeOut("slow");
			$(".intro-text").fadeOut("slow");
			
			var next = starter + 1;
			if (next > $(".intro-img").length) {
				next = 1;
			}
			
			$("#intro-text-" + next).fadeIn("slow");
			$("#intro-img-" + next).fadeIn("slow");
			$(document).featureRotator(next);
		}, 20000);
	};
	*/
});

