//Banner slideshow 
function bannerFade(){
	
	if ($('.last_image').is(':visible')){
		$(".current_image").delay(4000).fadeOut(500, function() {
			$(".first_image").addClass("current_image");
			$(this).removeClass("current_image");
			$(".first_image").fadeIn(500, function() {
				//Fixes IE's clear-type issue on animated fonts
				if(jQuery.browser.msie) this.style.removeAttribute('filter');
				bannerFade();
			});
		});
	} else {
		$(".current_image").delay(4000).fadeOut(500, function() {
			$(this).next().addClass("current_image");
			$(this).removeClass("current_image").next().fadeIn(500, function() {
				//Fixes IE's clear-type issue on animated fonts
				if(jQuery.browser.msie) this.style.removeAttribute('filter');
				bannerFade();
			});
		});
	};
};

//Text slideshow
function textFade(){
	
	if ($('.last_text').is(':visible')){
		$(".current_text").delay(5000).fadeOut(500, function() {
			$(".first_text").addClass("current_text");
			$(this).removeClass("current_text");
			$(".first_text").fadeIn(500, function() {
				//Fixes IE's clear-type issue on animated fonts
				if(jQuery.browser.msie) this.style.removeAttribute('filter');
				textFade();
			});
		});
	} else {
		$(".current_text").delay(5000).fadeOut(500, function() {
			$(this).next().addClass("current_text");
			$(this).removeClass("current_text").next().fadeIn(500, function() {
				//Fixes IE's clear-type issue on animated fonts
				if(jQuery.browser.msie) this.style.removeAttribute('filter');
				textFade();
			});
		});
	};
};

//Corner slideshow 
function cornerFade(){
	
	if ($('.last_image').is(':visible')){
		$(".current_corner").delay(2000).fadeOut(250, function() {
			$(".first_corner").addClass("current_corner");
			$(this).removeClass("current_corner");
			$(".first_corner").fadeIn(200, function() {
				//Fixes IE's clear-type issue on animated fonts
				if(jQuery.browser.msie) this.style.removeAttribute('filter');
				cornerFade();
			});
		});
	} else {
		$(".current_corner").delay(2000).fadeOut(250, function() {
			$(this).next().addClass("current_corner");
			$(this).removeClass("current_corner").next().fadeIn(200, function() {
				//Fixes IE's clear-type issue on animated fonts
				if(jQuery.browser.msie) this.style.removeAttribute('filter');
				cornerFade();
			});
		});
	};
};


//Handler for executing functions
$(document).ready(function(){
	
	$(".banner img, .show-homes-banner img").first().addClass("current_image first_image");
	$(".banner img, .show-homes-banner img").last().addClass("last_image");
	
	bannerFade();
	
	$("#gold_bar h1").first().addClass("current_text first_text");
	$("#gold_bar h1").last().addClass("last_text");
	
	textFade();

	$("#stampede_corner img").first().addClass("current_corner first_corner");
	$("#stampede_corner img").last().addClass("last_corner");
	
	cornerFade();

	
	//Where We Build Map Markers Hover
	$("#cat_1161680_divs li").hover(

        function () {
	
			var hovertext = $(this).children("a").text();
		
			$(this).append("<p class='hovertext'><strong>"+ hovertext +"</strong><span></span></p>");
        	
            $(this).children(".hovertext").fadeIn("fast", function() {
		    	//Fixes IE's clear-type issue on animated fonts
		    	if(jQuery.browser.msie) this.style.removeAttribute('filter');
		    }).css("visibility","visible");
		    
		    $(this).siblings().children(".hovertext").fadeOut("fast");
		    
        }, 
        function () {
        
            $(this).children(".hovertext").fadeOut("fast");
            
        }

    );
	
	//Testimonials functions
	$(".testimonial_containers .inner, .testimonials_read_less").css({'display' : 'none'});
	
	$(".testimonials_read_more").click(function(){

		var target = $(this).attr("href") + " .inner";
		
		$(target).animate({
			height: 'toggle'
		  }, 600, function() {
			// Animation complete.
		});
		
		$(this).fadeOut(300, function() {
			$(this).siblings(".testimonials_read_less").fadeIn(300);
		});
		
		return false;
		
	});
	
	$(".testimonials_read_less").click(function(){

		var target = $(this).attr("href") + " .inner";
		
		$(target).animate({
			height: 'toggle'
		  }, 600, function() {
			// Animation complete.
		});
		
		$(this).fadeOut(300, function() {
			$(this).siblings(".testimonials_read_more").fadeIn(300);
		});
		
		return false;
		
	});
	
});
