if (Mxm == undefined)
	var Mxm = {};

Mxm.Slider = {
	// load the automatic carousel
	Load : function() {
	    this.Auto.init();
	},

	// Mxm.Slider.Auto namespace, used for initializing
	// an automatic scrolling carousel
	Auto : {

		slideLeft : null,
		slideRight : null,
        startIndex : 0,

		init : function() {
	        var carouselElement = $('edito');
	        // Carousel class instance initialization call
			// @param 1 : Carousel.key
			// @param 2 : Carousel.carouselElement
			// @param 3 : Carousel.item.width
			// @param 4 : Carousel.item.height
			// @param 5 : Event observer (activate, shutdown..)
			// @param 6 : Options ! (required: setSize, itemParser, setItemEvents)
			Mxm.Slider.PictureCarousel = new Carousel('PictureCarousel', carouselElement, 100, 100, Mxm.Slider, {
	            setSize: 2,
	            duration: .5,
	            direction: 'horizontal',
				// needed by Carousel class in order to parse IMG item
				// (name = alt ; pictureHtml = src)
	            itemParser: function(item) {
	                var sKey = item.down('.key').innerHTML;
	                var sCaption = item.down('.caption').innerHTML;
	                var sPictureHtml = item.down('.picture').innerHTML;
	                return { name: sCaption, pictureHtml: sPictureHtml };
	            },
				// setting click event to activate custom element of the carousel
				// Maximiles won't need it since there is a redirection aswell
				// on the image as on the link above it
	            setItemEvents: function(carousel, itemElement, carouselItem, observer) {
	                //This allows you to set events to the item like rollovers/mouse events
	                Event.observe(itemElement, 'click', function() {
	                    carousel.activate(carouselItem);
	                });
	            },
				// both boolean are needed for compatibility with manual carousels
				// @see carousel.js
	            allowAutoLoopOnSet: false,
	            allowAutoLoopOnIndividual: false
	        });
	        Mxm.Slider.PictureCarousel.load();

            Mxm.Slider.PictureCarousel.next();

			// fire next() trigger
            this.slideLeft = setInterval(this.slideNext.bind(this), 5000);
	    },
	    slideNext: function() {
	        Mxm.Slider.PictureCarousel.next();
	    },
		slidePrevious: function() {
			Mxm.Slider.PictureCarousel.previous();
		}
	},

	// Observer method, on-activate
	fireActiveCarouselLoaded : function(carousel) {
	},

	// Observer method, on-activate
	fireActiveCarouselItem : function(carousel, element, item) {
        element.removeClassName('item');
	    element.addClassName('itemSelected');

        // remove current link
        if ($('slideTitle') && $('slideTitle').down('a')) {
            Element.remove($('slideTitle').down('a'));
        }
        else {
            if (! $('slideTitle')) {
                var slideTitle = new Element('h2');
                slideTitle.setAttribute('id', 'slideTitle');

                var tmpLink = new Element('a');
                tmpLink.setAttribute('href', '#');
                tmpLink.update('&nbsp;');

                Element.insert(element.up('.container'), {'top' : slideTitle});
                Element.insert(slideTitle, {'top' : tmpLink});
            }
        }

        if ($('slideTitle').down('a')) {
            // make sure there is no more data in the h2
            Element.remove($('slideTitle').down('a'));
        }

        // create new link with caption
        var newLink = new Element('a');
        newLink.setAttribute('href', element.down('.caption').childNodes[0].nodeValue);
        newLink.update(element.down('.picture').childNodes[0].nodeValue);

        // insert new link into the h2
        Element.insert($('slideTitle'), {'bottom' : newLink});

		// proceed to pre-slide statements
	},

	// Observer method, on-activate
	fireDeactiveCarouselItem : function(carousel, element, item) {
	    element.removeClassName('itemSelected');
        element.addClassName('item');
		// proceed to pre-activate statements
	}
}; // End of Mxm.Slider

