/*
 * SimpleModal 1.3.5 - jQuery Plugin
 * http://www.ericmmartin.com/projects/simplemodal/
 * Copyright (c) 2010 Eric Martin (http://twitter.com/EricMMartin)
 * Dual licensed under the MIT and GPL licenses
 * Revision: $Id: jquery.simplemodal.js 245 2010-03-25 20:41:15Z emartin24 $
 */

(function(b){var i=b.browser.msie&&parseInt(b.browser.version)==6&&typeof window.XMLHttpRequest!="object",j=null,c=[];b.modal=function(a,g){return b.modal.impl.init(a,g)};b.modal.close=function(){b.modal.impl.close()};b.fn.modal=function(a){return b.modal.impl.init(this,a)};b.modal.defaults={appendTo:"body",focus:!0,opacity:50,overlayId:"simplemodal-overlay",overlayCss:{},containerId:"simplemodal-container",containerCss:{},dataId:"simplemodal-data",dataCss:{},minHeight:null,minWidth:null,maxHeight:null,
maxWidth:null,autoResize:!1,autoPosition:!0,zIndex:1E3,close:!0,closeHTML:'<a class="modalCloseImg" title="Close"></a>',closeClass:"simplemodal-close",escClose:!0,overlayClose:!1,position:null,persist:!1,modal:!0,onOpen:null,onShow:null,onClose:null};b.modal.impl={o:null,d:{},init:function(a,g){if(this.d.data)return!1;j=b.browser.msie&&!b.boxModel;this.o=b.extend({},b.modal.defaults,g);this.zIndex=this.o.zIndex;this.occb=!1;if(typeof a=="object"){if(a=a instanceof jQuery?a:b(a),this.d.placeholder=
!1,a.parent().parent().size()>0&&(a.before(b("<span></span>").attr("id","simplemodal-placeholder").css({display:"none"})),this.d.placeholder=!0,this.display=a.css("display"),!this.o.persist))this.d.orig=a.clone(!0)}else if(typeof a=="string"||typeof a=="number")a=b("<div></div>").html(a);else return alert("SimpleModal Error: Unsupported data type: "+typeof a),this;this.create(a);this.open();b.isFunction(this.o.onShow)&&this.o.onShow.apply(this,[this.d]);return this},create:function(a){c=this.getDimensions();
if(this.o.modal&&i)this.d.iframe=b('<iframe src="javascript:false;"></iframe>').css(b.extend(this.o.iframeCss,{display:"none",opacity:0,position:"fixed",height:c[0],width:c[1],zIndex:this.o.zIndex,top:0,left:0})).appendTo(this.o.appendTo);this.d.overlay=b("<div></div>").attr("id",this.o.overlayId).addClass("simplemodal-overlay").css(b.extend(this.o.overlayCss,{display:"none",opacity:this.o.opacity/100,height:this.o.modal?c[0]:0,width:this.o.modal?c[1]:0,position:"fixed",left:0,top:0,zIndex:this.o.zIndex+
1})).appendTo(this.o.appendTo);this.d.container=b("<div></div>").attr("id",this.o.containerId).addClass("simplemodal-container").css(b.extend(this.o.containerCss,{display:"none",position:"fixed",zIndex:this.o.zIndex+2})).append(this.o.close&&this.o.closeHTML?b(this.o.closeHTML).addClass(this.o.closeClass):"").appendTo(this.o.appendTo);this.d.wrap=b("<div></div>").attr("tabIndex",-1).addClass("simplemodal-wrap").css({height:"100%",outline:0,width:"100%"}).appendTo(this.d.container);this.d.data=a.attr("id",
a.attr("id")||this.o.dataId).addClass("simplemodal-data").css(b.extend(this.o.dataCss,{display:"none"})).appendTo("body");this.setContainerDimensions();this.d.data.appendTo(this.d.wrap);(i||j)&&this.fixIE()},bindEvents:function(){var a=this;b("."+a.o.closeClass).bind("click.simplemodal",function(b){b.preventDefault();a.close()});a.o.modal&&a.o.close&&a.o.overlayClose&&a.d.overlay.bind("click.simplemodal",function(b){b.preventDefault();a.close()});b(document).bind("keydown.simplemodal",function(b){a.o.modal&&
a.o.focus&&b.keyCode==9?a.watchTab(b):a.o.close&&a.o.escClose&&b.keyCode==27&&(b.preventDefault(),a.close())});b(window).bind("resize.simplemodal",function(){c=a.getDimensions();a.setContainerDimensions(!0);i||j?a.fixIE():a.o.modal&&(a.d.iframe&&a.d.iframe.css({height:c[0],width:c[1]}),a.d.overlay.css({height:c[0],width:c[1]}))})},unbindEvents:function(){b("."+this.o.closeClass).unbind("click.simplemodal");b(document).unbind("keydown.simplemodal");b(window).unbind("resize.simplemodal");this.d.overlay.unbind("click.simplemodal")},
fixIE:function(){var a=this.o.position;b.each([this.d.iframe||null,!this.o.modal?null:this.d.overlay,this.d.container],function(b,c){if(c){var d=c[0].style;d.position="absolute";if(b<2)d.removeExpression("height"),d.removeExpression("width"),d.setExpression("height",'document.body.scrollHeight > document.body.clientHeight ? document.body.scrollHeight : document.body.clientHeight + "px"'),d.setExpression("width",'document.body.scrollWidth > document.body.clientWidth ? document.body.scrollWidth : document.body.clientWidth + "px"');
else{var e,f;a&&a.constructor==Array?(e=a[0]?typeof a[0]=="number"?a[0].toString():a[0].replace(/px/,""):c.css("top").replace(/px/,""),e=e.indexOf("%")==-1?e+' + (t = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + "px"':parseInt(e.replace(/%/,""))+' * ((document.documentElement.clientHeight || document.body.clientHeight) / 100) + (t = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + "px"',a[1]&&
(f=typeof a[1]=="number"?a[1].toString():a[1].replace(/px/,""),f=f.indexOf("%")==-1?f+' + (t = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft) + "px"':parseInt(f.replace(/%/,""))+' * ((document.documentElement.clientWidth || document.body.clientWidth) / 100) + (t = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft) + "px"')):(e='(document.documentElement.clientHeight || document.body.clientHeight) / 2 - (this.offsetHeight / 2) + (t = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + "px"',
f='(document.documentElement.clientWidth || document.body.clientWidth) / 2 - (this.offsetWidth / 2) + (t = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft) + "px"');d.removeExpression("top");d.removeExpression("left");d.setExpression("top",e);d.setExpression("left",f)}}})},focus:function(a){a=b(":input:enabled:visible:"+(a||"first"),this.d.wrap);a.length>0?a.focus():this.d.wrap.focus()},getDimensions:function(){var a=b(window);return[b.browser.opera&&
b.browser.version>"9.5"&&b.fn.jquery<="1.2.6"?document.documentElement.clientHeight:b.browser.opera&&b.browser.version<"9.5"&&b.fn.jquery>"1.2.6"?window.innerHeight:a.height(),a.width()]},getVal:function(a){return a=="auto"?0:a.indexOf("%")>0?a:parseInt(a.replace(/px/,""))},setContainerDimensions:function(a){if(!a||a&&this.o.autoResize){var a=b.browser.opera?this.d.container.height():this.getVal(this.d.container.css("height")),g=b.browser.opera?this.d.container.width():this.getVal(this.d.container.css("width")),
h=this.d.data.outerHeight(!0),d=this.d.data.outerWidth(!0),e=this.o.maxHeight&&this.o.maxHeight<c[0]?this.o.maxHeight:c[0],f=this.o.maxWidth&&this.o.maxWidth<c[1]?this.o.maxWidth:c[1],a=a?a>e?e:a:h?h>e?e:h<this.o.minHeight?this.o.minHeight:h:this.o.minHeight,g=g?g>f?f:g:d?d>f?f:d<this.o.minWidth?this.o.minWidth:d:this.o.minWidth;this.d.container.css({height:a,width:g});(h>a||d>g)&&this.d.wrap.css({overflow:"auto"})}this.o.autoPosition&&this.setPosition()},setPosition:function(){var a,b;a=c[0]/2-this.d.container.outerHeight(!0)/
2;b=c[1]/2-this.d.container.outerWidth(!0)/2;this.o.position&&Object.prototype.toString.call(this.o.position)==="[object Array]"&&(a=this.o.position[0]||a,b=this.o.position[1]||b);this.d.container.css({left:b,top:a})},watchTab:function(a){var c=this;if(b(a.target).parents(".simplemodal-container").length>0){if(c.inputs=b(":input:enabled:visible:first, :input:enabled:visible:last",c.d.data[0]),!a.shiftKey&&a.target==c.inputs[c.inputs.length-1]||a.shiftKey&&a.target==c.inputs[0]||c.inputs.length==0){a.preventDefault();
var h=a.shiftKey?"last":"first";setTimeout(function(){c.focus(h)},10)}}else a.preventDefault(),setTimeout(function(){c.focus()},10)},open:function(){this.d.iframe&&this.d.iframe.show();b.isFunction(this.o.onOpen)?this.o.onOpen.apply(this,[this.d]):(this.d.overlay.show(),this.d.container.show(),this.d.data.show());this.focus();this.bindEvents()},close:function(){if(!this.d.data)return!1;this.unbindEvents();if(b.isFunction(this.o.onClose)&&!this.occb)this.occb=!0,this.o.onClose.apply(this,[this.d]);
else{if(this.d.placeholder){var a=b("#simplemodal-placeholder");this.o.persist?a.replaceWith(this.d.data.removeClass("simplemodal-data").css("display",this.display)):(this.d.data.hide().remove(),a.replaceWith(this.d.orig))}else this.d.data.hide().remove();this.d.container.hide().remove();this.d.overlay.hide().remove();this.d.iframe&&this.d.iframe.hide().remove();this.d={}}}}})(jQuery);
