// jQuery My Modal v 1.0 - Copyright © 2010 Emanuele Toffolon - Released under the GNU License
function openModal(ajaxScriptLoader,id){

        var container_height = 1*$(document).height();
        /*
        $("<div id=\"overlay\"></div>").appendTo("body").addClass("overlay").css({width:$("body").width(),height:container_height,top: 0, left: 0}).click(function(){
            removeModal("my_modal");
        });
        */
        $("<div id=\"overlay\"></div>").appendTo("body").addClass("overlay").css({width:$("body").width(),height:container_height,top: 0, left: 0});
        $("body").append("<div class=\"my_modal\" id=\"my_modal\"></div>");
        if (ajaxScriptLoader){
            var poststr = "&id="+id;
            $.post(ajaxScriptLoader,poststr,function(data){
               $("#my_modal").html(data); 
                $("a[rel='_blank']").each(function(){
                   $(this).attr("target","_blank"); 
                });
            });        
            var height = $("#my_modal").height();
            if (!height) height = 387;
            var windowHeight = $(window).height();
            var windowWidth = $(window).width();
            var left = (windowWidth - $("#my_modal").width()) / 2;
            var top = (windowHeight - height) / 2;
            if (height > windowHeight){
                $("#my_modal").height((windowHeight - 20));            
            }
            $("#my_modal").css("top",top);
            $("#my_modal").css("left",left);
        }
        $("#my_modal").fadeIn();
    
}

function removeModal(obj){    
    $("#"+obj).fadeOut("slow", function(){
      $("#overlay").remove();
      $(this).remove();
        
    });
}
