//Fonts
Cufon.replace('#center h1, #center h2, #center h3, #center h4, .submenu h4, .newsh h3', { fontFamily: 'delicious' });
var t;	

$(function()
{

	var max = 0;
	$('.ipod span').each(function(){max++;});

	if(max > 1)
	{
		loopSlide(0,max);
	}
	
	// slider
	$('.slider img:first').css("display","block");
	$('.ipod span').click(function(){
		var nb = parseInt($(this).attr("id").substring(1,3))-1;
		$('.ipod span').removeClass('ncurrent');
		$(this).addClass('ncurrent');
		$('.slider img').fadeOut(500);
		$('.slider img:eq('+nb+')').fadeIn(500);
        $('.nav strong').text($('.ncurrent').attr("title"));
	});
	
	$('.slider').mouseenter(function(){stopme(t);});
	$('.slider').mouseleave(function(){loopSlide(0,max);});
	
	// script menu
	$('.submenu .sub.scurrent ul').show();
	$('.submenu .sub h4').each(function()
	{
		// on est sur .sub
		$(this).parent().click(function()
		{	
			// si !current
			if(!$(this).hasClass('scurrent') && !$(this).hasClass('nclick'))
			{
				$('.scurrent').removeClass('scurrent');
				$(this).addClass('scurrent');
				$(this).parent().find('.sub').not('scurrent').find('ul').slideUp({queue:true, duration:500});
				$('.scurrent').find('ul').slideDown({queue:true, duration:500});
			}
		});
	});
	
});

function loopSlide(jCount,jMax)
{
	// Function for slider
	t = setTimeout
	(
		function()
		{
			if(jCount != -jMax+1)
			{
				jCount = jCount-1;
				$('.ncurrent').next().addClass('ncurrent');
				$('.ncurrent:first').removeClass('ncurrent');
				var nbs = parseInt($('.ncurrent').attr("id").substring(1,3))-1;
				$('.nav strong').text($('.ncurrent').attr("title"));
				$('.slider img').fadeOut(500);
				$('.slider img:eq('+nbs+')').fadeIn(500);
			}
			else
			{
				jCount = 0;
				$('.ipod span:first').addClass('ncurrent');
				$('.ncurrent:last').removeClass('ncurrent');
				var nbs = parseInt($('.ncurrent').attr("id").substring(1,3))-1;
				$('.nav strong').text($('.ncurrent').attr("title"));
				$('.slider img').fadeOut(500);
				$('.slider img:eq('+nbs+')').fadeIn(500);
			}
			
			loopSlide(jCount, jMax);
		}
		,5000	
	)
}

function stopme(t)
{
	clearTimeout(t);
}

