// Homepage slide switcher

$(document).ready(function() {

	$(function () {
	    var tabContainers = $('div#imgSwapper > div');
	    
	    $('div#imgSwapper ul a').click(function () {
	        tabContainers.hide().filter(this.hash).show();
	        
	        $('div#imgSwapper ul a').removeClass('switchActive');
	        $(this).addClass('switchActive');
	        
	        return false;
	    }).filter(':first').click();
	});
	
	
	setInterval(function(){ChangeSlide();}, 5000);
	                       
	function ChangeSlide()
	{

		var currentElem = $('div#imgSwapper ul a.switchActive');
		var currentHref = currentElem.attr('href');
		var currentIndex = parseInt(currentHref.substring(10,11));
		var tabContainers = $('div#imgSwapper > div');
		
		if(currentIndex == 4)
		{
			next = 1
		}
		else
		{
			next = currentIndex + 1;
		}
		
		var nextElem = $('div#imgSwapper > div#homePanel'+next);
		var nextLink = $('a[href=#homePanel'+next+']');
		
		// Set all panels to hide
		tabContainers.hide();
		nextElem.show();
		
		// Remove the active class from all links
		$('div#imgSwapper ul a').removeClass('switchActive');
		nextLink.addClass('switchActive');
		
	}
	

});
