/*
	Simple jQuery Slider
	Author - @xphree - jduquej@intergrupo.com.
*/
$(document).ready( function() {
	
	// Config

	// Duration in ms
	var duration = 8000; // 8 seconds
	var animate = false; 

	// Hide all but first
	$("#tool02").hide();
	$("#tool03").hide();
	$("#tool04").hide();
	$("#tool05").hide();
	$("#tool06").hide();
	
	// TOP BANNER
	$('.thumbLink').click( function(e) {
		e.preventDefault();
		
		// We get the content id to show
		var href = $(this).attr("href");
		
		var content = $(href);

		showContent(content);

		// We change the state of the button
		var current = getCurrent();
		current.removeClass("active");
		$(this).addClass("active")

	});
	
	
	// SHOW TOP CONTENT
	function showContent(content) {
		var current = getCurrent();	
		var currentContent = $(current.attr("href"));	
		
		// Hide the current content
		currentContent.hide();
	
		// Fade in the new content
		content.fadeIn();	
	}

	
	// GET TOP CURRENT 
	function getCurrent() {
		return $(".active");
	}
	
	
	// GET TOP NEXT
	function getNext() {
		var current = getCurrent();
		var next = null;

		// If we dont have the next, we get the first one	
		if(!current.parent().next().length) {
			next = $('.thumbs a:first-child').children("a");
		} else {
			next = current.parent().next().children("a");
		}
		
		return next;
	}

	
	// Animation
	if(animate) {
		// Top Animation
		setInterval(function() {
			var current = getCurrent();
			var next = getNext();
		
			showContent($(next.attr("href")));
		
			current.removeClass("active");
			next.addClass("active");
		}, duration);
	}
});

