var tooltipTimer, tooltipCache, sliderTimer;

//Domready
$(document).ready(function(){
	
	//Tabs behaviour
	$('#tabs li a').each(function(i){
		$(this).click(function(e){
			if($(this).attr("href") == "#"){
				e.preventDefault();
				$('#submenu').animate({height: "56px"}, 300);
				$('#tabs li a').removeClass('active');
				$(this).addClass("active");
				$('#submenu div.wrap ul').fadeOut("fast");
				$('#submenu div.wrap').children().eq(i).fadeIn("fast");
			}
		});
	});
	
	
	//Tooltips
	$(".hasTooltip").each(function(i){
		$(this).hover(
			function(e){
				$().mousemove(function(e){
					$("#tooltip").css({'top' : e.pageY - $("#tooltip").height() - 20  + 'px', 'left' : e.pageX + 'px'});
				});
				
				tooltipCache = $(this).attr('title');
				
				$("#tooltip span.text").html(tooltipCache);
				$(this).attr('title', '');
				$("#tooltip").show();
				clearTimeout(tooltipTimer);
			},
			
			function(){
				$(this).attr('title', tooltipCache);
				tooltipTimer = setTimeout(function(){$("#tooltip").hide()}, 150);
			}
		);
	});
	
	//Slider
	var pages = $('#showcase ul li').length;
	var page = 1;
	var pageWidth = 915;
	
	$('#slider-controls').hover(function(){
		clearInterval(sliderTimer);
	});
	
	$('#slider-controls a.prev').click(function(e){
		e.preventDefault();
		
		if(page > 1) {
			$('#showcase ul').animate({left: "+=" + pageWidth}, 500, 'swing');
			page --;
			//$('#counter').html(page + "/" + pages);
		}
	});	
	
	$('#slider-controls a.next').click(function(e){
		e.preventDefault();
		
		if(page < pages) {
			$('#showcase ul').animate({left: "-=" + pageWidth}, 500, 'swing');
			page ++;
			//$('#counter').html(page + "/" + pages);
		}
	});
	
	//Timer slider
	
	sliderTimer = setInterval(function(){$('#slider-controls a.next').trigger('click');}, 5000);

}); //Domready end