 function changeTab(img_num, wrapper) {
    var imgs = document.getElementById(wrapper).getElementsByTagName("img");
    for(var i=0; i < imgs.length; i++) {
      if(imgs[i].src.indexOf("on.jpg") != -1 && img_num != i) {
        imgs[i].src = imgs[i].src.replace("on.jpg","off.jpg");
        document.getElementById(wrapper+"_tab"+i).style.display = "none";
      }
      if(img_num == i) {
        if(imgs[i].src.indexOf("off.jpg") != -1) {
          imgs[i].src = imgs[i].src.replace("off.jpg","on.jpg");
          document.getElementById(wrapper+"_tab"+i).style.display = "block";
        }
      }
    }
  }
function checkForm() {
    var obj = document.getElementById("colors");
    if(obj && obj.selectedIndex == 0) { alert("Please make a size selection"); return false; }
    if(/^-?\d+$/.test(document.getElementById("qty").value)) {
      return true;
    } else {
      alert("Please enter in a valid quantity");
      return false;
    }
  }
  function changeBox(sel) {
    var sel = document.getElementById("colors");
    document.getElementById("qty").name = sel[sel.selectedIndex].value;
  }

function slider(container,items_show,item_width,item_height,increment,speed,slide) {
  this.container = document.getElementById(container);
  this.num_items = this.pointer = this.borders = 0;
  this.items = new Array();
  this.item_width = item_width;
  this.item_height = item_height;
  this.top = this.right = this.bottom = this.left = 10;
  this.content_top = this.content_right = this.content_bottom = this.content_left = 10;
  this.items_show = items_show;
  this.slide = slide;
  this.setContentPadding = function(top,right,bottom,left) {
    this.content_top = top;
    this.content_right = this.right = right;
    this.content_bottom = bottom;
    this.content_left = this.left = left;
  };
  this.setContainerPadding = function(top,bottom) {
    this.top = top;
    this.bottom = bottom;
  };
  this.turnOnBorders = function() { this.borders = 1; };
  this.configureSlider = function() {
    this.container.style.width = (this.items_show*(this.item_width + this.content_left + this.content_right + 2*this.borders))+"px";
    this.container.style.height = (this.item_height + this.content_top + this.content_bottom + 2*this.borders)+"px";
    this.container.style.padding = this.top + "px " + this.right + "px " + this.bottom + "px " + this.left+"px";
    for(i = 0; i < this.num_items; i++) {
      obj = this.items[i];
      obj.style.top = (this.top + this.content_top + this.borders)+"px";
      obj.style.left = (this.left + this.content_left + i*(this.item_width+this.content_right+this.content_left+2*this.borders))+"px";
      this.container.appendChild(obj);
    }
    document.getElementById("slider_left_button").className= this.num_items > this.items_show ? "visible" : "faded";
    document.getElementById("slider_right_button").className="faded";
  };
  this.addImage = function(img_src) {
    var img = document.createElement("img");
    img.src = img_src;
    img.style.position = "absolute";
    if(this.borders != 0) { img.style.border = "1px solid #CCCCCC"; }
    this.items[this.num_items++] = img;
  };
  this.addElement = function(obj) { 
    obj.style.position = "absolute";
    this.items[this.num_items++] = obj;
  };
  this.slide = function(dir) {
    if((this.pointer >= this.num_items-this.items_show && dir =="left") || (this.pointer <= 0 && dir == "right")) { return false; } 
    if(dir=="left") {
      this.pointer = this.pointer + slide;
      document.getElementById("slider_right_button").className="visible";
    } else if(dir=="right") {
      this.pointer = this.pointer - slide;
      document.getElementById("slider_left_button").className="visible";
    }
    for(var j=0; j < slide*(this.item_width + this.content_left + this.content_right + 2*this.borders)/increment; j++) {
      var items = this.items;
      var f = function() { slideItem(items,increment,dir)};
      setTimeout(f,200+speed*j);
    }
    if(this.pointer >= this.num_items-this.items_show && dir =="left") {
      document.getElementById("slider_left_button").className="faded";
    } 
    if(this.pointer <= 0 && dir == "right") { 
       document.getElementById("slider_right_button").className="faded";
    } 
  };
}
function slideItem(items,amount,dir) {
  for(i=0; i < items.length; i++) {
    var item = items[i];
    var left = parseInt(item.style.left.replace("px",""));
    item.style.left = (dir == "left" ? (left - amount)+"px" : (left + amount)+"px");
  }
}