  //pre-load med(ium) images
  var images = new Array();
  var image;
  for (var i = 1; i <= 10; i++) {
	  image = new Image();
	  image.src = "med/frontpage" + i + "_med.jpg";
	  images[i] = image;
  }
  
  //captions
  
  var captions = { _1 : "hand-dyed shibori silk chiffon kimono constructed/finished with viscose/silk thread 35x52&quot;",
  					_2 : "hand-dyed shibori silk organza wrap with detailed stitching using viscose/silk thread 18x88x1&quot;",
  					_3 : "hand-dyed shibori silk wrap finished with viscose/silk thread 26x88&quot;",
  					_4: "hand-dyed shibori silk organza wrap with detailed stitching using metallic filament thread 18x88x1&quot;",
					_5: "hand-dyed shibori silk organza wrap with detailed stitching using viscose/silk thread 18x88x1&quot;",
					_6: "hand-dyed shibori silk chiffon scarf with detailed stitching using viscose/silk thread 16x60&quot;",
					_7: "stitched shibori metallic polyester organza wrap gathered, heat-set and finished with polyester thread 17x84x2.5&quot;"};
  					
  var captionExists = false;
  
  function swapPic(e) {
	  var divOrImg;
	  if (!e.target) {
		  e = event;
		  divOrImg = event.srcElement;
	  } else {
		divOrImg = e.target;
	  }
	  var imgLoc;
	  if (divOrImg.tagName.indexOf("DIV") != -1) {
	  	imgLoc = divOrImg.getElementsByTagName("img")[0].src;
	  } else {
	  	imgLoc = divOrImg.src;
	  }
	  divOrImg.className='pointer';
	  var newImgLoc = imgLoc.replace(/thumb/g, "med");
	  var pic = document.getElementById("mainPic").getElementsByTagName("img")[0];
	  pic.src = newImgLoc;
	  if (captionExists) swapCaption(pic.src.replace(/[^0-9]+([0-9]+)\_.*/, "$1"));
  }
  
  function swapMainIn(e) {
  	  document.getElementById("mainPic").getElementsByTagName("img")[0].src = "med/frontpage1_med.jpg";
  	  //if(captionExists) swapCaption(1);
  	  document.getElementById("caption").innerHTML = "";
  }
	  

  function addImgEventListeners(img, func1, func2, func3) {
	  try {
		  img.addEventListener("mouseover", func1, false);
		  img.addEventListener("mouseout", func2, false); 
		  img.addEventListener("click", func3, false);
	  } catch (err) {
		  img.attachEvent("onmouseover", func1);
		  img.attachEvent("onmouseout", func2);
		  img.attachEvent("onclick", func3);
	  }
  }

  function onLoad() {
	  //var i = 0;
	  //i = i + 1;
	  if (document.getElementById("caption")) {
	  	captionExists = true;
	  }
	  var thumbsDiv = document.getElementById("thumbs");
	  var divImgs = thumbsDiv.getElementsByTagName("div");
	  for (var i = 0; i < divImgs.length; i++) {
		  var imgs = divImgs[i].getElementsByTagName("img");
		  var img = imgs[0];
		  addImgEventListeners(divImgs[i], swapPic, swapMainIn, viewBig);
		  addImgEventListeners(img, swapPic, swapMainIn, viewBig);
	  }
  }

  function viewBig(e) {
	  var divOrImg;
	  if (!e.target) {
		  e = event;
		  divOrImg = event.srcElement;
	  } else {
		divOrImg = e.target;
	  }
	  var imgLoc;
	  if (divOrImg.tagName.indexOf("DIV") != -1) {
	  	imgLoc = divOrImg.getElementsByTagName("img")[0].src;
	  } else {
	  	imgLoc = divOrImg.src;
	  }  
	  var newLoc = imgLoc.replace(/thumb/g, "large");
	  window.open(newLoc, "large", "toolbar=no, menubar=no, status=no, width=701px, height=945px, scrollbars=yes");
  }
  function viewMainBig() {
  	  var newLoc = document.getElementById("mainPic").getElementsByTagName("img")[0].src.replace(/med/g, "large");
	  window.open(newLoc, "large", "toolbar=no, menubar=no, status=no, width=701px, height=945px, scrollbars=yes");
 }
  function show(elem) {
    elem.style.display="block";
  }
  function hide(elem) {
    elem.style.display="none";
  }
  
  function swapCaption(num) {
  	document.getElementById("caption").innerHTML = eval("captions._" + num);
  }