/******************************************************************************************************************
 * @name: bPopup modified
 * @type: jQuery
 * @author: Bjoern Klinggaard (http://dinbror.dk/blog/bPopup)
 *******************************************************************************************************************/ 
(function(a){a.fn.openPopup=function(e){function p(){var b=a("input[type=text]",d).length!=0;d.css({left:c.scrollLeft()+g,top:c.scrollTop()+h,"z-index":o.zIndex}).appendTo(o.appendTo).hide(function(){b&&d.each(function(){d.find("input[type=text]").val("")})}).fadeIn(o.duration,function(){b&&d.find("input[type=text]:first").focus()})}function j(){a("#bModal").length!=0?a("#bModal, selector").fadeOut("normal",function(){d.css("display","none");a("#bModal").remove()}):d.fadeOut("normal");a("html").removeAttr("style");a("."+o.closeClass).unbind("click.bPopup");c.unbind("keydown.bPopup");f.unbind("resize.bPopup scroll.bPopup")}function q(){if(k){var b=[c.height(),c.width()];return{height:b[0],left:i(),opacity:0,position:"absolute",top:0,width:b[1],"z-index":o.zIndex-1}}else return{height:"100%",left:0,opacity:0,position:"fixed",top:0,width:"100%","z-index":o.zIndex-1}}function r(){a("."+o.closeClass).bind("click.bPopup",function(){j()});f.bind("scroll.bPopup",function(){d.stop().animate({left:c.scrollLeft()+g,top:c.scrollTop()+h},o.duration)});f.bind("resize.bPopup",function(){if(o.modal&&k){var b=[c.height(),c.width()];l.css({height:b[0],width:b[1],left:i()})}b=m(d,o.amsl);h=b[0];g=b[1];d.stop().animate({left:c.scrollLeft()+g,top:c.scrollTop()+h},o.duration)});o.escClose&&c.bind("keydown.bPopup",function(b){b.which==27&&j()})}function i(){return f.width()<a("body").width()?0:(a("body").width()-f.width())/2}function m(b,s){var n=(f.height()-b.height())/2-s,t=(f.width()-b.width())/2+i();return[n<o.minTop?o.minTop:n,t]}o=a.extend({},a.fn.openPopup.defaults,e);var d=a(this),l=a('<div id="bModal"></div>'),c=a(document),f=a(window);e=m(d,o.amsl);var h=e[0],g=e[1],k=a.browser.msie&&parseInt(a.browser.version)==6&&typeof window.XMLHttpRequest!="object";return this.each(function(){o.scrollBar||a("html").css("overflow","hidden");o.xLink&&a("a#bContinue").text(a("a.xlink").attr("title")).attr({href:a("a.xlink").attr("rel")});o.modal&&l.css(q()).appendTo(o.appendTo).animate({opacity:o.opacity},o.duration);p();r()})};a.fn.openPopup.defaults={amsl:150,appendTo:"body",closeClass:"bClose",duration:"normal",escClose:true,minTop:20,modal:true,opacity:0.5,scrollBar:true,xLink:false,zIndex:9999};a.fn.closePopup=function(){return this.each(function(){var e=a(this);a("#bModal").length!=0?a("selector, #bModal").fadeOut("normal",function(){e.css("display","none");a("#bModal").remove()}):e.fadeOut("normal");a("html").removeAttr("style");a(document).unbind("keydown");a(window).unbind("resize scroll")})}})(jQuery);
