$(window).load(function(){
	if ($('#heroBox').length) {
		setTimeout('showNextHero()', 5000);
	}

	// homepage Features
	if ($('#featuresBox').size()) {
		$('#featuresBox .featuresNext').click(function(){
			var $current = ($('#featuresBox li.active'));
			var $next = $current.next();
			if (!$next.length) $next = $('#featuresBox li:first');
			
			$next.fadeIn('slow');		
			$next.addClass('active');
			$current.hide();
			$current.removeClass('active')
			
			$('#featuresItem' + ($('#featuresBox li').index($next)+1) ).addClass('active');
			$('#featuresItem' + ($('#featuresBox li').index($current)+1) ).removeClass('active');
		});	
		$('#featuresBox .featuresNext').click();
		
		$('#featuresBox .featuresPrev').click(function(){
			var $current = ($('#featuresBox li.active'));
			var $next = $current.prev();
			if (!$next.length) $next = $('#featuresBox li:last');
			
			$next.fadeIn('slow');		
			$next.addClass('active');
			$current.hide();
			$current.removeClass('active')

			$('#featuresItem' + ($('#featuresBox li').index($next)+1) ).addClass('active');
			$('#featuresItem' + ($('#featuresBox li').index($current)+1) ).removeClass('active');			
		});		

		$('#featuresBox .featuresItem').click(function(){
			var $current = ($('#featuresBox li.active'));
			var iClickedIndex = ($('#featuresNav div').index($(this)));
			var $next = $('#featuresBox').find('li:eq(' + (iClickedIndex-1) + ')');
			
			$next.fadeIn('slow');		
			$next.addClass('active');
			$current.hide();
			$current.removeClass('active')

			$(this).addClass('active');
			$('#featuresItem' + ($('#featuresBox li').index($current)+1) ).removeClass('active');			
		});	
				
       

		
	}
		
});

function showNextHero() {
	var $top = $('#heroBox');
	var $current = $top.find('div.on');
	var $next = $current.prev();
	if (!$next.length) $next = $('#heroBox').find('div:last');

	$next.addClass('on');
	$current.animate(
		{opacity:0.0},
		2000,
		function() {
			$current.removeClass('on');
			$top.remove($current);
			$current.css( {opacity:1.0} )
			$top.prepend($current);
		}
	);
	setTimeout('showNextHero()', 5000);
}
