var modalbox = new function() { this.show = function (mbContent,mbWidth,mbClose){ if(typeof(mbWidth)=="undefined") mbWidth = 450; if(typeof(mbClose)=="undefined" || mbClose==true) showClose = true; else showClose = false; var mbHTML = ' \ '; $("body").append(mbHTML); var i = $(".modalBox").length-1; $(".modalBox").eq(i).fadeIn(400); var top = Math.floor(($(window).height() - $('.mbWrapper').eq(i).height()) / 2) + $(window).scrollTop(); if( top<10 ) { top = 10; } $('.mbWrapper').eq(i).css('margin-top', top ); $(".mbClose").click( function() { destroy(); } ); if(showClose==true) { $(document).bind('keydown.modalBox', function(e) { if (e.keyCode == 27) destroy(); }); } }; var destroy = function destroy(){ var i = $(".modalBox").length-1; $(".modalBox").eq(i).fadeOut(400,"linear", function() { $(".modalBox").eq(i).remove(); } ); $(document).unbind('keydown.modalBox'); }; this.destroy = destroy; }