﻿///<reference path="mootools-1.2.js" />
var scollMainContent = new Class({
    initialize : function () {
     
	
	 this.c = $("mainHolder");
     if(!$chk(this.c)) return;
     var t = this.c.getScrollSize().y / this.c.getSize().y;
     if(t <= 1) return;
   	 
     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($("mainTop"));
    this.u.style.display = "none";
	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($("mainBottom"));
     this.c.addEvent("mousewheel",this.wheel.bindWithEvent(this));
    },
    wheel : function(ev) {
        this.cancel();
		
        this.f.set(0, this.c.getScroll().y - 5*ev.wheel);
		this.testScroll();
		//this.stopTimer();
    },
    goUp : function (ev, ef) {
		
		this.cancel();
		this.periodicalTimer = this.testScroll.periodical(400, this);
        ef.toTop();
		
    },
    goDown : function (ev, ef) {
      
		this.cancel();
		this.periodicalTimer = this.testScroll.periodical(400, this);		
        ef.toBottom();
		
    },
    cancel : function () {
        $clear(this.periodicalTimer);
		this.f.cancel();
        this.ff.cancel();
        
    },
	testScroll : function () {
		
		
		var scroll = $("mainHolder").getScroll();
		var stopUp = false;
		var stopDown = false;
		if(scroll.y > 1) {
			this.showUp(true);
		} else {			
			this.showUp(false);			
		}
		var total = $("mainHolder").getScrollSize().y-$("mainHolder").getCoordinates().height;
		if(scroll.y >= total) {
			this.showDown(false);			
		} else {
			this.showDown(true);
		}
		
		
	
	
	},
	showUp : function (thisState) {
		
		var elt = $("mainTop").getElement("a"); 
		if(thisState) {
			elt.style.display = "block";
		} else {
			$clear(this.periodicalTimer);
			elt.style.display = "none";
		}
	},
	showDown : function (thisState) {
		
		var elt = $("mainBottom").getElement("a"); 
		if(thisState) {
			elt.style.display = "block";
		} else {
			$clear(this.periodicalTimer);
			elt.style.display = "none";
		}
	}
	
	
});
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);
    }
});

window.addEvent("domready", function () {new scollMainContent(); new makeAccordion();});
