/***********************
*** Script SlideShow ***
************************/
function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 5000 );
});


/***********************
*** Script  tooltips ***
************************/
this.screenshotPreview = function(){    
        /* CONFIG */
                
                xOffset = 10;
                yOffset = 30;
                
                // these 2 variable determine popup's distance from the cursor
                // you might want to adjust to get the right result
                
        /* END CONFIG */
        $("a.screenshot").hover(function(e){
                this.t = this.title;
                this.title = "";        
                var c = (this.t != "") ? "<br/>" + this.t : "";
                $("body").append("<p id='screenshot'><img src='"+ this.rel +"' alt='url preview' />"+ c +"</p>");                                                                
                $("#screenshot")
                        .css("top",(e.pageY - xOffset) + "px")
                        .css("left",(e.pageX + yOffset) + "px")
                        .fadeIn("fast");                                                
    },
        function(){
                this.title = this.t;    
                $("#screenshot").remove();
    }); 
        $("a.screenshot").mousemove(function(e){
                $("#screenshot")
                        .css("top",(e.pageY - xOffset) + "px")
                        .css("left",(e.pageX + yOffset) + "px");
        });                     
};
this.imagePreview = function(){ 
        /* CONFIG */
                
                xOffset = 10;
                yOffset = 30;
                
                // these 2 variable determine popup's distance from the cursor
                // you might want to adjust to get the right result
                
        /* END CONFIG */
        $("a.preview").hover(function(e){
                this.t = this.title;
                this.title = "";        
                var c = (this.t != "") ? "<br/>" + this.t : "";
                $("body").append("<p id='preview'><img src='"+ this.href +"' alt='Image preview' />"+ c +"</p>");                                                                
                $("#preview")
                        .css("top",(e.pageY - xOffset) + "px")
                        .css("left",(e.pageX + yOffset) + "px")
                        .fadeIn("fast");                                                
    },
        function(){
                this.title = this.t;    
                $("#preview").remove();
    }); 
        $("a.preview").mousemove(function(e){
                $("#preview")
                        .css("top",(e.pageY - xOffset) + "px")
                        .css("left",(e.pageX + yOffset) + "px");
        });                     
};
this.tooltip = function(){      
        /* CONFIG */            
                xOffset = 10;
                yOffset = 20;           
                // these 2 variable determine popup's distance from the cursor
                // you might want to adjust to get the right result             
        /* END CONFIG */                
        $("a.tooltip").hover(function(e){                                                                                         
                this.t = this.title;
                this.title = "";                                                                          
                $("body").append("<p id='tooltip'>"+ this.t +"</p>");
                $("#tooltip")
                        .css("top",(e.pageY - xOffset) + "px")
                        .css("left",(e.pageX + yOffset) + "px")
                        .fadeIn("fast");                
    },
        function(){
                this.title = this.t;            
                $("#tooltip").remove();
    }); 
        $("a.tooltip").mousemove(function(e){
                $("#tooltip")
                        .css("top",(e.pageY - xOffset) + "px")
                        .css("left",(e.pageX + yOffset) + "px");
        });                     
};

//Activation du script pour les tooltips
$(document).ready(function(){
        tooltip();//active les tooltip simple
        //imagePreview();//active les tooltip image preview
        //screenshotPreview();//active les tooltip lien avec preview
});
/***********************
*** Lightbox galerie ***
************************/
$(document).ready(function(){
    $('.pic a').lightBox({
    // we call the lightbox method, and convert all the hyperlinks in the .pic container into a lightbox gallery
        imageLoading: 'lightbox/images/loading.gif',
        imageBtnClose: 'lightbox/images/close.gif',
        imageBtnPrev: 'lightbox/images/prev.gif',
        imageBtnNext: 'lightbox/images/next.gif'
    });
});

/***********************
******** AGENDA ********
************************/
$(document).ready(function(){
	//Affichage des events
	$('div.Bloc_Mois').click(function() {
		var id = $(this).attr('id');
		$('#Events'+id).slideToggle('fast');
	});
	
	//Affichage des détails d'un Event
	//var id_event;
	
	$('div.select_event').click(function() {
		//$('#bloc_'+id_event).hide();
		var id_event = $(this).attr('id');
		//$('#bloc_'+id_event).show();
		$('#bloc_'+id_event).slideToggle('fast');
	});
});
