var YOOFxBase = Fx.Base;
if (parseFloat(String(MooTools.version).slice(0, 3)) >= 1.2) YOOFxBase = new Class({
    Extends: Fx,
    initialize: function () {
        MooTools.upgradeLog("1.1 > 1.2: Fx.Base is deprecated. use Fx.");
        this.parent.apply(this, arguments)
    },
    step: function () {
        var a = $time();
        if (a < this.time + this.options.duration) {
            this.delta = a = this.transition((a - this.time) / this.options.duration);
            this.setNow();
            this.set(this.compute(this.from, this.to, a));
            this.increase()
        } else {
            this.set(this.compute(this.from, this.to, 1));
            this.complete()
        }
    }
});
JCtoppanel = YOOFxBase.extend({
    initialize: function (a, b) {
        this.setOptions({
            offset: 320,
            duration: 500,
            transition: Fx.Transitions.linear
        }, b);
        this.element = $E(".panel", a);
        this.wrapper = $E(".panel-wrapper", a);
        this.container = $E(".panel-container", a);
        this.margin = "top";
        this.layout = "height";
        this.mode = "out";
        this.now = [];
        this.parent(this.options)
    },
    addTriggerEvent: function (a) {
		a = $E(a);
		//dynamic height of the content
		var articleSize=$E('.article').getCoordinates();
		articleheight=articleSize.height;
		styleval = ($E('.panel').getStyle('min-height')).toInt();
		if(styleval>articleheight)
			articleheight=styleval;
		//dynamic height of the content
		
		var size=$E('.trigger-m').getCoordinates();
		var newwidth=-(75 + parseInt((size.width - 60)/2));
		$E('.trigger').setStyle('margin-left', newwidth);
		
        this.element && a && a.addEvent("click", function () {
            this.toggle()
        }.bind(this))
    },
    setNow: function () {
        if (parseFloat(String(MooTools.version).slice(0, 3)) >= 1.2) for (var a = 0; a < 2; a++) this.now[a] = this.compute(this.from[a], this.to[a], this.delta);
        else for (a = 0; a < 2; a++) this.now[a] = this.compute(this.from[a], this.to[a])
    },
    vertical: function () {
        return [this.element.getStyle("margin-top").toInt(), this.wrapper.getStyle("height").toInt()]
    },
    slideIn: function () {
        this.container.setStyle("z-index", 9999);
		$E('#toppanelarrow').setProperty('class', 'to_top');
		$E('#toppanelarrow-left').setProperty('class', 'to_top');
		this.mode = "in";
		return this.start(this.vertical(),[0,articleheight])
        
       // return this.start(this.vertical(), [0, this.options.offset])
    },
    slideOut: function () {
        this.container.setStyle("z-index", 9990);
		$E('#toppanelarrow').setProperty('class', 'to_down');
		$E('#toppanelarrow-left').setProperty('class', 'to_down');
		this.mode = "out";
		return this.start(this.vertical(),[-articleheight,0])
       
       // return this.start(this.vertical(), [-this.options.offset, 0])
    },
    toggle: function () {
        return this.wrapper.offsetHeight == 0 ? this.slideIn() : this.slideOut()
    },
    increase: function () {
        this.element.setStyle("margin-" + this.margin, this.now[0] + this.options.unit);
        this.wrapper.setStyle(this.layout, this.now[1] + this.options.unit)
    },
    onComplete: function () {
        if (this.mode == "out") {
            this.element.setStyle("margin-" + this.margin, -this.options.offset);
            this.wrapper.setStyle(this.layout, 0);
            return this
        }
    }
});
