Object.extend(Product.Config.prototype, {
	configureElementFromLink : function(element,attributeId,productId) {
			/*alert(element);
			alert(attributeId);
			alert(productId);*/
			element = $(element);
	        //this.reloadOptionLabels(element);
        	subatts = this.config.attributes[attributeId].options;
        	for(i=0; i<subatts.length; ++i) {
        		for(n=0;n<subatts[i].allowedProducts.length;++n) {
        			if(subatts[i].allowedProducts[n] == productId) {
        				newAttributeValue = subatts[i].id;
        			}
        		}
        	}
        				
            this.state[this.config.attributes[attributeId]] = newAttributeValue;
            element.value = newAttributeValue;
            if(element.nextSetting){
                element.nextSetting.disabled = false;
                this.fillSelect(element.nextSetting);
                this.resetChildren(element.nextSetting);
            }
	        this.reloadPrice();
	        swatchOver(productId);
	        setDescription(productId);
	        if($('qty')){
	        	setQty(productId);
	        }
	        $('addtocart-wrapper').show();
		}

	});
	
var original_product_image;

function swatchOver(productId) {
	original_product_image = $('mainimage').src;
	$('mainimage').src = $('image'+productId).src;
}
function swatchOut() {
	$('mainimage').src = original_product_image;
}
function setDescription(productId) {
	$('attribute-description').update($('desc'+productId).innerHTML);
}
function setQty(productId) {
	qty = parseInt($('qty'+productId).innerHTML);
	select = $('qty');
	select.update('');
	for (i=1;i<=qty;++i) {
		txt = "<option>"+i+"</option>";
		new Insertion.Bottom(select, txt);
	}
	var options = $$('select#qty option');
	options[0].selected = true;
}