/*
@author : Jérôme Lecocq ( jer.lecocq@gmail.com )
Visionneuse réalisée sous jquery 1.6.2

*/

$(document).ready(function() {
    var visionneuse = {
        
        anchorslinks: $('#visionneuse .ancres li a'),
        anchors: $('#visionneuse .ancres li'),
        items: $('#visionneuse .content_visio'),
        count: this.anchors.length,
        currentIndex: -1,
        indexMax: this.count - 1,
        init: function(){
            // On cache tous les elements sauf le premier
            this.items.fadeOut(0);
            this.setCurrentIndex(0);
            
            this.anchorslinks.click(function(){
                visionneuse.setCurrentItem(this);
                return false;
            });
			
			this.anchorslinks.mouseenter(function(){
                visionneuse.setCurrentItem(this);
                return false;
            });
        },
        
        setCurrentItem: function(item){
            var newIndex = this.getIndex(item.parentNode.id);
            this.setCurrentIndex(newIndex);
        },
        setCurrentIndex: function(index){
            if(index != this.currentIndex){
                if(this.currentIndex >= 0){
                    $('#content_visio_' + this.currentIndex).fadeOut();
                    $('#visio_anchor_' + this.currentIndex).removeClass('selected');
                }
                $('#content_visio_' + index).fadeIn();
                $('#visio_anchor_' + index).addClass('selected');
                this.currentIndex = index;
            }
        },
        next: function(){
            var nextIndex = this.currentIndex + 1;
            if(nextIndex > indexMax)
                this.setCurrentIndex(nextIndex);
            else
                this.setCurrentIndex(0);
        },
        
        getIndex: function(id){
            var tmp = id.split('_');
            return tmp[tmp.length - 1];
        }
        
    }
    
    
    visionneuse.init();
});
