// gedicht.js uses popupData[6] and therefore depends on this order
   var popupData = [
      { file: 'archief',        width: 700, height: 450 },
      { file: 'bibliotheek',    width: 290, height: 600 },
      { file: 'blad',           width: 770, height: 484 },
      { file: 'colofon',        width: 470, height: 250 },
      { file: 'gebarencolofon', width: 400, height: 200 },
      { file: 'gebarenwinkel',  width: 560, height: 470 },
      { file: 'gedicht',        width: 440, height: 280 },
      { file: 'hoorspelen',     width: 400, height: 390 },
      { file: 'kbw' ,           width: 430, height: 150 },
      { file: 'kist',           width: 490, height: 384 },
      { file: 'knipsels',       width: 600, height: 450 },
      { file: 'mailform',       width: 560, height: 400 },
      { file: 'perpetuum',      width: 700, height: 550 },
      { file: 'programma',      width: 490, height: 384 },
   // 'subs' == sponsors but using that word the file gets blocked by certain adblockers
      { file: 'subs',           width: 500, height: 444 },
//      { file: 'studio',         width: 250, height: 216 },
      { file: 'studio',         width: 800, height: 600 },
      { file: 'uitleg',         width: 550, height: 400 },
      { file: 'verhaal',        width: 700, height: 450 },
      { file: 'spel',           width: 800, height: 600 }
   ];

function popup(event, reqFile)
{
   for (var i = 0; i < popupData.length; i++)
   {
   // trim path prefix and '.html' suffix which are needed in window.open call
      var testReqFile = reqFile.substr(reqFile.lastIndexOf('/') + 1, popupData[i].file.length);
      if ((reqFile.match(popupData[i].file))
      &&  (reqFile.substr(reqFile.indexOf(popupData[i].file), testReqFile.length) == popupData[i].file))
      {
         var w = popupData[i].width;
         var h = popupData[i].height;
         if (BrowserDetect.browser == 'chrome')
            h += 62;
         break;
      }
   }

// blad9 is a special case and self.resize won't work
   if (reqFile.match(/route9/))
   {
      w = 800;
      h = 600;
      if (BrowserDetect.browser == 'chrome')
         h += 62;
   }

// set size for all windows spawned from orgs menu here
   if (reqFile.match(/orgs/))
   {
      w = 430;
      h = 150;
      if (BrowserDetect.browser == 'chrome')
         h += 62;
   }

   var x = (top.BrowserDetect.browser == 'opera' ? top.innerWidth  - w : screen.width  - w) / 2;
   var y = (top.BrowserDetect.browser == 'opera' ? top.innerHeight - h : screen.height - h) / 2;

   var temp = window.open(reqFile, '', 'screenX=' + x + ',screenY=' + y + ',left=' + x + ',top=' + y + ',scrollbars,width=' + w + ',height=' + h);
      temp.focus();
}

function toggleMenu(event)
{
   if (document.getElementById('menu').animator.running)
      return;

   event  = event || window.event;
   target = event.target || event.srcElement;

   var currentFile = location.href.substring(location.href.lastIndexOf('/') + 1, location.href.lastIndexOf('.'));
   var menu        = document.getElementById('menu');

   if (currentFile == 'home')
      document.getElementById('orgs').src = './pix/home/orgs_' + (menu.offsetHeight == 0 ? 'down' : 'up') + '.gif';
   if (currentFile == 'spel')
      document.getElementById('twisty').src = '../pix/wijkenspel/twisty_' + (menu.offsetHeight == 0 ? 'open' : 'closed') + '.gif';

   var direction, method;
   if (parseInt(menu.offsetHeight) == 0)
   {
      direction = 'fwd';
      method    = 'inbounce';
   }
   else
   {
      direction = 'rev';
      method    = 'outexpo';
   }
   menu.style.visibility = 'visible';
   menu.animator.init(1000);
   menu.animator.add(menu, 0, menu.displayHeight, method, 'height', direction);
   menu.animator.start();

   stopClick(event);
}

function scaleSelf()
{
   if (opener)
      return;

   var trueHeight = BrowserDetect.browser == 'chrome' ? 662 : 600;
   if (screen.width == 800 && screen.height == 600)
      var chrome = (document.all) ? 'fullscreen' : 'screenX=-4,screenY=-4,width=' + screen.availWidth + ',height=' + screen.availHeight;
   else
   {
      var x = (top.BrowserDetect.browser == 'opera' ? top.innerWidth  - 800        : screen.width  - 800) / 2;
      var y = (top.BrowserDetect.browser == 'opera' ? top.innerHeight - trueHeight : screen.height - trueHeight) / 2;
      var chrome = 'screenX=' + x + ',screenY=' + y + ',left=' + x + ',top=' + y + ',width=800,height=' + trueHeight;
   }

   newWin = window.open(document.location.href, 'kbs', chrome);
   if (!newWin)
   {
      alert('Om deze pagina vanaf uw locatie te kunnen bezoeken dienen popup vensters voor het domein "www.kinderboekenstad.nl" te worden toegestaan');
      history.back();
      return;
   }
   newWin.focus();
   history.back();
}

