/* Copyright 2010 Xsevo */
var xsCmtList = {

    NoAutoHide:true,ShowBg:true,BoxId:'xs-cmtlist', ClassName:'xs-cmtlist hbl',
    click: function(p) {
        if (!p) p = 1;
        new Ajax.Request(xs.path+'comments/'+p+'/', {onSuccess:this.jsReturn.bind(this)});
        return false;
    },
    load: function(response) {
        if (!this.Visible) this.prep();
        this.setContents(response);
        if (!this.Visible) this.show();
    },
    prep: function() {
        this._init();
        this.prepBox();
    },
    show: function() {
        var size = this.Box.getDimensions();
        var wsize = xsUtil.getWindowSize();
        var hover_left = Math.round((wsize.width - size.width) / 2);
        var hover_top = Math.round((wsize.height - size.height) / 2) + (document.documentElement.scrollTop || document.body.scrollTop);
        this.showBox(hover_left > 0 ? hover_left : 0, hover_top > 0 ? hover_top: 0);        
    },
    setContents: function(buf) {
        this.Box.innerHTML = buf;
    },
    jsReturn: function(req_obj, obj) {
        try {
            var response = obj?obj:req_obj.responseText;
        } catch (e) { if (req_obj.responseText) { xsJSError(e); } return; }
        try {
            this.load(response);
        } catch (e) { }
    }
};
Object.extend(xsCmtList, xsHoverBase);


