/*
 * 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(a){var c=[];function b(c,b,e,f){var d=c[b];if(a.isFunction(d))try{return d.call(e,f)}catch(g){if(c.alert)alert("Error calling overlay."+b+": "+g);else throw g;return false}return true}function d(l,d){var f=this,j=null,i=a(window),m=d.target||l.attr("rel"),e=m?a(m):null;if(!e)e=l;else j=l;var g=e.attr("overlay");if(!g){g=e.css("backgroundImage");g=g.substring(g.indexOf("(")+1,g.indexOf(")"));e.css("backgroundImage","none");e.attr("overlay",g)}!g&&alert("background-image CSS property not set for overlay element: "+m);g=g.replace(/\"/g,"");d.preload&&a(window).load(function(){setTimeout(function(){var a=new Image;a.src=g},2e3)});var k=e.outerWidth({margin:true}),o=e.outerHeight({margin:true}),h=a('<img src="'+g+'"/>');h.css({border:0,position:"absolute"}).width(k).hide();a("body").append(h);j&&j.bind("click.overlay",function(a){f.load(a.pageY-i.scrollTop(),a.pageX-i.scrollLeft());return a.preventDefault()});if(!d.close||!e.find(d.close).length){e.prepend('<div class="close"></div>');d.close="div.close"}var n=e.find(d.close);a.extend(f,{load:function(m,l){if(f.isOpened())return f;d.oneInstance&&a.each(c,function(){this.close()});if(b(d,"onBeforeLoad",f)===false)return f;m=m||d.start.top;l=l||d.start.left;var j=d.finish.top,g=d.finish.left;if(j=="center")j=Math.max((i.height()-o)/2-30,0);if(g=="center")g=Math.max((i.width()-k)/2,0);if(!d.start.absolute){m+=i.scrollTop();l+=i.scrollLeft()}if(!d.finish.absolute){j+=i.scrollTop();g+=i.scrollLeft()}h.css({top:m,left:l,width:d.start.width,zIndex:d.zIndex}).show();h.animate({top:j,left:g,width:k},d.speed,function(){e.css({position:"absolute",top:j,left:g});var a=h.css("zIndex");n.add(e).css("zIndex",++a);e.fadeIn(d.fadeInSpeed,function(){b(d,"onLoad",f)})});return f},getBackgroundImage:function(){return h},getContent:function(){return e},getTrigger:function(){return j},isOpened:function(){return e.is(":visible")},getConf:function(){return d},close:function(){if(!f.isOpened())return f;if(b(d,"onClose",f)===false)return f;if(h.is(":visible")){h.hide();e.hide()}return f},getVersion:function(){return[1,0,0]},expose:function(){h.expose()}});n.bind("click.overlay",function(){f.close()});i.bind("keypress.overlay",function(a){a.keyCode==27&&f.close()});d.closeOnClick&&a(document).bind("click.overlay",function(c){if(!e.is(":visible, :animated"))return;var b=a(c.target);if(b.attr("overlay"))return;if(b.parents("[overlay]").length)return;f.close()})}jQuery.prototype.overlay=function(b){var f=this.eq(typeof b=="number"?b:0).data("overlay");if(f)return f;var g=a(window),e={start:{top:Math.round(g.height()/2),left:Math.round(g.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(a.isFunction(b))b={onBeforeLoad:b};a.extend(true,e,b);this.each(function(){var b=new d(a(this),e);c.push(b);a(this).data("overlay",b)});return this}})(jQuery);
