// ---------------------------------------------------------------------------
// SingleOptionSelector
// takes option name and values and creates a option selector from them
// ---------------------------------------------------------------------------
Shopify.SingleOptionSelector = function(multiSelector, index, name, values) {
  //alert('multiSelector:'+multiSelector +' index:'+index+' name:'+name+' values:'+values)
  this.multiSelector = multiSelector;
  this.values = values;
  this.index = index;
  this.name = name;
  this.element = document.createElement('ul');
  for (var i = 0; i < values.length; i++) {
	var li = document.createElement('li');
    var opt = document.createElement('a');
    //opt.value = values[i];
	opt.setAttribute("value", values[i]);
	opt.innerHTML = values[i];
	
	opt.onclick = function() {
		var variantParent = this.parentNode.parentNode;
		
		for (var i = 0; i < variantParent.childNodes.length; i++) {
			variantParent.childNodes[i].childNodes[0].setAttribute('class', "");
		}
		this.setAttribute('class', "active");
		
		variantParent.setAttribute('current', this.getAttribute('value'));
		multiSelector.updateSelectors(index);
	}
	li.appendChild(opt);
	this.element.appendChild(li);
  }
  this.element.setAttribute('class', this.multiSelector.selectorClass);
  this.element.id = multiSelector.domIdPrefix + '-option-' + index;
 
 // this is needed for the initial setting of the options
  this.element.initOption = function() {
	this.childNodes[0].childNodes[0].onclick();
  }

  this.element.onchange = function() {}

  return true;
};  


Shopify.OptionSelectors.prototype.initOptions = function() {
  for (var i = 0; i < this.selectors.length; i++) {
	  this.selectors[i].element.initOption();     // init the new dropdown
  }
  return true;
};


// returns array of currently selected values from all multiselectors
Shopify.OptionSelectors.prototype.selectedValues = function() {
  var currValues = [];
  for (var i = 0; i < this.selectors.length; i++) {
    var thisValue = this.selectors[i].element.getAttribute('current');
    currValues.push(thisValue);
  }
  return currValues;
};