/**
 * Scripts de la home page
 */
jQuery("document").ready(function($){


    /*
     * Activation du fade entre image dans le bloc du haut
     
     $("a > img.mainMin, a > img.listMin").click(function aClick() {
     
     $('.ad-gallery').adGallery();
     
     $("a > img.mainMin, a > img.listMin").unbind("click", aClick);
     $("a > img.mainMin, a > img.listMin").click(function(){return false;});
     
     $("img.mainBg").attr("src", $(this).attr("src"));
     $("a.linkMain").attr("href", ($(this).parent().attr("href")));
     $("#titreImage").children("a").html($(this).parent().attr("rel"));
     
     $("img.mainGrande").fadeOut("normal", function() {
     $(this).attr("src", $("img.mainBg").attr("src"));
     $(this).show();
     $("a > img.mainMin, a > img.listMin").bind("click", aClick);
     });
     
     return false;
     });
     */
    $('.ad-thumb-list > li').each(function(){
        $(this).children("a").children("img").attr('longdesc', '');
        $(this).children("a").children("img").attr('title', '');
    });
    
    var galleries = $('.ad-gallery').adGallery({
        slideshow: {
            enable: true,
            autostart: true,
            speed: 5000,
            stop_on_scroll: true // Should the slideshow stop if the user scrolls the thumb list?
        },
        cycle: true,
        callbacks: {
            // Executes right after the internal init, can be used to choose which images
            // you want to preload
            init: function(){
                // preloadAll uses recursion to preload each image right after one another
                //this.preloadAll();
                $(".linkMain").attr('href', $(".ad-active").next().attr('value'));
                $(".linkMain").html($(".ad-active").attr('rel'));
				$(".ad-image").click(function() { document.location.href = $(".linkMain").attr('href'); });
            },
            
            // This gets fired right after the new_image is fully visible
            afterImageVisible: function(){
                // For example, preload the next image
                $(".linkMain").attr('href', $(".ad-active").next().attr('value'));
                $(".linkMain").html($(".ad-active").attr('rel'));
				$(".ad-image").children("img").click(function() { document.location.href = $(".linkMain").attr('href'); });
                
				/*
				var context = this;
                this.loading(true);
                this.preloadImage(this.current_index + 1, function(){
                    // This function gets executed after the image has been loaded
                    context.loading(false);
                });
                */
            },
            // This gets fired right before old_image is about to go away, and new_image
            // is about to come in
            beforeImageVisible: function(new_image, old_image){
            	//alert(new_image);
            }
        }
    });
    /*
     $('#switch-effect').change(
     function() {
     galleries[0].settings.effect = $(this).val();
     return false;
     }
     );
     $('#toggle-slideshow').click(
     function() {
     galleries[0].slideshow.toggle();
     return false;
     }
     );
     galleries[0].addAnimation('wild',
     function(img_container, direction, desc) {
     var current_left = parseInt(img_container.css('left'), 10);
     var current_top = parseInt(img_container.css('top'), 10);
     if(direction == 'left') {
     var old_image_left = '-'+ this.image_wrapper_width +'px';
     img_container.css('left',this.image_wrapper_width +'px');
     var old_image_top = '-'+ this.image_wrapper_height +'px';
     img_container.css('top', this.image_wrapper_height +'px');
     } else {
     var old_image_left = this.image_wrapper_width +'px';
     img_container.css('left','-'+ this.image_wrapper_width +'px');
     var old_image_top = this.image_wrapper_height +'px';
     img_container.css('top', '-'+ this.image_wrapper_height +'px');
     };
     if(desc) {
     desc.css('bottom', '-'+ desc[0].offsetHeight +'px');
     desc.animate({bottom: 0}, this.settings.animation_speed * 2);
     };
     img_container.css('opacity', 0);
     return {old_image: {left: old_image_left, top: old_image_top, opacity: 0},
     new_image: {left: current_left, top: current_top, opacity: 1},
     easing: 'easeInBounce',
     speed: 2500};
     }
     );
     */
    $('.ad-back, .ad-forward').remove();
});
