var tooltipTimer, tooltipCache, sliderTimer;

//Domready
$(document).ready(function(){
	
	//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 = 1007;
	
	$('#slider-controls').hover(function(){
		clearInterval(sliderTimer);
	});
	
	$('#slider-controls a.prev').click(function(e){
		e.preventDefault();
		
		if(page > 1) {
			$('#showcase ul').animate({left: "+=" + pageWidth}, 1000, 'swing');
			page --;
			//$('#counter').html(page + "/" + pages);
		}
	});	
	
	$('#slider-controls a.next').click(function(e){
		e.preventDefault();
		
		if(page < pages) {
			$('#showcase ul').animate({left: "-=" + pageWidth}, 1000, 'swing');
			
			page ++;
			//$('#counter').html(page + "/" + pages);
		}
		else if(page==pages){
			page=1;
			$('#showcase ul').animate({left: "+="+(pageWidth*(pages-1))+"px"}, 5000, 'swing');
			//$('#showcase ul').animate({'marginLeft' : "+="+(pageWidth*(pages-1))+"px"}, 5000);
			
		}
	});
	
	//Timer slider
	
	sliderTimer = setInterval(function(){$('#slider-controls a.next').trigger('click');},8000);

}); //Domready end
