// jQuery My Modal v 1.0 - Copyright © 2010 Emanuele Toffolon - Released under the GNU License
function openModal(ajaxScriptLoader,id,force,type){
    var cookieVal = getCookie("casale_news");
    if (!cookieVal || force){
        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");
        });
        $("body").append("<div class=\"my_modal\" id=\"my_modal\"></div>");
        if (ajaxScriptLoader){
            var poststr = "&id="+id;
            if (type=="B") poststr += "&banner=1";
            $.post(ajaxScriptLoader,poststr,function(data){
               $("#my_modal").html(data); 
                $("a[rel='_blank']").each(function(){
                   $(this).attr("target","_blank"); 
                });
            });        
            var height = $("#my_modal").height();
            var windowHeight = $(window).height();
            var windowWidth = $(window).width();
            var left = (windowWidth - $("#my_modal").width()) / 2;
            if (height > windowHeight){
                $("#my_modal").height((windowHeight - 20));            
            }
            $("#my_modal").css("top",15);
            $("#my_modal").css("left",left);
        }
        $("#my_modal").fadeIn();
    }
    setCookieOre("casale_news","view;ok",1);    
}

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