// Gallery --------------------------------------------------
var currentId = 1;
function showElement(inId) {
  // Do elements
  document.getElementById("galleryElement" + currentId).style.display = "none";
  document.getElementById("galleryElement" + inId).style.display = "block";
  
  // Do links
  document.getElementById("galleryLink" + currentId).className = "";
  document.getElementById("galleryLink" + inId).className = "selected";

  // Keep id  
  currentId = inId;
}

function nextElement(inTotal) {
  showElement((currentId + 1 > inTotal)?(1):(currentId + 1));
}

function lastElement(inTotal) {
  showElement((currentId - 1 < 1)?(inTotal):(currentId - 1));
}


// Image swapping -------------------------------------------
function swap(inObj, inSrc) {
  
  if (typeof(inObj) != "object") {
    inObj = document.getElementById(inObj);
  }

  if (inSrc) {
    inObj.defaultSrc = inObj.src;
    inObj.src        = inSrc;
  } else {
    inObj.src        = inObj.defaultSrc;
  }
}


// Form checking --------------------------------------------
function checkNumbers(inObj) {
  inObj.value = parseInt(inObj.value);
  if (isNaN(inObj.value)) {
    inObj.value = "";
  }
}


// Popups ---------------------------------------------------
function popWin(inUrl, inWidth, inHeight) {
  var w = window.open(inUrl, "", "width="+inWidth+",height="+inHeight+",location=no,toolbar=no,menubar=no,status=no,scrollbars=yes");
}


// Emails --------------------------------------------------
function mailto(inEmail) {
  location.href="mailto:" + reverse(inEmail);
}

function reverse(inText) {
  var outText = "";
  for (var i=inText.length-1; i>=0; i--) {
    outText+= inText.substr(i,1);;
  }
  return outText;
}
