// ON LOAD
$(document).ready(function(){
	// Cufon
	cufon();
			
	// Tools links
	$(".toolslink").delay(3000).animate({ right: '+=12'}, {duration:500} );
	$(".toolslink").mouseenter(function(){$(".toolslink").animate({ right: '-=12'}, {duration:100} );});
	$(".toolslink").mouseleave(function(){$(".toolslink").animate({ right: '+=12'}, {duration:500} );});
	
	// Carousel Acc + Acc Actu
	if ($('#mycarousel').length != 0) 
	{
		$('#mycarousel').jcarousel({
		    scroll: 1, // Nbre item par iterations
		    auto: 3, // Interval en secondes
			wrap: 'last',
			initCallback: mycarousel_initCallback
		});
	}
	
	// Page ACCEUIL
	if ($('body.accueil').length != 0) 
	{		
		// Background BDX ACC 
		$('.accueil .menu').mouseleave(function(){ $('.accueil .backGround').css({backgroundPosition: '0px 0px'});});
		
		$('.accueil .menu a').eq(0).hover(function(){ $('.accueil .backGround').hide().css({backgroundPosition: '0px 0px'}).fadeIn(100);});
		$('.accueil .menu a').eq(1).hover(function(){ $('.accueil .backGround').hide().css({backgroundPosition: '0px -248px'}).fadeIn(100);});
		$('.accueil .menu a').eq(2).hover(function(){ $('.accueil .backGround').hide().css({backgroundPosition: '0px -496px'}).fadeIn(100);});
		$('.accueil .menu a').eq(3).hover(function(){ $('.accueil .backGround').hide().css({backgroundPosition: '0px -248px'}).fadeIn(100);});
		$('.accueil .menu a').eq(4).hover(function(){ $('.accueil .backGround').hide().css({backgroundPosition: '0px 0px'}).fadeIn(100);});
		$('.accueil .menu a').eq(5).hover(function(){ $('.accueil .backGround').hide().css({backgroundPosition: '0px -248px'}).fadeIn(100);});
		$('.accueil .menu a').eq(6).hover(function(){ $('.accueil .backGround').hide().css({backgroundPosition: '0px -496px'}).fadeIn(100);});
		$('.accueil .menu a').eq(7).hover(function(){ $('.accueil .backGround').hide().css({backgroundPosition: '0px -0px'}).fadeIn(100);});
		
		// Background "Je suis..."
		//$('.accueil .col-left a').eq(0).hover(function(){ $('.bdx-content .col-left').css({backgroundImage: 'url(/skins/enit/resources/img/jesuis-bg-01.png)'}).fadeIn(100);});
		//$(''.accueil .col-left a').eq(1).hover(function(){ $('.bdx-content .col-left').css({backgroundImage: 'url(/skins/enit/resources/img/jesuis-bg-02.png)'}).fadeIn(100);});
		//$('.accueil .col-left a').eq(2).hover(function(){ $('.bdx-content .col-left').css({backgroundImage: 'url(/skins/enit/resources/img/jesuis-bg-03.png)'}).fadeIn(100);});
		//$('.accueil .col-left a').eq(3).hover(function(){ $('.bdx-content .col-left').css({backgroundImage: 'url(/skins/enit/resources/img/jesuis-bg-04.png)'}).fadeIn(100);});
		//$('.accueil .col-left a').eq(4).hover(function(){ $('.bdx-content .col-left').css({backgroundImage: 'url(/skins/enit/resources/img/jesuis-bg-05.png)'}).fadeIn(100);});
		//$('.accueil .col-left a').eq(5).hover(function(){ $('.bdx-content .col-left').css({backgroundImage: 'url(/skins/enit/resources/img/jesuis-bg-06.png)'}).fadeIn(100);});
		// RollOut
		//$('.accueil .col-left ul li a').mouseleave(function(){ $('.bdx-content .col-left').css({backgroundImage: 'url(/skins/enit/resources/img/jesuis-bg.png)'});});
	}
	
	// Page ACCEUIL ACTUS
	if ($('body.accactu').length != 0) 
	{
		$('.news ul').mouseover(function(){ $('.news').addClass('over');});
		$('.news ul').mouseleave(function(){ $('.news').removeClass('over');});
	}
	
	// Gestion SITEMAP treeview 
	if ($('body.sitemap').length != 0) 
	{
		$('.filetree').treeview({
			persist:   "location",
			collapsed: true,
			animated:  "fast"
		});
	}
	
});



// Cufon
function cufon(){
	Cufon.replace(['ul.menu>li>a','.bdx-content h2','.bdx-content a.allnews','.content-list-wrapper .link','.cufon','.rightcolumn h3','.rightcolumn a.all'], {hover: true});
}

// Carousel
function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};
