/*
 * jquery.overlay 1.0.1. Overlay HTML with eyecandy.
 * 
 * Copyright (c) 2009 Tero Piirainen
 * http://flowplayer.org/tools/overlay.html
 *
 * Dual licensed under MIT and GPL 2+ licenses
 * http://www.opensource.org/licenses
 *
 * Launch  : March 2008
 * Version : 1.0.1 - Wed Feb 18 2009 05:18:27 GMT-0000 (GMT+00:00)
 */
(function(C){var D=[];function B(J,H,F,E){var I=J[H];if(C.isFunction(I)){try{return I.call(F,E)}catch(G){if(J.alert){alert("Error calling overlay."+H+": "+G)}else{throw G}return false}}return true}function A(I,E){var P=this;var K=null;var N=C(window);var J=E.target||I.attr("rel");var H=J?C(J):null;if(!H){H=I}else{K=I}var M=H.attr("overlay");if(!M){M=H.css("backgroundImage");M=M.substring(M.indexOf("(")+1,M.indexOf(")"));H.css("backgroundImage","none");H.attr("overlay",M)}if(!M){alert("background-image CSS property not set for overlay element: "+J)}M=M.replace(/\"/g,"");if(E.preload){C(window).load(function(){setTimeout(function(){var Q=new Image();Q.src=M},2000)})}var O=H.outerWidth({margin:true});var G=H.outerHeight({margin:true});var L=C('<img src="'+M+'"/>');L.css({border:0,position:"absolute"}).width(O).hide();C("body").append(L);if(K){K.bind("click.overlay",function(Q){P.load(Q.pageY-N.scrollTop(),Q.pageX-N.scrollLeft());return Q.preventDefault()})}if(!E.close||!H.find(E.close).length){H.prepend('<div class="close"></div>');E.close="div.close"}var F=H.find(E.close);C.extend(P,{load:function(T,S){if(P.isOpened()){return P}if(E.oneInstance){C.each(D,function(){this.close()})}if(B(E,"onBeforeLoad",P)===false){return P}T=T||E.start.top;S=S||E.start.left;var Q=E.finish.top;var R=E.finish.left;if(Q=="center"){Q=Math.max((N.height()-G)/2-30,0)}if(R=="center"){R=Math.max((N.width()-O)/2,0)}if(!E.start.absolute){T+=N.scrollTop();S+=N.scrollLeft()}if(!E.finish.absolute){Q+=N.scrollTop();R+=N.scrollLeft()}L.css({top:T,left:S,width:E.start.width,zIndex:E.zIndex}).show();L.animate({top:Q,left:R,width:O},E.speed,function(){H.css({position:"absolute",top:Q,left:R});var U=L.css("zIndex");F.add(H).css("zIndex",++U);H.fadeIn(E.fadeInSpeed,function(){B(E,"onLoad",P)})});return P},getBackgroundImage:function(){return L},getContent:function(){return H},getTrigger:function(){return K},isOpened:function(){return H.is(":visible")},getConf:function(){return E},close:function(){if(!P.isOpened()){return P}if(B(E,"onClose",P)===false){return P}if(L.is(":visible")){L.hide();H.hide()}return P},getVersion:function(){return[1,0,0]},expose:function(){L.expose()}});F.bind("click.overlay",function(){P.close()});N.bind("keypress.overlay",function(Q){if(Q.keyCode==27){P.close()}});if(E.closeOnClick){C(document).bind("click.overlay",function(Q){if(!H.is(":visible, :animated")){return }var R=C(Q.target);if(R.attr("overlay")){return }if(R.parents("[overlay]").length){return }P.close()})}}jQuery.prototype.overlay=function(F){var G=this.eq(typeof F=="number"?F:0).data("overlay");if(G){return G}var E=C(window);var H={start:{top:Math.round(E.height()/2),left:Math.round(E.width()/2),width:0,absolute:false},finish:{top:"center",left:"center",absolute:false},speed:"normal",fadeInSpeed:"fast",close:null,oneInstance:true,closeOnClick:true,preload:false,zIndex:9999,target:null,alert:true};if(C.isFunction(F)){F={onBeforeLoad:F}}C.extend(true,H,F);this.each(function(){var I=new A(C(this),H);D.push(I);C(this).data("overlay",I)});return this}})(jQuery);