$(function() { 
	
	var currentText = 1;
	var currentPic = 0;
	var fadeTransition = "slow";
	var clickInProgress = false;
		var testimonialArray = [
		{id: '0', who:'Lance Wayne and Shay Reichert', testimonial: '\"We used Casa Bella Homes to build our dream home in 2007.  It was our first experience with a custom builder.  We loved every moment of it!\"' },

		{id: '1', who:'continued...', testimonial: '\"One of our first encounters with Brady was on a jobsite as he maintained a watchful eye on the construction of another custom built home. We quickly learned that was the Behrens way, thoughtful oversight, vast experience, and true enjoyment of the construction process...\"' },
		{id: '2', who:'Mark/Cindy,  Georgetown', testimonial: '\"...turns out, our project received that same special attention along with a generous helping of humor. We are proud to tell friends and family we have a Casa Bella Home. Thanks for using the big nails.\"' },

{id: '3', who:'Lance Wayne and Shay Reichert', testimonial: '\"We got a no-nonsense price for the construction, and excellent advice to help finish it out.  Brady Behrens and his wife, Jan, have become a part of our family.  We still talk to this day, and Brady is our first call if we need to add or fix anything on the house.\"' },

{id: '4', who:'Felix and Lori Munson, New Custom Homeowner', testimonial: '\"Working with Casa Bella Homes was a real pleasure. Brady\'s attention to detail is unsurpassed. He always did what he said he would do in a timely manner. We would highly recommend Casa Bella Homes to anyone for their next home building project – ours went so smoothly and with little stress.\"' },

{id: '5', who:'Roland Swenson and Roseana Auten', testimonial: '\"Brady Behrens is an amazingly resourceful, patient and honest man.  The process of building or remodeling your home is a journey, so you had best be traveling with someone you like and trust.  Brady and his crew were those companions for us.\"' },




	];

	var picturesArray = [
		{id: '0', src: 'http://www.casabellahomesonline.com/wp-content/themes/CasaBella/images/landingPic1.jpg' },
		{id: '1', src: 'http://www.casabellahomesonline.com/wp-content/themes/CasaBella/images/landingPic2.jpg' },
		{id: '2', src: 'http://www.casabellahomesonline.com/wp-content/themes/CasaBella/images/landingPic3.jpg' },
		{id: '3', src: 'http://www.casabellahomesonline.com/wp-content/themes/CasaBella/images/landingPic4.jpg' }

	];
	
	var prevPic = picturesArray.length;
	
	
	$(".testimonial").fadeOut("slow", function() { 
		$(".testimonial .text").text(testimonialArray[0].testimonial);
		$(".testimonial .delimSep").text("- ");
		$(".testimonial .who").text(testimonialArray[0].who);
		$(".testimonial").fadeIn("slow");
	});
	
	function updateText() { 
		$(".testimonial").fadeOut("fast", function() { 
			$(".testimonial .text").text(testimonialArray[currentText].testimonial);
			$(".testimonial .delimSep").text("- ");
			$(".testimonial .who").text(testimonialArray[currentText].who);
			$(".testimonial").fadeIn("slow");
			if(currentText==testimonialArray.length-1) { 
				currentText=0;
			} else { 
				currentText=currentText+1;
			}
		});		
	};

	function fadeNow() { 
		$(".landingImg").fadeIn(fadeTransition, function() { 		
			clickInProgress=false;
		});
	};	
	
	function fadeBg() { 	
		$(".landingImg").fadeOut(fadeTransition, function() { 				
			$(".landingImg").attr("src",picturesArray[currentPic].src).load(fadeNow);				
		});				
	};
	
	function updatePic() { 	
		if(currentPic==picturesArray.length-1) { 
			currentPic=0;
		} else { 
			currentPic=currentPic+1;
		}	
		fadeTransition = "slow";
		$(".imageContainer").css("backgroundImage","url("+picturesArray[currentPic].src+")");	
		
		fadeBg();
	
	};
	
	$(".nextBtn").click(function() { 
		if(!clickInProgress) { 
			clickInProgress=true;
			$(".landingImg").stopTime("updatePictures");
			if(currentPic==(picturesArray.length-1)) { 		
				currentPic=0;
				$(".imageContainer").css("backgroundImage","url("+picturesArray[currentPic].src+")");		
				
			} else { 
				currentPic=currentPic+1;
				$(".imageContainer").css("backgroundImage","url("+picturesArray[currentPic].src+")");		
			    
			}		
			fadeTransition = "slow";
			fadeBg();
			$(".landingImg").everyTime(10000, "updatePictures", function() { 
				updatePic();		
			});			
		}
		return false;
	});
	
	$(".prevBtn").click(function() { 
		if(!clickInProgress) { 
			clickInProgress=true;
			$(".landingImg").stopTime("updatePictures");		
			if(currentPic==0) { 	
				currentPic=picturesArray.length-1;			
				$(".imageContainer").css("backgroundImage","url("+picturesArray[picturesArray.length-1].src+")");
				
			} else { 
				currentPic=currentPic-1;
				$(".imageContainer").css("backgroundImage","url("+picturesArray[currentPic].src+")");				
			}	
			fadeTransition = "slow";
			fadeBg();
			$(".landingImg").everyTime(10000, "updatePictures", function() { 
				updatePic();		
			});				
			
		}
		return false;
	});
	
	$(".tabber li a").click(function() {	
		var linkClicked = $(this).attr("href");
		tabber(".tabber",linkClicked);
		$(this).parent("li").addClass("active");
		return false;
	});	  
	
	function tabber(where,what) { 			
		var activeLink = $(".tabber").find("li.active a").attr("href");
		$(where).find("li.active").removeClass("active");
		$(activeLink).hide();
		$(what).show();						
	};
	
	$(".landingImg").everyTime(6000, "updatePictures", function() { 
		updatePic();		
	});	
	
	$(".testimonial").everyTime(10000, "updateTestimonials", function() { 
		updateText();		
	});	
	
	$(function() {
		$('#gallery_images a').lightBox();
	});
		
});