/* Greybox Terminland
 * Required: http://jquery.com/
 * Based on: Greybox Redux (Written by: John Resig)
 * Based on code by: 4mir Salihefendic (http://amix.dk)
 * License: LGPL (read more in LGPL.txt)
 */

var GB_DONE = false;
if (typeof GB_ANIMATION=='undefined') var GB_ANIMATION=true;
if (typeof GB_HEIGHT=='undefined') var GB_HEIGHT = 700;
if (typeof GB_WIDTH=='undefined') var GB_WIDTH = 600;
if (typeof GB_TOP=='undefined') var GB_TOP = 20;

$(document).ready(function(){
   if ((navigator.userAgent.indexOf('iPhone') == -1) && (navigator.userAgent.indexOf('iPod') == -1) && (navigator.userAgent.indexOf('iPad') == -1) && (navigator.userAgent.indexOf('Android') == -1) && (navigator.userAgent.indexOf('BlackBerry') == -1)) {  
    $("a.greybox").click(function(e){
      if (!e.shiftKey && !e.ctrlKey) {
        var t = this.title || $(this).text() || this.href;
        GB_show(t,this.href);
        return false;
      } else {
        return true;
      }
    });
   }
});

function GB_show(caption, url) {

  if(!GB_DONE) {
    $(document.body)
      .append("<div id='GB_overlay'></div><div id='GB_window'><div id='GB_caption'></div>"
        + "<img src='http://www.terminland.de/greybox/close.gif' alt='Fenster Schließen'/></div>");
    $("#GB_window img").click(GB_hide);
    //$("#GB_overlay").click(GB_hide);
    //GB_TOP = eval($("#GB_window").css('top').replace(/px/, '')) ;
    $(window).resize(GB_position);
    GB_DONE = true;
    
  }

  if (url.search(/\?/)!=-1) {
    if (url.search(/mode=[^&]*/)!=-1) {
      url = url.replace(/mode=[^&]*/, "mode=frame");
    } else {
       url += "&mode=frame";
    }
  } else { 
    url+= "?mode=frame" 
  };
 
  $("#GB_frame").remove();
  $("#GB_window").append("<iframe id='GB_frame' src='"+url+"' frameborder='0'></iframe>");

  $("#GB_caption").html(caption);
  
  var de = document.documentElement;
  var y = self.pageYOffset || (de&&de.scrollTop) || document.body.scrollTop;
  $("#GB_overlay").css('top', y+"px");
  $("#GB_window").css('top', y+GB_TOP+"px");

  $("#GB_overlay").fadeTo("slow", 0.50, function() {
      GB_position();
      if(GB_ANIMATION)
        $("#GB_window").slideDown("fast");
      else
        $("#GB_window").show();
      if ($.browser.msie) {
	$("body","html").css({height: "100%", width: "100%"});
	$("html").css('overflow', 'hidden');
      } else {  
        $("body").css('overflow', 'hidden');
      }
  });
}

function GB_hide() {
  if ($.browser.msie) {
      $("body","html").css({height: "", width: ""});
      $("html").css('overflow', '');
  } else {  
      $("body").css('overflow', '');
  }
  $("#GB_window").hide();
  $("#GB_overlay").fadeTo("slow", 0, function() {$("#GB_overlay").hide();});
}

function GB_position() {
  var de = document.documentElement;
  var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
  var h = self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
  h-=GB_TOP;
  if (h>GB_HEIGHT) h = GB_HEIGHT;
  $("#GB_window").css({width:GB_WIDTH+"px",height:h+"px",
    left: ((w - GB_WIDTH)/2)+"px" });
  $("#GB_frame").css({height:h - 55 +"px",width:GB_WIDTH-30 +"px","overflow-x":"hidden"});
}




