/*
Оформление вкладок описания товара
2008 - Magic Wand
*/
TabsDecorator = function(selector, img_path) {
    this.selector = selector;
    this.img_path = img_path;
}

TabsDecorator.prototype = {
    decorate: function() {
        var container = $(this.selector);
        var tabs = $('td', container);
        var count_tabs = tabs.length;
        
        var _this = this;
        tabs.each(function(i) {
          if(i == 0) _this.processFirstElem(this);
          else if(i == count_tabs - 1) _this.processEndElem(this);
          else if($(this).hasClass('tab_content')) _this.processContentElem(this);
          else _this.processBorderElem(this);
        });
    },
    
    processFirstElem: function(el) {
        if(this.nextIsActive(el)) {
            this.setImageOfElem(el, 'item_l_a.gif');
        }
    },
    
    processEndElem: function(el) {
        if(this.prevIsActive(el))
            this.setImageOfElem(el, 'item_r_a.gif');
        else
            this.setImageOfElem(el, 'item_r.gif');
    },
    
    processContentElem: function(el) {
        if(this.isActive(el))
           $(el).removeClass('bor_td').addClass('bor_t');
    },
    
    processBorderElem: function(el) {
        if(this.prevIsActive(el)) {
            this.setImageOfElem(el, 'item_cr_a.gif');
        } else if(this.nextIsActive(el)) {
            this.setImageOfElem(el, 'item_cl_a.gif');
        }
    },
    
    nextIsActive: function(el) {
        return this.isActive($(el).next());
    },
    
    prevIsActive: function(el) {
        return this.isActive($(el).prev());
    },
    
    isActive: function(el) {
        return $(el).children('a').hasClass('act');
    },
    
    setImageOfElem: function(el, img) {
        $(el).children('img').attr('src', this.img_path + img);
    }
}

