var lastCategory;

$(document).ready(function() {
	
	$("header nav a").click(function() {
			$("header nav a.active").removeClass("active");
			$("body").attr("id", "");
			$(this).addClass("active");	
	});	
	
	$("a.sublink").click(function() {
	
		$("a.sublink.active").removeClass("active");
		$(this).addClass("active");
	
		$("#content").html($("#subcontent-"+$(this).attr("data-id")).html());
		
		return false;
	});
	
	$("a.button").hover(function() {
		$(this).stop().animate({backgroundPosition:"(0 -14px)"}, {duration: 700});
		
	});
	
	
	setInterval(slideSwitch, 1500);
	
	

});




function slideSwitch()
{
	
	do 
	{	
		randomCategory = $(".work-category").get().sort(function(){ 
		  return Math.round(Math.random())-0.1
		}).slice(0,1)
	} while(randomCategory == lastCategory)

	lastCategory = randomCategory;

	var $category = $(randomCategory);
	var $active = $category.find("div.active");
    var $next =  $active.next().length ? $active.next() : $category.find("div:first");
	
    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1200, function() {
            $active.removeClass('active last-active');
        });


}



