// JavaScript Document for Kulturfabrik Dessau
// (c) Computersitter Dessau

var div = null;
var over = null;

function closing() {
  new Effect.Fade(div,{
    duration: 0.3,
    afterFinish: function(es) {
      Element.remove(div);
      div = null;
      Element.remove(over);
    }
  });
}

function toggle_div(toCall) {
  toCall.match(/#(\w+)$/);
  var mode = RegExp.$1;
  if (!div) {
    var viewport = document.viewport.getDimensions();
    
    div = Builder.node('div',{
      className: "window",
      style: "width: 460px; height: 80%; display: none;"
    });
    
    var close = Builder.node('div',{
      style: "width: 448px; height: 30px;"
    },[
      Builder.node('img',{
        style: "float: right; cursor: pointer; margin-right: 4px;",
        title: "Fenster schließen",
        src: '/images/close.gif'
      })
    ]);
    $(close).observe('click',closing);
    $(div).appendChild(close);
    $$('body')[0].appendChild(div);
    if (mode != "images") {
      var _iframe = Builder.node('iframe',{
        frameborder: "0",
        scrolling: "auto",
        src: "/" + ((mode=="images")?"images.php5":mode + ".html"),
        style: "position: relative; width: 448px; height: " + ($(div).getHeight()-40)+"px; background-color: #fff;"
      });
      $(div).appendChild($(_iframe));
      new Effect.SlideDown(div,{
        beforeStart: function() {
          over = Builder.node('div',{
            style: "position: absolute; top: 0px; left: 0px; z-index: 9; height: 100%; width: 100%;"
          });
          $$('body')[0].appendChild(over);
          $(over).observe('click',closing);
        },
        duration: 0.9
      });
    }
    else {
      try {
        new Ajax.Request("/images.php5",{
          onSuccess: function(req) {
            $(div).innerHTML = req.responseText;
            new Effect.SlideDown(div,{
              beforeStart: function() {
                over = Builder.node('div',{
                  style: "position: absolute; top: 0px; left: 0px; z-index: 9; height: 100%; width: 100%;"
                });
                $$('body')[0].appendChild(over);
                $(over).observe('click',closing);
              },
              duration: 0.9
            });
          }
        });
      }
      catch(e) {
        alert(e.message + " at line " + e.lineNumber);
      }
    }
  }
}


/*var curDiv = null;
var divImg = null;

function displayDiv(id) {
  if ($(id)) {
    if ($(curDiv))
      hideDiv();
    if (divImg)
      blindImages();
    $(id).setStyle({width: (((window.innerWidth)?window.innerWidth:document.body.clientWidth) - 615)+"px",height: (((window.innerHeight)?window.innerHeight:document.body.clientHeight) - 60)+"px",zIndex: '10',fontSize: '10px'});
    new Effect.Appear(id,{from: 0.0, to: 1.0, duration: 1.15});
    curDiv = id;
  }
}

function hideDiv() {
  if ($(curDiv)) {
    new Effect.Appear(curDiv,{from: 1.0, to: 0.0, duration: 1.15, afterFinish: function() {curDiv = null;}});
  }
  if ($(divImg))
    blindImages();
}

function resizeCurDiv() {
  if ($(curDiv)) {
    $(curDiv).setStyle({width: (((window.innerWidth)?window.innerWidth:document.body.clientWidth) - 615)+"px",height: (((window.innerHeight)?window.innerHeight:document.body.clientHeight) - 60)+"px",zIndex: '10'});
  }
  if ($(divImg)) {
    $(divImg).setStyle({width: (((window.innerWidth)?window.innerWidth:document.body.clientWidth) - 40)+"px", height:(((window.innerHeight)?window.innerHeight:document.body.clientHeight) - 40)+"px"});
  }
}

if(window.addEventListener) window.addEventListener("resize",resizeCurDiv,false);
else if (window.attachEvent) window.attachEvent("onresize",resizeCurDiv);



function growImages(picDir) {
  if ($(curDiv))
    hideDiv();
  divImg = document.createElement('div');
  $(divImg).setStyle({position: 'absolute',display: 'none',width: (((window.innerWidth)?window.innerWidth:document.body.clientWidth) - 40)+"px", height:(((window.innerHeight)?window.innerHeight:document.body.clientHeight) - 40)+"px",top: '20px',left: '20px',zIndex: '100',backgroundColor: '#fff',border: '1px solid #000;', overflow: 'auto', padding: '2px'});
  document.getElementsByTagName('body')[0].appendChild(divImg);
  new Ajax.Updater($(divImg),'/pictures.php5?imgDir='+ picDir,{
    method: 'get',
    onSuccess: function (req) {
      $(divImg).innerHTML = req.responseText;
      new Effect.Appear($(divImg));
    }
  });
}

function blindImages() {
  if ($(divImg))
    new Effect.Appear($(divImg),{from: 1.0,to: 0.0, afterFinish: function () { document.getElementsByTagName('body')[0].removeChild($(divImg)); divImg = null; }});
}

*/

