var nbactu=0;
var curr_actu=0;
var timer=0;
$(document).ready(function()
{
	$('#menu_real ul li').hover(
		function(){ $(this).addClass('shover');},
		function(){ $(this).removeClass('shover');}
	);
	
	//actus
	$('.showactu').click(function()
	{
		if($(this).hasClass('up'))
		{
			$('.controller').stop().animate({'bottom':-$('.baseline').height()});
			$(this).removeClass('up').addClass('down');
		}
		else
		{
			$('.controller').stop().animate({'bottom':'0px'});
			$(this).removeClass('down').addClass('up');
		}
		return false;
	});
	
	
	if(idpage==1)
	{
		nbactu=$('.actus .actu').length;
		load_actu(curr_actu);
	}
	
	if(idpage==2 || parent==2)
	{
		nbactu=$('.categories .cat').length;
		load_cat(curr_actu);
		timer=setInterval("autochange()",8000);
	}
	
	
	
	$('.prevcat').click(function()
	{
		if($(this).hasClass('enabled'))
		{
			curr_actu--;
			load_cat();
			clearInterval(timer);
		}
		return false;
	});
	
	$('.nextcat').click(function()
	{
		if($(this).hasClass('enabled'))
		{
			curr_actu++;
			load_cat();
			clearInterval(timer);
		}
		return false;
	});
	
	
	$('.prevactu').click(function()
	{
		if($(this).hasClass('enabled'))
		{
			curr_actu--;
			load_actu();
		}
		return false;
	});
	
	$('.nextactu').click(function()
	{
		if($(this).hasClass('enabled'))
		{
			curr_actu++;
			load_actu();
		}
		return false;
	});
	
	if($('.popup').html())
	{
		var docHeight = $(document).height();
	    $(".layer").height(docHeight);
		$('.close_popup,.layer').click(function(){$('.popup,.layer').fadeOut('fast'); return false;});
		$('.layer').fadeIn('fast');
	}
	
	
	$('.thumbs li').not('.thumbs .current').css('opacity',0.6);
	
	$('.thumbs li a').click(function()
	{
		if(!$(this).parent('li').hasClass('current'))
		{
			$('.thumbs .current').removeClass('current').stop().animate({opacity:0.6},'fast');
			
			
			$(this).parent('li').addClass('current').animate({opacity:1},'fast');
			$('.picback').html($('.picfront').html());
			
			$('.picfront>img').attr('alt',$(this).attr('title'));
			$('.title_pic').html($(this).attr('title'));
			$('.picfront img').hide().attr('src',$(this).attr('href'));
			$('.picfront>img').load(function(){		
					$(this).fadeIn('slow',function(){ $('.picfront img').attr('src')});
			});
		}
		return false;
	});
	
	$('.getactu').click(function()
	{
		$('.scroller').stop().scrollTo($(this).attr('href'),1000,{axis:'y', easing:'easeOutCubic'});
		return false;
	});
});

function load_actu()
{
	check_arrows();
	actu=$($('.actus .actu').get(curr_actu))
	html=actu.children('.cont_actu').html();
	$('.scroller').stop().scrollTo(actu,1000,{axis:'x', easing:'easeOutCubic'});
	$('.controller_content').html(html);
}

function check_arrows()
{
	if(curr_actu==0)
	{
		$('.prevactu,.prevcat').removeClass('enabled').addClass('disabled');
		curr_actu=0;
	}
	else
	{
		$('.prevactu, .prevcat').removeClass('disabled').addClass('enabled');
	}
	if(curr_actu==(nbactu-1))
	{
		$('.nextactu, .nextcat').removeClass('enabled').addClass('disabled');
		curr_actu=nbactu-1;
	}
	else
	{
		$('.nextactu, .nextcat').removeClass('disabled').addClass('enabled');
	}
}

function load_cat()
{
	check_arrows();
	actu=$($('.categories .cat').get(curr_actu))
	html=actu.children('.desc_cat').html();
	$('.scroller').stop().scrollTo(actu,1000,{axis:'x', easing:'easeOutCubic'});
	$('.content_cat').html(html);
}

function autochange()
{
	curr_actu++;
	if(curr_actu>(nbactu-1))
		cur_actu=0;
	load_cat();
}