///<reference path="mootools-1.2.js" />
var scollMainContent = new Class({
    initialize : function () {
     if(Browser.Engine.webkit419) return;
     if(!$chk($("compcont"))) return;
     this.c = $("compcont").getElement("div.contentText");
     
     if(!$chk(this.c)) return;
     this.c.setStyles({"overflow": "hidden", "padding-right" : 20, "width" :448});
     var t = Math.round(this.c.getScrollSize().y / this.c.getSize().y);
     
     if(this.c.getScrollSize().y <= this.c.getSize().y) return;
     var controls = new Element("div",{"class" : "controls"}).inject(this.c);
     this.f = new Fx.Scroll(this.c, {"duration" : (t*1500)});
     this.ff = new Fx.Scroll(this.c, {"duration" : (t*400)});
     this.u = new Element("a", {"class" : "up"}).addEvent("mouseleave",this.cancel.bindWithEvent(this)).addEvent("mouseenter",this.goUp.bindWithEvent(this, this.f)).addEvent("mousedown",this.goUp.bindWithEvent(this, this.ff)).inject(controls);
     this.d = new Element("a", {"class" : "down"}).addEvent("mouseleave",this.cancel.bindWithEvent(this)).addEvent("mouseenter",this.goDown.bindWithEvent(this, this.f)).addEvent("mousedown",this.goDown.bindWithEvent(this, this.ff)).inject(controls);
     this.c.addEvent("mousewheel",this.wheel.bindWithEvent(this));
    },
    wheel : function(ev) {
        this.cancel();
        this.f.set(0, this.c.getScroll().y - 5*ev.wheel);
    },
    goUp : function (ev, ef) {
        this.cancel();
        ef.toTop();
    },
    goDown : function (ev, ef) {
        this.cancel();
        ef.toBottom();
    },
    cancel : function () {
        this.f.cancel();
        this.ff.cancel();
        
    }
});
window.addEvent("domready", function () {new scollMainContent()});
var Diaporama = new Class({
    initialize : function (urlList,contid, controlsId, titleList) {
        $(contid).setStyle("background-image","none");
        $(controlsId).empty();
        this.cuRInd = 0;
        this.tL = titleList;
        this.c = $chk($(contid).getElement("div.diap")) ? $(contid).getElement("div.diap") : new Element("div",{"class":"diap"}).inject($(contid));
        this.ct = $chk($(contid).getElement("div.diapC")) ? $(contid).getElement("div.diapC") : new Element("div",{"class":"diapC"}).inject($(controlsId));
        this.play = false;
        this.s = new SimpleImageSlideShow({imgUrls : urlList, imgClass : "slides", container : this.c});
        //this.pElt = new Element("a", { "class" : "pauseCtrl"}).inject(controlsId);
        this.legendElt = new Element("span").inject(this.ct);
        this.nElt = new Element("a", { "class" : "nextCtrl"}).addEvent("click",this.forward.bind(this)).inject(this.ct,"top");
        this.bElt = new Element("a", { "class" : "backCtrl"}).addEvent("click",this.back.bind(this)).inject(this.ct,"top");
        new Element("div", { "class" : "clearer"}).inject(this.ct);
        window.addEvent("hideAll",this.hide.bind(this));
        window.addEvent("showDiap",this.show.bind(this));
        this.togglePlay();
        this.updateLegend(this.s.now);
    },
    forward : function() {
        
        this.stopPlay();
        this.s.back();
        this.updateLegend(this.s.now);
    },
    back : function() {
        this.stopPlay();
        this.s.forward();
        this.updateLegend(this.s.now);
    },
    nextSlide : function () {
        this.s.forward();
        this.updateLegend(this.s.now);
    },
    togglePlay : function() {
        if($chk(this.play)) {
            $clear(this.play);
            //this.pElt.removeClass("play");
            this.play = false;
        } else {
            this.play = this.nextSlide.periodical(5000,this);
            //this.pElt.addClass("play");
        }
    },
    stopPlay : function() {
        if($chk(this.play)) {
            $clear(this.play);
            //this.pElt.removeClass("play");
            this.play = false;
        }
    },
    show : function() {
        this.c.setStyle("display","block");
        this.ct.setStyle("display","block");
    },
    hide : function(){
        this.c.setStyle("display","none");
        this.ct.setStyle("display","none");
    },
    updateLegend : function (num) {
        if($chk(this.tL) && this.tL.length > num) this.legendElt.set('text', this.tL[num]);
    }
});
var Video = new Class({
    initialize : function (urlVideo, contId,controlsId,linkId) {
        if($chk($(contId))) $(contId).setStyle("background-image","none");
        window.fireEvent("hideAll");
        this.c = $chk($(contId).getElement("div.vid")) ? $(contId).getElement("div.vid") : new Element("div",{"class":"vid"}).inject($(contId));
        this.ct = new Element("a",{'text' : "diaporama", "class" : "diap"}).addEvent("click", function () {window.fireEvent("hideAll");window.fireEvent("showDiap");}.bind(this)).inject($(controlsId),"top");
        if(Browser.Plugins.Flash.version >= 9)  new Swiff('/video.swf', {"width": "300px","height": "225px", vars : {'urlVideo' : urlVideo, 'autoPlay' : 'true'},params : {'scale' : 'showall','allowFullScreen' : 'true','allowScriptAccess' :'sameDomain'}}).inject(this.c);
        else new Element("a",{'text' : "veuillez télécharger la dernière version du lectuer flash en suivant ce lien pour lire cette vidéo","target" : "_blank","href" : "http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=shockwaveFlash", "styles" : {"color" : "white", "font-size" : "10px", "display" : "block", "margin" : "5px"}}).inject(this.c);
        this.l = $(linkId).addClass("vidactive");
        window.addEvent("hideAll",this.hide.bind(this));
    },
    hide : function(){
        this.c.destroy();
        this.ct.destroy();
        this.l.removeClass("vidactive");
    }
});
var Sound = new Class({
    initialize : function (urlSound, linkId) {
        
        //window.fireEvent("hideAll");        
        this.ct = $("soundPlayer") ? $("soundPlayer").empty() : new Element("div", {"id" : "soundPlayer","styles" : {width:1, height:1, display:"none"}}).inject($(document.body));
        if(Browser.Plugins.Flash.version >= 9)  new Swiff('/sound.swf', {"width": "1px","height": "1px", vars : {'urlVideo' : urlVideo, 'autoPlay' : 'true'},params : {'scale' : 'showall','allowFullScreen' : 'true','allowScriptAccess' :'sameDomain'}}).inject(this.ct);
        //else new Element("a",{'text' : "veuillez télécharger la dernière version du lectuer flash en suivant ce lien pour lire cette vidéo","target" : "_blank","href" : "http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=shockwaveFlash", "styles" : {"color" : "white", "font-size" : "10px", "display" : "block", "margin" : "5px"}}).inject(this.c);
        this.l = $(linkId).addClass("vidactive");
        window.addEvent("hideAll",this.hide.bind(this));
    },
    hide : function(){
        this.c.destroy();
        this.ct.destroy();
        this.l.removeClass("vidactive");
    }
});
function getVideo(url,linkId) {    
    new Video(url,'diaporama','linksSpec',linkId);
}
var Agenda = new Class({
    initialize : function () {
        $("compcont").getElements("li.n").each(function(el){
            el.o = el.getElements("a.l").getStyle("background-color");
            el.addEvent("mouseenter",function (){this.getElements("a.l").setStyle("background-color","#660099");}.bind(el));
            el.addEvent("mouseleave",function (){this.getElements("a.l").setStyle("background-color",this.o);}.bind(el));
        });
        this.c = $("compcont");
        this.c.setStyles({"overflow": "hidden", "padding-right" : 20, "width" :(Browser.Engine.trident && Browser.Engine.version <= 6) ? 760 : 780});
        var t = Math.round(this.c.getScrollSize().y / this.c.getSize().y);
     
        if(this.c.getScrollSize().y <= this.c.getSize().y) return;
        var controls = new Element("div",{"class" : "controlsAg"}).inject(this.c);
        this.f = new Fx.Scroll(this.c, {"duration" : (t*1500)});
        this.ff = new Fx.Scroll(this.c, {"duration" : (t*400)});
        this.u = new Element("a", {"class" : "up"}).addEvent("mouseleave",this.cancel.bindWithEvent(this)).addEvent("mouseenter",this.goUp.bindWithEvent(this, this.f)).addEvent("mousedown",this.goUp.bindWithEvent(this, this.ff)).inject(controls);
        this.d = new Element("a", {"class" : "down"}).addEvent("mouseleave",this.cancel.bindWithEvent(this)).addEvent("mouseenter",this.goDown.bindWithEvent(this, this.f)).addEvent("mousedown",this.goDown.bindWithEvent(this, this.ff)).inject(controls);
        this.c.addEvent("mousewheel",this.wheel.bindWithEvent(this));
    },
    wheel : function(ev) {
        this.cancel();
        this.f.set(0, this.c.getScroll().y - 5*ev.wheel);
    },
    goUp : function (ev, ef) {
        this.cancel();
        ef.toTop();
    },
    goDown : function (ev, ef) {
        this.cancel();
        ef.toBottom();
    },
    cancel : function () {
        this.f.cancel();
        this.ff.cancel();
        
    }
});
var Spectacles = new Class({
    initialize : function () {
     if(!$chk($("linksSpec"))) return;
     this.c = $("linksSpec");
     this.c.setStyles({"overflow": "hidden", "padding-right" : 10, "width" :290, "height" : (Browser.Engine.trident && Browser.Engine.version <= 6) ? 112 : 119});
     var t = Math.round(this.c.getScrollSize().y / this.c.getSize().y);
     
     if(this.c.getScrollSize().y <= this.c.getSize().y) return;
     var controls = new Element("div",{"class" : "controlsSp"}).inject(this.c);
     this.f = new Fx.Scroll(this.c, {"duration" : (t*1500)});
     this.ff = new Fx.Scroll(this.c, {"duration" : (t*400)});
     this.u = new Element("a", {"class" : "up"}).addEvent("mouseleave",this.cancel.bindWithEvent(this)).addEvent("mouseenter",this.goUp.bindWithEvent(this, this.f)).addEvent("mousedown",this.goUp.bindWithEvent(this, this.ff)).inject(controls);
     this.d = new Element("a", {"class" : "down"}).addEvent("mouseleave",this.cancel.bindWithEvent(this)).addEvent("mouseenter",this.goDown.bindWithEvent(this, this.f)).addEvent("mousedown",this.goDown.bindWithEvent(this, this.ff)).inject(controls);
     this.c.addEvent("mousewheel",this.wheel.bindWithEvent(this));
    },
    wheel : function(ev) {
        this.cancel();
        this.f.set(0, this.c.getScroll().y - 5*ev.wheel);
    },
    goUp : function (ev, ef) {
        this.cancel();
        ef.toTop();
    },
    goDown : function (ev, ef) {
        this.cancel();
        ef.toBottom();
    },
    cancel : function () {
        this.f.cancel();
        this.ff.cancel();
        
    }
})