/*
 * jQuery Impromptu
 * By: Trent Richardson [http://trentrichardson.com]
 * Version 3.1
 * Last Modified: 3/30/2010
 * 
 * Copyright 2010 Trent Richardson
 * Dual licensed under the MIT and GPL licenses.
 * http://trentrichardson.com/Impromptu/GPL-LICENSE.txt
 * http://trentrichardson.com/Impromptu/MIT-LICENSE.txt
 * 
 */
(function(a){a.prompt=function(c,b){function m(){e.remove();f&&p.h("scroll",q);g.h("resize",n);j.r(b.i,function(){j.h("click",o);j.remove();d.h("keypress",r);d.remove();f&&!b.l&&a("select").b("visibility","visible")})}function n(){d.b({position:f?"absolute":"fixed",height:g.height(),width:"100%",top:f?g.scrollTop():0,left:0,right:0,bottom:0});j.b({position:"absolute",height:g.height(),width:"100%",top:0,left:0,right:0,bottom:0});e.b({position:"absolute",top:b.top,left:"50%",marginLeft:e.outerWidth()/
2*-1})}function r(b){var c=window.event?event.keyCode:b.keyCode;c==27&&o();if(c==9){var h=a(":input:enabled:visible",d),s=b.shiftKey&&b.target==h[0];if(!b.shiftKey&&b.target==h[h.length-1]||s)return setTimeout(function(){if(h){var b=h[s===!0?h.length-1:0];b&&b.focus()}},10),!1}}function o(){if(b.t){var a=0;d.o(b.prefix+"warning");var c=setInterval(function(){d.R(b.prefix+"warning");a++>1&&(clearInterval(c),d.L(b.prefix+"warning"))},100)}else m()}function q(){d.b({top:g.scrollTop()})}b=a.extend({},
a.prompt.d,b);a.prompt.a=b.prefix;var f=a.p.H&&a.p.version<7,p=a(document.body),g=a(window);b.e=a.trim(b.e);if(b.e!="")b.e=" "+b.e;var k='<div class="'+b.prefix+"box"+b.e+'" id="'+b.prefix+'box">';b.l&&(a("object, applet").length>0||f)?k+='<iframe src="javascript:false;" style="display:block;position:absolute;z-index:-1;" class="'+b.prefix+'fade" id="'+b.prefix+'fade"></iframe>':(f&&a("select").b("visibility","hidden"),k+='<div class="'+b.prefix+'fade" id="'+b.prefix+'fade"></div>');k+='<div class="'+
b.prefix+'" id="'+b.prefix+'"><div class="'+b.prefix+'container">';k+='<div id="'+b.prefix+'states"></div>';k+="</div></div></div>";var d=a(k).v(p),e=d.children("#"+b.prefix),j=d.children("#"+b.prefix+"fade");c.constructor==String&&(c={Q:{f:c,c:b.c,focus:b.focus,submit:b.submit}});var l="";a.g(c,function(d,e){e=a.extend({},a.prompt.d.state,e);c[d]=e;l+='<div id="'+b.prefix+"_state_"+d+'" class="'+b.prefix+'_state" style="display:none;"><div class="'+b.prefix+'message">'+e.f+'</div><div class="'+b.prefix+
'buttons">';a.g(e.c,function(a,c){l+=typeof c=="object"?'<button name="'+b.prefix+"_"+d+"_button"+c.title.replace(/[^a-z0-9]+/gi,"")+'" id="'+b.prefix+"_"+d+"_button"+c.title.replace(/[^a-z0-9]+/gi,"")+'" value="'+c.value+'">'+c.title+"</button>":'<button name="'+b.prefix+"_"+d+"_button"+a+'" id="'+b.prefix+"_"+d+"_button"+a+'" value="'+c+'">'+a+"</button>"});l+="</div></div>"});e.find("#"+b.prefix+"states").f(l).children("."+b.prefix+"_state:first").b("display","block");e.find("."+b.prefix+"buttons:empty").b("display",
"none");a.g(c,function(c,d){var h=e.find("#"+b.prefix+"_state_"+c);h.children("."+b.prefix+"buttons").children("button").click(function(){var c=h.children("."+b.prefix+"message"),f=d.c[a(this).text()];if(f==void 0)for(var g in d.c)if(d.c[g].title==a(this).text())f=d.c[g].value;if(typeof f=="object")f=f.value;var i={};a.g(e.find("#"+b.prefix+"states :input").N(),function(b,a){i[a.name]===void 0?i[a.name]=a.value:typeof i[a.name]==Array||typeof i[a.name]=="object"?i[a.name].push(a.value):i[a.name]=
[i[a.name],a.value]});c=d.submit(f,c,i);(c===void 0||c)&&m()});h.find("."+b.prefix+"buttons button:eq("+d.focus+")").o(b.prefix+"defaultbutton")});n();j.b({zIndex:b.zIndex,display:"none",opacity:b.opacity});e.b({zIndex:b.zIndex+1,display:"none"});d.b({zIndex:b.zIndex});e.q("round 10px").children(".impromptucontainer").q("round 10px");f&&g.scroll(q);j.click(o);g.M(n);d.bind("keydown keypress",r);e.find("."+b.prefix+"close").click(m);j.B(b.i);e[b.show](b.u,b.loaded);e.find("#"+b.prefix+"states ."+b.prefix+
"_state:first ."+b.prefix+"defaultbutton").focus();b.timeout>0&&setTimeout(a.prompt.close,b.timeout);return d};a.prompt.d={prefix:"jqi",e:"",c:{n:!0},loaded:function(){},submit:function(){return!0},z:function(){},opacity:0.6,zIndex:1E4,i:"slow",u:"fast",show:"fadeIn",focus:0,l:!1,top:"15%",t:!0,timeout:0,state:{f:"",c:{n:!0},focus:0,submit:function(){return!0}}};a.prompt.a=a.prompt.d.prefix;a.prompt.O=function(c){a.prompt.d=a.extend({},a.prompt.d,c)};a.prompt.P=function(c){a.prompt.d.state=a.extend({},
a.prompt.d.state,c)};a.prompt.F=function(c){return a("#"+a.prompt.a+"_state_"+c)};a.prompt.s=function(){return a("."+a.prompt.a+"_state:visible")};a.prompt.D=function(){return a.prompt.s().w("id").replace(a.prompt.a+"_state_","")};a.prompt.G=function(c,b){a("."+a.prompt.a+"_state").k("slow");a("#"+a.prompt.a+"_state_"+c).j("slow",function(){a(this).find("."+a.prompt.a+"defaultbutton").focus();typeof b=="function"&&b()})};a.prompt.I=function(c){var b=a("."+a.prompt.a+"_state:visible").next();a("."+
a.prompt.a+"_state").k("slow");b.j("slow",function(){b.find("."+a.prompt.a+"defaultbutton").focus();typeof c=="function"&&c()})};a.prompt.K=function(c){var b=a("."+a.prompt.a+"_state:visible").J();a("."+a.prompt.a+"_state").k("slow");b.j("slow",function(){b.find("."+a.prompt.a+"defaultbutton").focus();typeof c=="function"&&c()})};a.prompt.close=function(){a("#"+a.prompt.a+"box").r("fast",function(){a(this).remove()})};a.C.prompt=function(c){c==void 0&&(c={});if(c.m==void 0)c.m=!1;a.prompt(a(this).A(c.m).f(),
c)}})(jQuery);
