var colorpreview = document.getElementById('color-preview-32-3');
var colorselect = document.getElementById('option-32-3');

if(colorselect && colorpreview) {
	addEventSimple(colorselect, 'change', updateColor);
	colorpreview.style.border = '1px solid #000000';
	
	var color = colorselect.options[colorselect.selectedIndex].text;
	color = color.toLowerCase();
	var hex = checkColor(color)
	if(toString(hex) != false)
		colorpreview.style.backgroundColor = '#'+hex;

}

function updateColor() {
	var color = colorselect.options[colorselect.selectedIndex].text;
	color = color.toLowerCase();
	var hex = checkColor(color)
	if(hex != -1)
		colorpreview.style.backgroundColor = '#'+hex;
}

function checkColor(color) {
	var hex = -1;
	if(color.indexOf('atlantic') > -1) {
		hex = '7f9faa';
	}
	if(color.indexOf('black') > -1) {
		hex = '000000';
	}
	if(color.indexOf('blue') > -1) {
		hex = '7a8db5';
	}
	if(color.indexOf('chocolate') > -1) {
		hex = '63453d';
	}
	if(color.indexOf('cream') > -1) {
		hex = 'efefed';
	}
	if(color.indexOf('delft') > -1) {
		hex = '44679d';
	}
	if(color.indexOf('oatmeal') > -1) {
		hex = '7f6355';
	}						
	if(color.indexOf('sand') > -1) {
		hex = 'b0a796';
	}						
	if(color.indexOf('tarragon') > -1) {
		hex = '69775e';
	}						
	if(color.indexOf('terracotta') > -1) {
		hex = '68150d';
	}						
	if(color.indexOf('white') > -1) {
		hex = 'ffffff';
	}	
	if(color.indexOf('grape') > -1) {
		hex = '481a25';
	}	
	return hex;
}


function addEventSimple(obj,evt,fn) {
	if (obj.addEventListener)
		obj.addEventListener(evt,fn,false);
	else if (obj.attachEvent)
		obj.attachEvent('on'+evt,fn);
}

function removeEventSimple(obj,evt,fn) {
	if (obj.removeEventListener)
		obj.removeEventListener(evt,fn,false);
	else if (obj.detachEvent)
		obj.detachEvent('on'+evt,fn);
}

