﻿$.fn.loadModelInfo = function (data, displaycol, displaycolText) {
    var _html = '';
    // alert(_obj.Products[0][0] + ','+ _obj.Products[0][1] + ',' + _obj.Products[0][2] + ','+_obj.Products[0][3] + ','+_obj.Products[0][4] + ','+_obj.Products[0][5]);
    // 0.description, 1.OEM#, 2.Stock, 3.In Stock, 4.Price, 5.Axiom Part #, 6.CustPartNum, 7.BuyLink
    if (data.length != 0) {
        //this.parent().css('display', 'block');

        _html = _html + '<table class="configTable" style="border-collapse:collapse;">';
        _html = _html + '<tr class="configHeader" >\
             <th style="white-space: nowrap;padding-left:4px;">Description</th>\
             <th style="padding-left:6px;">OEM Part#</th>';

             if (displaycol.stock != 'none') { _html = _html + '<th style="text-align:center;display:' + displaycol.stock + ';">' + displaycolText.stockText + '</th>' };
             if (displaycol.instock != 'none') {_html = _html + '<th style="text-align:center;display:' + displaycol.instock + ';">In Stock</th>'};
             if (displaycol.price != 'none') {_html = _html + '<th style="display:' + displaycol.price + ';">Price</th>'};
             _html = _html + '<th style="white-space: nowrap;">' + displaycolText.axiompartText + '</th>';
             if (displaycol.custpart != 'none') { _html = _html + '<th style="white-space: nowrap;display:' + displaycol.custpart + ';">' + displaycolText.custpartText + '</th>' };
             if (displaycol.buylink != 'none') { _html = _html + '<th style="display:' + displaycol.buylink + ';">' + displaycolText.buyLinkText + '</th>' };
             
             _html = _html + '</tr>';

        for (var _i = 0; _i < data.length; _i++) {
            _html = _html + '<tr><td class="configSubHeader" colspan=' + colcnt + '>' + data[_i].Category + '</td></tr>';
            var _obj = data[_i];
            var _length = $(_obj.Products).length;
            for (var _j = 0; _j < _obj.Products.length; _j++) {
                _html = _html + '<tr style="height:100%;border-bottom:1px solid #ccc;">\
             <td style="white-space: nowrap;vertical-align:top;padding-left:12px;height:100%;">' + _obj.Products[_j][0] + '</td>\
             <td style="vertical-align:top;padding-left:18px;height:100%;">' + _obj.Products[_j][1] + '</td>'

             if (displaycol.stock != 'none') { _html = _html + '<td style="vertical-align:top;text-align:center;height:100%;display:' + displaycol.stock + ';">' + _obj.Products[_j][2] + '</td>' };
             if (displaycol.instock != 'none') { _html = _html + '<td style="vertical-align:top;text-align:center;height:100%;display:' + displaycol.instock + ';">' + _obj.Products[_j][3] + '</td>' };
             if (displaycol.price != 'none') { _html = _html + '<td style="vertical-align:top;height:100%;display:' + displaycol.price + ';"> $' + _obj.Products[_j][4] + '</td>' };
             _html = _html + '<td style="white-space: nowrap;vertical-align:top;height:100%;">' + _obj.Products[_j][5] + '</td>';
             if (displaycol.custpart != 'none') { _html = _html + '<td style="white-space: nowrap;vertical-align:top;height:100%;display:' + displaycol.custpart + ';">' + _obj.Products[_j][6] + '</td>' };
             if (displaycol.buylink != 'none') { _html = _html + '<td style="vertical-align:top;height:100%;display:' + displaycol.buylink + ';">' + _obj.Products[_j][7] + '</td>' };
             _html = _html + '</tr>';
       
            }
        }
        _html = _html + '</table>';
        this.html(_html);
    } else {
        this.parent().css('display', 'none');
    }

}

function flipModel(current, list, accordion) {
    for (var _i = 0; _i < list.length; _i++) {
        if (list[_i].Id == current) {
            var _icons = $('.icon-set img[alt=' + list[_i].Id + ']');
            //_icons[0].src = '/images/model/' + list[_i].Enabled[0];
            _icons[1].src = '/images/model/' + list[_i].Enabled[1];
            $(accordion).accordion("activate", list[_i].Index);
        } else {
            var _icons = $('.icon-set img[alt=' + list[_i].Id + ']');
            //_icons[0].src = '/images/model/' + list[_i].Disabled[0];
            _icons[1].src = '/images/model/' + list[_i].Disabled[1];
        }
    }
}

$.fn.initIcon = function(data) {
    if (data.length == 0) {
        this.parent().css('display', 'none');
    }
}

function handleHover(object, cat, active) {
    if (active) {
        object.src = '/images/model/' + cat + '_btn.jpg?d=11910212001';
    } else {
        object.src = '/images/model/' + cat + '_btn_1.jpg?d=11910212001';
    }
}
