//Globals
var timer;
var counter;
var currentTarget;
var useTimer = "no"; //Use of delay on menues yes/no
var delay = 1; //Seconds of delay
//NOTE! not working yet...

//Dropdown menu timer
function dropdownTimer(ident) {
 counter--;
 if (counter == 0) {
  window.clearInterval(timer);
  document.getElementById('submenu'+ident).style.visibility = 'hidden';
 }
}

//Dropdown menu
function dropdown(ident, type) {
 if (type == 'in') {
  if (useTimer == "yes") {
   window.clearInterval(timer);
   if (ident != currentTarget && currentTarget != null) {
    document.getElementById('submenu'+currentTarget).style.visibility = 'hidden';
   }
  }
  document.getElementById('submenu'+ident).style.visibility = 'visible';
 } else if (type == 'out') {
  if (useTimer == "yes") {
   counter = 1;
   timer = window.setInterval("dropdownTimer('"+ident+"')", 1000);
   currentTarget = ident;
  } else if (useTimer == "no") {
   document.getElementById('submenu'+ident).style.visibility = 'hidden';
  }
 }
}

//Popup window for Image-Viewer
function openViewer(ident, lang, width, height) {
 window.open('viewer.php?lang='+lang+'&image='+ident+'&dims='+width+'x'+height,'Viewer','fullscreen = no, width = 640, height = 480, left = 64, top = 128, location = no, menubar = no, resizable = no, scrollbars = no, status = yes, titlebar = yes, toolbar = no');
}

//Image-Viewer controls
var scale = 1;
function scrollControl(axis, amount) {
 if (axis == "x") {
  document.getElementById('controlArea').scrollLeft += amount*scale;
 } else if (axis == "y") {
  document.getElementById('controlArea').scrollTop += amount*scale;
 }
}

//Ändrar bild storlek och scrollar
function resizeImage(ident, height, width, changeScale) {
 document.getElementById(ident).style.width = null;
 document.getElementById(ident).style.height = height;
  
 var x = document.getElementById('controlArea').scrollLeft;
 var y = document.getElementById('controlArea').scrollTop;
// scrollControl('x', Math.round((x*changeScale/scale)));
// scrollControl('y', Math.round((y/scale)*changeScale));
 scale = changeScale;
}

//Hover effect for Image-Viewer buttons
function flashRed(ident) {
 document.getElementById(ident).style.backgroundColor = "#AA2200";
}

//Restores color from hover effect
function restoreColor(ident) {
 document.getElementById(ident).style.backgroundColor = "#CCCCCC";
}
