Product.Config.prototype.currentAttributeOption = new Array();
Product.Config.prototype.fillSelect = function(element) {
        if (this.config.fillSelect===false) {
            return;
        }
        var attributeId = element.id.replace(/[a-z]*/, '');
        var options = this.getAttributeOptions(attributeId);
        this.clearSelect(element);
        element.options[0] = new Option(this.config.chooseText, '');

        var prevConfig = false;
        if(element.prevSetting){
            prevConfig = element.prevSetting.options[element.prevSetting.selectedIndex];
        }

        if(options) {
//            optionsPrices = new Array();
//            options.each(function(option) {
//                if (option.price) {
//                    optionsPrices[option.id] = option.price;
//                }
//            });
            var index = 1;
            for(var i=0;i<options.length;i++){
                var allowedProducts = [];
                if(prevConfig && prevConfig.config) {
                    for(var j=0;j<options[i].products.length;j++){
                        if(prevConfig.config.allowedProducts
                            && prevConfig.config.allowedProducts.indexOf(options[i].products[j])>-1){
                            allowedProducts.push(options[i].products[j]);
                        }
                    }
                } else {
                    allowedProducts = options[i].products.clone();
                }

                if(allowedProducts.size()>0){
                    options[i].allowedProducts = allowedProducts;
                    element.options[index] = new Option(this.getOptionLabel(options[i], options[i].price), options[i].id);
                    element.options[index].config = options[i];

                    // the only custom line added in this method:
                    if ($('attribute' + attributeId + '-option' + options[i].id)) {
                        $('attribute' + attributeId + '-option' + options[i].id).show();
                    }
                    
                    index++;
                }

                config = this.config;
                var pConfig = this;
                if ($('attribute' + attributeId + '-option' + options[i].id)) {
                    if(this.config.outOfStockOptions[attributeId] && this.config.outOfStockOptions[attributeId].indexOf(options[i].id) != -1 ) {
                        var simpleProductId = options[i].products[0];
                        jQuery('#attribute' + attributeId + '-option' + options[i].id + ' a').tooltip({
                                top: -42,
                                left: 0,
                                delay: 0,
                                showURL: false,
                                opacity: 0.85,
                                bodyHandler: function() {
                                    // change link to alert subscription dynamically
                                    var hrefTemp = jQuery("#stock_alert_a").attr('href');
                                    var hrefTempArray = hrefTemp.split('/');
                                    var i;
                                    var fineFlag = false;
                                    for(i=0; i<hrefTempArray.length; i++) {
                                        if(hrefTempArray[i] == 'product_id') {
                                            fineFlag = true;
                                            break;
                                        }
                                    }
                                    if(fineFlag) {
                                        hrefTempArray[++i] = simpleProductId; // configurable id
                                        var hrefNew = hrefTempArray.join('/');
                                        jQuery("#stock_alert_a").attr('href', hrefNew);
                                    }
                                    return jQuery("#sizeOutOfStockInfo").html();
                                }
                            });
//                        $('attribute' + attributeId + '-option' + options[i].id).observe('mouseover', function(event) {
//                            jQuery('attribute' + attributeId + '-option' + options[i].id).tooltip({
//                                top: -65,
//                                left: 1,
//                                delay: 0,
//                                showURL: false,
//                                opacity: 0.85,
//                                bodyHandler: function() {
//                                    return jQuery("#sizeOutOfStockInfo").html();
//                                }
//                            });
//                        });
                        $('attribute' + attributeId + '-option' + options[i].id).addClassName('disabled').observe('click', function(event) {   
                            event.preventDefault();
                        }); 
                    }  
                    else {
                        $('attribute' + attributeId + '-option' + options[i].id).observe('click', function(event) {
                            optionId = this.id.split('-')[1].replace('option', '');
                            pConfig.setAttributeOption(attributeId, optionId);
//                            if (optionsPrices[optionId]) {
//                                price = new Number(optionsPrices[optionId]).toFixed(2).replace('.', ',');
//                            } else {
//                                price = new Number(0).toFixed(2).replace('.', ',');
//                            }
//                            price = config.template.replace('#{price}', price);
                            pConfig.reloadPrice();
//                            if ($$('div.product-main-info div.price-box').length > 0) {
//                                $$('div.product-main-info div.price-box')[0].update('<span class="price">'+price+'</span>');
//                            }
//                            if ($$('div.product-options-container div.price-box').length > 0) {
//                                $$('div.product-options-container div.price-box')[0].update('<span class="price">'+price+'</span>');
//                                if ($$('div.product-selected-options div.price-box').length > 0) {
//                                    $$('div.product-selected-options div.price-box')[0].update('<span class="price">'+price+'</span>');
//                                }
//                            }
                            event.preventDefault();
                        });            
                    } 
                }        
            }
            /*if (this.config.outOfStockOptions[attributeId] && $$('#attribute' + attributeId + '-option' + this.config.outOfStockOptions[attributeId][0]).length > 0) {
                $$('#attribute' + attributeId + '-option' + this.config.outOfStockOptions[attributeId][0]).each(function(elem) {
                    elem.addClassName('disabled');
                });
            }*/
//            price = new Number(0).toFixed(2).replace('.', ',');
//            price = config.template.replace('#{price}', price);
        }
    }
//Product.Config.prototype.initializeCustomSelector = function() {
//    var x;
//    for (x in this.config.attributes) {
//        this.config.attributes[x].options.each(function(option) {
//                $('attribute' + x + '-option' + option.id).show();
//                this.currentAttributeOption[x] = 0;
//            }.bind(this)
//        );
//    }
//}
Product.Config.prototype.setAttributeOption = function(attribute_id, option_id) {
    if (this.currentAttributeOption[attribute_id]) {
        var previousOption = $('attribute' + attribute_id + '-option' + this.currentAttributeOption[attribute_id]);
        if (previousOption && previousOption.hasClassName('active')) {
            previousOption.removeClassName('active');
        }
    }

    this.currentAttributeOption[attribute_id] = option_id;

    var currentOption =  $('attribute' + attribute_id + '-option' + option_id);
    if (currentOption) {
        currentOption.addClassName('active');
    }
    $('attribute' + attribute_id).setValue(option_id);

    return false;
}

Product.Config.prototype.setAttributeOptionMultiple = function(attribute_id, option_id, product_id) {
    /*if (this.currentAttributeOption[attribute_id]) {
        var previousOption = $('attribute' + attribute_id + '-option' + this.currentAttributeOption[attribute_id]);
        if (previousOption && previousOption.hasClassName('active')) {
            previousOption.removeClassName('active');
        }
    }*/

    this.currentAttributeOption[attribute_id] = option_id;

    /*var currentOption =  $('attribute' + attribute_id + '-option' + option_id);
    if (currentOption) {
        currentOption.addClassName('active');
    }*/
    $$('#product_addtocart_form-'+product_id+' .attribute' + attribute_id)[0].setValue(option_id);

    return false;
}


