/* ====================
   DATA
=====================*/

//thumbs
var thumbs = [
	'images/new_homes/mil_homes/carousel/orrock.jpg', 	
	'images/new_homes/mil_homes/carousel/dunson.jpg',	
	'images/new_homes/mil_homes/carousel/FisherSankhla.jpg', 
	'images/new_homes/mil_homes/carousel/Reagans.jpg',
	'images/new_homes/mil_homes/carousel/img3.jpg',
	'images/new_homes/mil_homes/carousel/blank.png',
	'images/new_homes/mil_homes/carousel/blank.png'
];

//headings
var names = [
	"The Orrock Family &#8226; Las Vegas, NV &#8226; KB Homes",		 
	"The Dunson Family &#8226; Victorville, CA &#8226; KB Homes",	
	"Leona Fisher and Will Sankhla &#8226; Southern California &#8226; KB Home",
	"The Reagan Family &#8226; Cottage Grove, MN &#8226; K. Hovnanian",
	"Ryan and Melanie Miller &#8226; Salt Lake City, Utah &#8226; Gold Medallion Homes",
	"Costa Family &#8226; Dallas, TX &#8226; KB Homes",	
	"The Trial Family &#8226; Dallas, TX &#8226; Braselton Homes"
];	 

//stories
var info = [
	"Being natives of Las Vegas, we know first-hand the importance of energy conservation, which is why we wanted to purchase an ENERGY STAR qualified home. During the last year, we have noticed substantial savings, not only in our utility bills, but in our overall energy consumption. This is due to the added benefits of having ENERGY STAR appliances, effective insulation, and high performance, energy-efficient windows throughout our house.  Going Green comes down to individual commitment and willingness to change our current routines. We truly appreciate the positive impact our ENERGY STAR home and community have on the planet.",
	"This has been a milestone year for our family as we decided to buy a new home at the beginning of the year. After living in our previous home for over four years and thus becoming accustomed to high utility bills, we were excited for the opportunity to buy a brand new ENERGY STAR qualified home as our first family home. Our utility bills are half of what they were in the previous home even though we have an additional five hundred square feet in our new home. I cannot say enough about how wonderful it is to be doing our part for a better tomorrow!",
	"We've always been impressed with the savings we've gotten from ENERGY STAR CFLs and appliances, so we knew that ENERGY STAR would be a smart choice for our first home too. But it's not just about the savings. When researching builders, we liked that KB Home was such a progressive builder. They really build with cutting-edge technology, and the environment in mind. Protecting the environment is important to us too &#8212; and ENERGY STAR gives us one more way to be part of the solution.",
	"We love the style, feel and location of our new home. It's a Parade of Homes showcase home from K. Hovnanian.  We liked everything that we learned about the home.  When we learned it was an ENERGY STAR home, it was the icing on the cake.  Saving money is what did it for us.  We doubled the size of our home, but our energy bills were comparable. Plus, the temperature throughout the house is consistent so we're always comfortable.",
	"During the summer it definitely stays cooler. ENERGY STAR is exactly why we aren't losing air anywhere. You get a tight seal around your house that keeps the cool air in and hot air out.",
	"I grew up being conscientious of the importance of energy efficiency. When it came time to buy a home, I made sure I did my research because I knew the savings involved with energy efficiency. I started out looking at pre-owned homes and quickly became very discouraged.  I then discovered the benefits of an ENERGY STAR home and it has made a significant difference for me - I love our new home!  There is a sense of well-being in knowing that we have a safe, energy-efficient home that we can live in for years. Also, my first electric bill was  extremely low - we love the savings! We are so thrilled with our final decision and love our ENERGY STAR home.",
	"For the past nine years I've lived in an apartment so moving into a new home was quite a thrill - a yard, an office, a large bathroom, I could go on and on. However, one thing impressed me more than most. My house is an ENERGY STAR qualified house. Going from a 600 square foot apartment to a 2,000 square foot home, I expected at least a 30% increase in my electric bill, but I was wrong. When I opened my first bill I was shocked at how low my bill was! As the months went by I noticed my electric bill stayed consistently low. The air conditioning keeps the house extremely comfortable and my attic stays amazingly cool during the summer. I would definitely recommend an ENERGY STAR house to anyone that I know."
];

/* ====================
	EVENT HANDLERS
=====================*/
	
function showStory(s) {
		//get info container
		var parent = YAHOO.util.Dom.get("information");
		
		//remove child elements if present
		(parent.hasChildNodes() != true) ? null : removeChildren();
		
		function removeChildren() {
			var children = YAHOO.util.Dom.getChildren("information");
			for(prop in children) {
				parent.removeChild(children[prop]);
			}
		}

		//create new heading and paragraph
		var heading = document.createElement("h2");
		var p = document.createElement("p");
		 
		//add text to new elements
		heading.innerHTML = names[s];
		p.innerHTML = info[s];			 
	
		//add new elements to page
		parent.appendChild(heading);
		parent.appendChild(p);
}

/* ====================
   INITIALIZATION
=====================*/

function init() {

	//remove the stories link
	 var showStoriesLink = YAHOO.util.Dom.get("showStoriesLink");
	 YAHOO.util.Dom.addClass(showStoriesLink, "hide_left");
	
	//build the carousel	
	var carousel= new YAHOO.widget.Carousel("container", {
			 animation: { speed: 0.5 },
			 numVisible: 4,
			 navigation: { prev: "prevBtn", next: "nextBtn" }
	});
	for (i=0; i<thumbs.length; i++) {
		var test = carousel.addItem('<img alt="" width="101" height="76" src="' + thumbs[i] + '" />');
	}

	carousel.render();
	carousel.show();
	
	/* progressive enhancement version	
	var carousel = new YAHOO.widget.Carousel("container", {
		 animation: { speed: 0.5 },
		 numVisible: 4,
		 navigation: { prev: "prevBtn", next: "nextBtn" }
	}); */

	//createdisplay selected image info
	carousel.on("itemSelected", function(i) {
		showStory(i);
	});
	

	//show the carousel
	//carousel.render();
	//carousel.show();
	
	//show the first story
	showStory(0);
 }
YAHOO.util.Event.onDOMReady(init);