/* SkuChanger by Kamil Witecki */

addLoadEvent(initSkuChanger);

function initSkuChanger() {
	var select = document.getElementById('cartSize');
	if(!select) {
		return;
	}
	var SkuChangerInstance = new SkuChanger(select);
	SkuChangerInstance.hideAll();
}

function SkuChanger(select) {
	var functions = new Array();
	var skus = new Array();
	var that = this;
	for(var i=0; i<select.options.length; i++) {
		skus.push(new Sku(select.options[i]));
		skus[i].SkuChanger = this;
		functions.push(function(index) {
			that.hideAll();
			skus[index].show();
		});
	}
	this.skus = skus;
	
	this.dl = document.getElementById('skuList');
	
	select.onchange = function() {
		functions[this.selectedIndex](this.selectedIndex);
	};
}



SkuChanger.prototype.hideAll = function() {
	for(var i=1; i<this.skus.length; i++) {
		this.skus[i].hide();
	}
	//this.dl.style.display = 'none';
	this.dl.getElementsByTagName('dt')[0].style.color = '#ffffff';
	this.dl.getElementsByTagName('dd')[0].style.color = '#ffffff';
}

SkuChanger.prototype.Show = function() {
	//this.dl.style.display = 'inline';
	this.dl.getElementsByTagName('dt')[0].style.color = '#777777';
	this.dl.getElementsByTagName('dd')[0].style.color = '#777777';
}

function Sku(option) {
	this.span = document.getElementById('sku_' + option.value);
}

Sku.prototype.hide = function() {
	if(!this.span) {
		return;
	}
	this.span.style.display = 'none';
}

Sku.prototype.show = function() {
	if(!this.span) {
		return;
	}
	this.span.style.display = 'inline';
	this.SkuChanger.Show();
}
