var mimirpopupStatus = 0;
//alert('popup loaded');

//centering popup 
function centerMimirPopup(){ 
//request data for centering 
var windowDim = getWindowSize(); 
var popupHeight = $("#popupMimir").height(); 
var popupWidth = $("#popupMimir").width(); 
var scroll = getScrollXY(); 
//centering 
$("#popupMimir").css({ 
"position": "absolute", 
"top": windowDim.Y/2-popupHeight/2 + scroll.Y-15, 
"left": windowDim.X/2-popupWidth/2 + scroll.X-15 
}); 
//only need force for IE6 

$("#backgroundMimirPopup").css({ 
"position": "absolute",
"top": 0,
"left": 0,
"height": $(document.body).height()+5,
"width": windowDim.X - 2
}); 
//window.alert("\npopup.Height="+popupHeight+"\nInner Height="+windowDim.Y); 
}

//loading popup with jQuery magic!
function loadMimirPopup(what){
//loads popup only if it is disabled
if(mimirpopupStatus==0){
$("#jump_hits").hide();
$("#jump_ordercat").hide();
$("#jump_order").hide();

$("#backgroundMimirPopup").css({
"opacity": "0.7"
});
$("#backgroundMimirPopup").fadeIn("slow");
$("#popupMimir").fadeIn("slow");
mimirpopupStatus = 1;
$("#popupMimir").load("/ajax/mimir.php?w=" + what + " #module_datasheet");
}
}

//disabling popup with jQuery magic!
function disableMimirPopup(){
//disables popup only if it is enabled
if(mimirpopupStatus==1){
$("#backgroundMimirPopup").fadeOut("slow");
$("#popupMimir").fadeOut("slow");
$("#jump_hits").show();
$("#jump_ordercat").show();
$("#jump_order").show();

mimirpopupStatus = 0;
}
}

//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
//LOADING POPUP
//Click the button event!
$("div[@name=mimirbutton]").click(function(){
//centering with css
centerMimirPopup();
//load popup
loadMimirPopup(this.getAttribute('rel'));
});

//CLOSING POPUP
//Click the x event!
$("#popupMimirClose").click(function(){
disableMimirPopup();
});
//Click out event!
$("#backgroundMimirPopup").click(function(){
disableMimirPopup();
});

});