﻿///<reference path="mootools-1.2.js" />
var scollMainContent = new Class({
    initialize : function () {
     this.c = $("mainContent");
     if(!$chk(this.c)) return;
     if(!this.checkSize()) window.addEvent("load", this.checkSize.bind(this));
    },
    checkSize : function() {
        var t = this.c.getScrollSize().y / this.c.getSize().y;
        if(t <= 1) return false;
        return this.addFunction(t);
    },
    addFunction : function(t){
         t = Math.round(t);
         this.f = new Fx.Scroll(this.c, {"duration" : (t*1500)});
         this.ff = new Fx.Scroll(this.c, {"duration" : (t*400)});
         this.c.setStyles({"overflow": "hidden"});
         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($("ctrlcont"));
         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($("ctrlcont"));
         this.c.addEvent("mousewheel",this.wheel.bindWithEvent(this));
         return true;
    },
    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 makeAccordion = new Class({
    initialize : function () {
        $$('.accordion').each(function(elt){
            elt.getElements('a.toggler').setStyle("cursor","pointer");
            new Accordion(elt, 'a.toggler', 'div.element',{alwaysHide: true, show:-1, opacity:false});
        }, this);
    }
});
var makePopup = new Class({
    initialize : function () {
        $$('a').each(function(elt){
            
            var relValue = elt.get("rel");
            
            if($chk(relValue) && relValue.indexOf("popup") >= 0) {
                
                params = relValue.replace("popup","").replace("[","").replace("]","");
                var paramsArr = params.split(",");
                var linkHref = elt.get("href");
                elt.set("href", "javascript:void(0)");
                elt.set("target", "");
                elt.addEvent("click", function(){window.open(linkHref,"pop","menubar=0,resizable=1,width="+paramsArr[0]+",height="+paramsArr[1])});
            }
        }, this);
        }
    });
window.addEvent("domready", function () {new scollMainContent(); new makeAccordion();new makePopup();});
//var Diaporama = new Class({
//    initialize : function (urlList,contid,slidenum) {
//        if(urlList.length <= 1) return;
//        //$(contid).setStyle("background-image","none");
//        
//        this.c = $chk($(contid).getElement("div.diap")) ?
//             $(contid).getElement("div.diap") : new Element("div",{"class":"diap","styles" : {"cursor" : "pointer", "width" : "100%", "height" : "100%"}}).inject($(contid));
//             
//        this.s = new Slideshow(this.c, urlList, {height : 450, width : 255, delay : 7000, controller: true,random : true, slide : slidenum});
//        return;
//        
//    }
//});
