
// **************************************************************
// **
// **     	VARS
// **
// **************************************************************

var selected_color_num = '';

// **************************************************************
// **
// **     	color_menu_click
// **
// **************************************************************

function color_menu_click(num,debug){
	
	// if the id is a new one
	if(num != selected_color_num){
		
		// check color menu element
		var color_menu_elm = false;
		if(!(color_menu_elm = getObj('color_menu_item_'+num)) && debug){
			alert('color_menu_click(): color menu element not found!');
		}
		
		// check your color element
		var your_color_elm = false;
		if(!(your_color_elm = getObj('your_color')) && debug){
			alert('color_menu_click(): your color element not found!');
		}
		
		// check color value element
		var color_value_elm = false;
		if(!(color_value_elm = getObj('color_value_'+num)) && debug){
			alert('color_menu_click(): color value element not found!');
		}
	
		// check price value element
		var price_value_elm = false;
		if(!(price_value_elm = getObj('price_value_'+num)) && debug){
			alert('color_menu_click(): price value element not found!');
		}
		
		// check image file value element
		var image_file_value_elm = false;
		if(!(image_file_value_elm = getObj('image_file_value_'+num)) && debug){
			alert('color_menu_click(): image file value element not found!');
		}
		
		// check image width value element
		var image_width_value_elm = false;
		if(!(image_width_value_elm = getObj('image_width_value_'+num)) && debug){
			alert('color_menu_click(): image width value element not found!');
		}
		
		// check image height value element
		var image_height_value_elm = false;
		if(!(image_height_value_elm = getObj('image_height_value_'+num)) && debug){
			alert('color_menu_click(): image height value element not found!');
		}
		
		// check color element
		var color_elm = false;
		if(!(color_elm = getObj('color')) && debug){
			alert('color_menu_click(): color send element not found!');
		}
	
		// check price send element
		var price_elm = false;
		if(!(price_elm = getObj('price')) && debug){
			alert('show_selected_elements(): price send element not found!');
		}

		// try to get image file element
		var image_file_elm = false;
		if(!(image_file_elm = getObj('image_file'))){
			alert('check_enable_cart(): image file send element not found!');
		}

		// try to get image width element
		var image_width_elm = false;
		if(!(image_width_elm = getObj('image_width'))){
			alert('check_enable_cart(): image width send element not found!');
		}

		// try to get image height element
		var image_height_elm = false;
		if(!(image_height_elm = getObj('image_height'))){
			alert('check_enable_cart(): image height send element not found!');
		}
		
		// try to reset the selected element
		if(selected_color_num != ''){
		
			// check selected element
			var selected_color_menu_elm = false;
			if(!(selected_color_menu_elm = getObj('color_menu_item_'+selected_color_num)) && debug){
				alert('color_menu_click(): selected element not found!');
			}
			
			// reset previous selected 
			if(
				selected_color_menu_elm && 
				selected_color_menu_elm.className.indexOf('selected') != -1 
			){
				selected_color_menu_elm.className = 'default';
			}
		}
		
		// try to initiate image fader
		if(typeof flip_color != 'function' && debug){
			alert('color_menu_click(): flip_color funtion not found!');
		}else{
			flip_color(num,debug);
		}
	
		// set header class
		if(
			color_menu_elm && 
			color_menu_elm.className.indexOf('selected') == -1
		){
			color_menu_elm.className = 'selected';
		}
	
		// set selected num & your color value
		if(
			color_value_elm.innerHTML != '' &&
			your_color_elm 
		){
			selected_color_num = num;
			your_color_elm.innerHTML = color_value_elm.innerHTML;
		}
		
		// set send values
		if(
			your_color_elm  &&
			price_value_elm &&
			image_file_value_elm &&
			image_width_value_elm &&
			image_height_value_elm &&
			your_color_elm.innerHTML != '' &&
			price_value_elm.innerHTML != ''&&
			image_file_value_elm.innerHTML != '' &&
			image_width_value_elm.innerHTML != '' &&
			image_height_value_elm.innerHTML != '' &&
			color_elm &&
			price_elm &&
			image_file_elm &&
			image_width_elm &&
			image_height_elm
		){
			color_elm.value = color_value_elm.innerHTML;
			price_elm.value = price_value_elm.innerHTML;
			image_file_elm.value = image_file_value_elm.innerHTML;
			image_width_elm.value = image_width_value_elm.innerHTML;
			image_height_elm.value = image_height_value_elm.innerHTML;
		}else if(debug){
			alert('color_menu_click(): could not set color, price or image send value!');
		}
		
		// try to enable the shopping cart
		if(typeof check_enable_cart != 'function' && debug){
			alert('color_menu_click(): check_enable_cart funtion not found!');
		}else{
			check_enable_cart(debug);
		}
	}
}



