/* Greybox Maskinbladet.tv
 * Required: http://jquery.com/
 * Rewritten by: Thomas Christensen
 */

var GB_DONE = false;
var GB_HEIGHT = 400;
var GB_WIDTH = 400;

function GB_show(url, height, width) {
  GB_HEIGHT = height || 400;
  GB_WIDTH = width || 400;
  if(!GB_DONE) {
    if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
      $("body","html").css({height: "100%", width: "100%"});
      $("html").css("overflow","hidden");
      if (document.getElementById("GB_HideSelect") === null) {//iframe to hide select elements in ie6
        $("body").append("<iframe id='GB_HideSelect'></iframe><div id='GB_overlay'></div>");
      }
    }else{//all others
      if(document.getElementById("GB_overlay") === null){
        $("body").append("<div id='GB_overlay'></div>");
      }
    }
    $("#GB_overlay").addClass("GB_overlayBG");
    
    $("body").append("<div id='GB_window'></div>");
    
    $(window).resize(GB_position);
    GB_DONE = true;
  }

  $("#GB_frame").remove();
  $("#GB_window").append("<iframe id='GB_frame' name='GB_frame"+Math.round(Math.random()*1000)+"' src='"+url+"' border='0' frameborder='no' framespacing='0' marginheight='0' marginwidth='0' noresize='noresize' scrolling='no'></iframe>");

  GB_position();

  $("#GB_window").css({display:"block"});
}

function GB_hide() {
  $('#GB_window,#GB_overlay,#GB_HideSelect').trigger("unload").unbind().remove();
  if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
    $("body","html").css({height: "auto", width: "auto"});
    $("html").css("overflow","");
  }
  return false;
}

function GB_position() {
  $("#GB_window").css({marginLeft: '-' + parseInt((GB_WIDTH / 2),10) + 'px', width: GB_WIDTH + 'px', height: GB_HEIGHT + 'px'});
  if ( !(jQuery.browser.msie && jQuery.browser.version < 7)) { // take away IE6
    $("#GB_window").css({marginTop: '-' + parseInt((GB_HEIGHT / 2),10) + 'px'});
  }
}

