function openNewWindow(url,windowName,windowFeatures) {
  popup=window.open(url,windowName,windowFeatures);
  popup.focus();
}

function popupWindow(filepath) {
  openNewWindow(filepath,'TShirtProjectPopUp','width=432,height=432,directories=no,location=no,menubar=no,resizable=yes,scrollbars=no,status=no,toolbar=no');
}

function preloadimages(arr) {
  var image;
  for(var k=0;k<arr.length;k++) {
    image = new Image();
    image.src = arr[k];
    arr[k] = image;
  }
}

function swapimages(theinterval) {

  var count = 0;
  var interval = theinterval;
  var image = document.images["theimage"];
  var link=document.getElementById('thelink');

  if (link!=null) {
    link = document.getElementById('thelink');
  } 

  rotate=1;

  setInterval(repeat,interval);

  function repeat() {
    if (rotate==1) {
      count = (count+1)%images.length;
      image.src = images[count].src;
      if (link!=null) {
        link.href = links[count];
      }
    }
  }
}

function showLayer(n) {
  ns4 = (document.layers) ? true:false 
  ie4 = (document.all) ? true:false 
  ng5 = (document.getElementById) ? true:false 

  if (ng5) {
    document.getElementById('layer' + n).style.visibility = "visible"; 
  } else if (ns4) {
    document.layers["layer" + n].visibility = "show"; 
  } else if (ie4) {
    document.all["layer" + n].style.visibility = "visible"; 
  }
}

function hideLayer(n) {
  ns4 = (document.layers) ? true:false 
  ie4 = (document.all) ? true:false 
  ng5 = (document.getElementById) ? true:false 

  if (ng5) {
    document.getElementById('layer' + n).style.visibility = "hidden"; 
  } else if (ns4) {
    document.layers["layer" + n].visibility = "hide"; 
  } else if (ie4) {
    document.all["layer" + n].style.visibility = "hidden"; 
  }
}

function displayNextImage(count) {
  var image = document.images["theimage"];
  var link = document.getElementById('thelink');

  count = (count+1)%images.length;
  image.src = images[count].src;
  link.href = links[count];
}

function displayPreviousImage(count) {
  var image = document.images["theimage"];
  var link = document.getElementById('thelink');
  count = (count-1)%images.length;
  image.src = images[count].src;
  link.href = links[count];
}

function displayNextShirt(count,imgid) {
  var image = document.getElementById(imgid);
  count = (count+1)%shirt_images.length;
  image.src = shirt_images[count].src;
}

function displayNextPrint(count,imgid) {
  var image = document.getElementById(imgid);
  count = (count+1)%print_images.length;
  image.src = print_images[count].src;
}

function displayPreviousShirt(count,imgid) {
  var image = document.getElementById(imgid);
  count = (count-1)%shirt_images.length;
  image.src = shirt_images[count].src;
}

function displayPreviousPrint(count,imgid) {
  var image = document.getElementById(imgid);
  count = (count-1)%print_images.length;
  image.src = print_images[count].src;
}

function catalogue_displayNextImage(count) {
  var image = document.images["theimage"];
  var link = document.getElementById('thelink');
  var nextlink = document.getElementById('NextLink');
  var previouslink = document.getElementById('PreviousLink');

  count = (count+1)%images.length;
  image.src = images[count].src;
  nextlink.href = "javascript: displayNextImage("+count+");";
  previouslink.href = "javascript: displayPreviousImage("+count+");";
  link.href = links[count];
  if (count>0) {
    // show Previous Image Link
    showLayer(0);
  } else {
    hideLayer(0);
  }
  if (count<(images.length-1)) {
    // show Next Image Link
    showLayer(1);
  } else {
    hideLayer(1);
  }
}

function catalogue_displayPreviousImage(count) {
  var image = document.images["theimage"];
  var link = document.getElementById('thelink');
  var nextlink = document.getElementById('NextLink');
  var previouslink = document.getElementById('PreviousLink');

  count = (count-1)%images.length;
  image.src = images[count].src;
  nextlink.href = "javascript: displayNextImage("+count+");";
  previouslink.href = "javascript: displayPreviousImage("+count+");";
  link.href = links[count];
  if (count>0) {
    // show Previous Image Link
    showLayer(0);
  } else {
    hideLayer(0);
  }
  if (count<(images.length-1)) {
    // show Next Image Link
    showLayer(1);
  } else {
    hideLayer(1);
  }
}

function stopimages() {
  rotate=0;
  var image = document.images["stop-start_button"];
  image.src = "/images/navigation/play.jpg";
  image.alt = "Play";
}

function rotateimages() {
  rotate=1;
  var image = document.images["stop-start_button"];
  image.src = "/images/navigation/stop.jpg";
  image.alt = "Stop";
}

function stopstartimages() {
  var image = document.images["stop-start_button"];
  if (image.src.indexOf("/images/navigation/play.jpg") != -1) {
    rotateimages();
  } else {
    stopimages();
  }
}