function HomePage() { }

HomePage.FeaturedContainer = null;
HomePage.FeaturePanels = Array();
HomePage.currentPanelInCycle = 0;
HomePage.listItems = null;

HomePage.cycleTimer = null;

HomePage.init = function() {

	HomePage.FeaturedContainer = $("div#features");

	var panels = $('div.feature', HomePage.FeaturedContainer);
	$.each(panels, function(panel) {
		HomePage.FeaturePanels.push($(this));
	});
	
	HomePage.listItems = $('ul.features li');
	HomePage.listItems.click(function() {
		// console.log(this.className);
		HomePage.currentPanelInCycle = this.className;
		clearTimeout(HomePage.cycleTimer);
		HomePage.cycle();
	});

	HomePage.cycle();
}

HomePage.cycle = function() {
	var index = HomePage.currentPanelInCycle;
	if (index == HomePage.FeaturePanels.length) {
		HomePage.currentPanelInCycle = 0;
	}
	HomePage.select(HomePage.currentPanelInCycle++);
	HomePage.cycleTimer = setTimeout("HomePage.cycle()", 5000);
}

HomePage.findPanel = function(order) {
	return $("div.feature", HomePage.FeaturedContainer).eq(order -1);
}

HomePage.showPanel = function(panel) {

	var featurePanels = $("div.feature", HomePage.FeaturedContainer);

	featurePanels.fadeOut();

	// console.log(panel);
	panel.fadeIn();
	
}

HomePage.prepareLinks = function() {

	var li = $("li", HomePage.FeaturedContainer);

	var i = 1;

	$.each(li, function(listItem) {

		var container = HomePage.findPanel(i);

		this.onclick = function() { 
			HomePage.select(container, li, $(this));
		};
		
		i++;

		
	});

}

HomePage.select = function(index) {
	HomePage.showPanel(HomePage.FeaturePanels[index]);	
	$(HomePage.listItems).removeClass('active');
	$(HomePage.listItems[index]).addClass('active');
}

$(document).ready(function() {
	HomePage.init();
});
