/*
 * jscript_attrib_color.js - Changes colors of images for attributes
 * Created by jstephens on Wed Jun 20 11:03:07 MDT 2007
 * Copyright 2007 Heritage Web Solutions
 * Requres Prototype
 */

var attrib_color_image_element;
var attrib_color_name_element;
var attrib_color_link_base;

function init_attrib_color_selection()
{
   var items = document.getElementsByClassName("attribColorImg",$('attribColorContainer'));
   for(i=0,m=items.size();i<m;++i) {
      var id = items[i].id.match(/attrib_color_(\d+)/);
      items[i].onmouseover = attrib_color_show_this;
      items[i].onclick = attrib_color_select;
      items[i].onmouseout = attrib_color_show_selected;
   }

   attrib_color_image_element = $('productImageImage');
   attrib_color_name_element = $('attribColorName');
   attrib_color_show_selected();
   for(i=0,m=attrib_color_list.size();i<m;++i) {
      //do some prefetching
      if(attrib_color_list[i] != undefined) {
         attrib_color_list[i].img_el = new Image;
         attrib_color_list[i].img_el.src = attrib_color_list[i].img;
      }
   }
}



function attrib_color_show_selected()
{
 var id = $('colorAttribHiddenInput').value;
 attrib_color_image_element.src = attrib_color_list[id].img;
 if(this.oldclassname != undefined) this.className = this.oldclassname;
 else {
    var el = $('attribColor' + id);
    el.className = el.oldclassname = "attribColorImg attribColorImgSelected";
 }

 attrib_color_name_element.innerHTML = attrib_color_list[id].name;
 attrib_color_name_element.className = "attribColorText";

 var bigger_image_href = attrib_color_link_base + '&products_image_large_additional=' + attrib_color_list[id].img_orig;
 eval("$('productImageLink').onclick = function () {return popupWindow('" + bigger_image_href + "'), false;}");
 $('productImageLink').href = bigger_image_href;
}

function attrib_color_select()
{
 var old_el = $('attribColor' + $('colorAttribHiddenInput').value);
 var id = this.id.match(/attribColor(\d+)/)[1];
 $('colorAttribHiddenInput').value = id;

 old_el.className = "attribColorImg";
 this.oldclassname = this.className = "attribColorImg attribColorImgSelected";
}

function attrib_color_show_this()
{
 var id = this.id.match(/attribColor(\d+)/)[1];
 attrib_color_image_element.src = attrib_color_list[id].img;
 this.oldclassname = this.className;
 this.className = "attribColorImg attribColorImgHover";

 attrib_color_name_element.innerHTML = attrib_color_list[id].name;
 attrib_color_name_element.className = "attribColorTextHover";
}