Object.extend(xsSkunk2, {
    set: function(obj) {
        Object.extend(this, obj);
    },
    RecentScrollIdx:0,RecentScrollHeight:150,RecentScrollIdxMax:0,RecentScrollPerPage:6,RecentScrollDuration:0.5,
    idxRecentScroll: function(f,m) {
        if (!this.RecentScrollIdxMax) this.RecentScrollIdxMax = parseInt(Math.ceil(m/this.RecentScrollPerPage))-1;
        this.RecentScrollIdx += (f==1?-1:1);
        if (this.RecentScrollIdx < 0) this.RecentScrollIdx = 0;
        if (this.RecentScrollIdx > this.RecentScrollIdxMax) this.RecentScrollIdx = this.RecentScrollIdxMax;
        new Effect.Move($('scroll-recent'), {y:(-(this.RecentScrollIdx*this.RecentScrollHeight)), duration: this.RecentScrollDuration, mode:'absolute'});
        return false;
    },
    NewsScrollIdx:0,NewsScrollHeight:252,NewsScrollIdxMax:0,NewsScrollPerPage:4,NewsScrollDuration:0.5,
    idxNewsScroll: function(f,m) {
        if (!this.NewsScrollIdxMax) this.NewsScrollIdxMax = parseInt(Math.ceil(m/this.NewsScrollPerPage))-1;
        this.NewsScrollIdx += (f==1?-1:1);
        if (this.NewsScrollIdx < 0) this.NewsScrollIdx = 0;
        if (this.NewsScrollIdx > this.NewsScrollIdxMax) this.NewsScrollIdx = this.NewsScrollIdxMax;
        new Effect.Move($('scroll-news'), {y:(-(this.NewsScrollIdx*this.NewsScrollHeight)), duration: this.NewsScrollDuration, mode:'absolute'});
        return false;
    },
    ProductScrollDuration:2.0,ProductScrollHoverDuration:30.0,ProductScrollInitDuration:120.0,
    ProductScrollDirection:2,ProductScrollAuto:1,
    ProductArrowsDuration:1,ProductArrowsOpacity:0.5,
    idxProductSetup: function() {
        try {
            this.ProductScrollEl = $('scroll-product');
            this.ProductViewEl = $('scroll-product-view');
            this.ProductLeftArrow = $('scroll-product-arr-l');
            this.ProductRightArrow = $('scroll-product-arr-r');
            this.ProductViewWidth = this.ProductViewEl.getDimensions().width;
            var product = $(this.ProductScrollEl.getElementsByTagName('div').item(0));
            var product_width = product.getDimensions().width;
            this.ProductScrollWidth = this.ProductCount * product_width;
            this.ProductScrollMax = this.ProductScrollWidth - this.ProductViewWidth;
            this.ProductScrollDuration = 2+parseInt(1750 / this.ProductScrollWidth);
            var offset = parseInt((this.ProductViewWidth - this.ProductScrollWidth) / 2 - parseInt(product_width/2));
            this.ProductScrollEl.setStyle({width:this.ProductScrollWidth+'px', left:offset+'px'});
            new Effect.Opacity(this.ProductViewEl, {duration:0.5, from:0.0, to:1});
            this.ProductViewEl.setStyle({visibility:'visible'});
        } catch(e) { xsJSError(e); }
    },
    idxProductScroll: function(f) {
        if (f) this.ProductScrollDirection = f;
        this.idxProductClear();
        if (!this.idxProductCallback(f)) return false;
        var d = (f==1?this.ProductViewWidth:-this.ProductViewWidth);
        this.ProductScrollEffect = new Effect.Move(this.ProductScrollEl, {x:d, duration:this.ProductScrollDuration, mode:'relative', beforeUpdate:this.idxProductCallback.bind(this,this.ProductScrollDirection) });
        return false;
    },
    idxProductClear: function() {
        if (!this.ProductScrollEffect) return false;
        try {
            this.ProductScrollEffect.cancel();
        } catch(e) {}
        this.ProductScrollEffect = null;
    },
    idxProductArrowsClear: function() {
        if (this.ProductLeftArrowEffect) {        
            try { this.ProductLeftArrowEffect.cancel(); } catch(e) {}
            this.ProductLeftArrowEffect = null;
        }
        if (this.ProductRightArrowEffect) {        
            try { this.ProductRightArrowEffect.cancel(); } catch(e) {}
            this.ProductRightArrowEffect = null;
        }        
    },
    idxProductScrollHover: function(f,m) {
        this.idxProductArrows(m);
        if (f) this.ProductScrollDirection = f;
        this.idxProductClear();
        if (!this.idxProductCallback(f)) return false;
        var d = (f==1?this.ProductScrollMax:-this.ProductScrollMax);
        if (m==1) {
            this.ProductScrollAuto = 0;
            this.ProductScrollEffect = new Effect.Move(this.ProductScrollEl, {x:d, duration:this.ProductScrollHoverDuration, mode:'relative', transition: Effect.Transitions.linear, beforeUpdate:this.idxProductCallback.bind(this,this.ProductScrollDirection) });
        } else {
            this.ProductScrollAuto = 1;
            this.idxProductScrollInit();
        }
    },
    idxProductCallback: function(f) {
        try {
            if (!this.ProductScrollEl) return false;
            var q = false;
            var l = parseInt(this.ProductScrollEl.getStyle('left'));
            if (((l > 0) && (f==1)) || ((l < (this.ProductViewWidth - this.ProductScrollWidth)) && (f==2))) {
                if (this.ProductScrollAuto) {
                    this.ProductScrollDirection = (this.ProductScrollDirection == 1) ? 2 : 1;
                    this.idxProductScrollInit();
                    return false;
                }
                if (!this.ProductScrollEffect) return true;
                this.idxProductClear();
                return false;
            }
        } catch(e) { }
        return true;
    },
    idxProductScrollInit: function() {
        return;
        this.idxProductClear();
        var d = (this.ProductScrollDirection==1?this.ProductScrollMax:-this.ProductScrollMax);
        this.ProductScrollEffect = new Effect.Move(this.ProductScrollEl, {x:d, duration:this.ProductScrollInitDuration, mode:'relative', transition: Effect.Transitions.linear, beforeUpdate:this.idxProductCallback.bind(this,this.ProductScrollDirection) });
    },
    idxProductArrows: function(m,d) {
        this.idxProductArrowsClear();
        if (m == 2) {
            var next_dir = d?0:1;
            var params = { duration:this.ProductArrowsDuration, to:(d?0.0:this.ProductArrowsOpacity), from:(d?this.ProductArrowsOpacity:0.0) };
            this.ProductRightArrowEffect = new Effect.Opacity(this.ProductRightArrow, params);
            params.afterFinish = this.idxProductArrows.bind(this, 2, next_dir);
            this.ProductLeftArrowEffect = new Effect.Opacity(this.ProductLeftArrow, params);
        } else {
            var params = { opacity: 0 }
            Element.setStyle(this.ProductRightArrow, params);
            Element.setStyle(this.ProductLeftArrow, params);
            
            
        }
    }
});

var xsInitBank = {
    index: function() {
        xsSkunk2.idxProductArrows(2);
//        setTimeout("xsSkunk2.idxProductScrollInit()", 5000);
    }
};
