﻿// popups a new window for provided file
function popWindow(directory, index, width, height) {
  newWindow = window.open('popup_gray.php?directory='+directory+'&index='+index,'newWindow'+getRandom(),'toolbar=no,menubar=no,resizable=yes,scrollbars=yes,status=no,dependent=yes,width='+width+',height='+height+',top='+(screen.height-height)/2+',left='+(screen.width-width)/2);
  newWindow.focus();
}

// popups a new window for provided file at maximal screen size
function popWindowMax(directory, index) {
  newWindow = window.open('popup_gray.php?directory='+directory+'&index='+index,'newWindow'+getRandom(),'toolbar=no,menubar=no,resizable=yes,scrollbars=yes,status=no,dependent=yes,width='+screen.width+',height='+screen.height+',top=0,left=0');
  newWindow.focus();
}

// popups a new window for slideshow at maximal screen size
function popSlideshowMax(selection) {
  newWindow = window.open('slideshow_gray.php?selection='+selection,'newWindow'+getRandom(),'toolbar=no,menubar=no,resizable=yes,scrollbars=yes,status=no,dependent=yes,width='+screen.width+',height='+screen.height+',top=0,left=0');
  newWindow.focus();
  }

// popups a new window for provide file at max screen size
function popWindowFileMax(file) {
  newWindow = window.open(file,'newWindow','toolbar=no,menubar=no,resizable=yes,scrollbars=yes,status=no,dependent=yes,width='+screen.width+',height='+screen.height+',top=0,left=0');
}

// popups a window for provided file
function popWindowFile(file, width, height) {
  newWindow = window.open(file,'newWindow','toolbar=no,menubar=no,resizable=yes,scrollbars=yes,status=no,dependent=yes,width='+width+',height='+height+',top='+(screen.height-height)/2+',left='+(screen.width-width)/2);
  // set location in case window is reused
  newWindow.moveTo((screen.width-width)/2, (screen.height-height)/2);
  newWindow.resizeTo(width, height);
  newWindow.focus();
}

// popups a window for provided file at a specific x, y location
function popWindowFileXY(file, w, h, x, y, n) {
  newWindow = window.open(file,'newWindow'+(n==null?0:n),'toolbar=no,menubar=no,resizable=yes,scrollbars=yes,status=no,dependent=yes,width='+w+',height='+h+',top='+y+',left='+x);
  // set location in case window is reused
  newWindow.moveTo(parseInt(x), parseInt(y));
  newWindow.resizeTo(parseInt(w), parseInt(h));
  newWindow.focus();
}

// popups a window for provided file at a specific x, y location; x is distance from middle
function popWindowFileXYMiddle(file, w, h, x, y, n) {
  newWindowX = window.open(file,'newWindow'+(n==null?0:n),'toolbar=no,menubar=no,resizable=yes,scrollbars=yes,status=no,dependent=yes,width='+w+',height='+h+',top='+y+',left='+((screen.width/2)+parseInt(x)));
  // set location in case window is reused
  newWindowX.moveTo((screen.width/2)+parseInt(x), parseInt(y));
  newWindowX.resizeTo(parseInt(w), parseInt(h));
  newWindowX.focus();
}

// maximizes a window
function maximize() {
  if ((document.body.clientWidth < screen.availWidth)/* || (document.body.clientHeight < screen.availHeight)*/) {
    window.moveTo(0,0);
    window.resizeTo(screen.availWidth, screen.availHeight);
  }
}

// gets a random number of window naming
function getRandom() {
  return (Math.round((Math.random() * 1000) + 1));
}
