(function($,undefined){function extendRemove(a,b){$.extend(a,b);for(var c in b)if(b[c]==null||b[c]==undefined)a[c]=b[c];return a}function Timepicker(){this.debug=true;this._curInst=null;this._isInline=false;this._disabledInputs=[];this._timepickerShowing=false;this._inDialog=false;this._dialogClass="ui-timepicker-dialog";this._mainDivId="ui-timepicker-div";this._inlineClass="ui-timepicker-inline";this._currentClass="ui-timepicker-current";this._dayOverClass="ui-timepicker-days-cell-over";this.regional=[];this.regional[""]={hourText:"Hour",minuteText:"Minute",amPmText:["AM","PM"]};this._defaults={showOn:"focus",button:null,showAnim:"fadeIn",showOptions:{},appendText:"",onSelect:null,onClose:null,timeSeparator:":",showPeriod:false,showPeriodLabels:true,showLeadingZero:true,showMinutesLeadingZero:true,altField:"",defaultTime:"now",onHourShow:null,onMinuteShow:null,zIndex:null,hours:{starts:0,ends:23},minutes:{starts:0,ends:55,interval:5},rows:4};$.extend(this._defaults,this.regional[""]);this.tpDiv=$('<div id="'+this._mainDivId+'" class="ui-timepicker ui-widget ui-helper-clearfix ui-corner-all " style="display: none"></div>')}$.extend($.ui,{timepicker:{version:"0.2.3"}});var PROP_NAME="timepicker";var tpuuid=(new Date).getTime();$.extend(Timepicker.prototype,{markerClassName:"hasTimepicker",log:function(){if(this.debug)console.log.apply("",arguments)},_widgetTimepicker:function(){return this.tpDiv},_getTimeTimepicker:function(a){return a?a.value:""},setDefaults:function(a){extendRemove(this._defaults,a||{});return this},_attachTimepicker:function(target,settings){var inlineSettings=null;for(var attrName in this._defaults){var attrValue=target.getAttribute("time:"+attrName);if(attrValue){inlineSettings=inlineSettings||{};try{inlineSettings[attrName]=eval(attrValue)}catch(err){inlineSettings[attrName]=attrValue}}}var nodeName=target.nodeName.toLowerCase();var inline=nodeName=="div"||nodeName=="span";if(!target.id){this.uuid+=1;target.id="tp"+this.uuid}var inst=this._newInst($(target),inline);inst.settings=$.extend({},settings||{},inlineSettings||{});if(nodeName=="input"){this._connectTimepicker(target,inst)}else if(inline){this._inlineTimepicker(target,inst)}},_newInst:function(a,b){var c=a[0].id.replace(/([^A-Za-z0-9_-])/g,"\\\\$1");return{id:c,input:a,inline:b,tpDiv:!b?this.tpDiv:$('<div class="'+this._inlineClass+' ui-timepicker ui-widget  ui-helper-clearfix"></div>')}},_connectTimepicker:function(a,b){var c=$(a);b.append=$([]);b.trigger=$([]);if(c.hasClass(this.markerClassName)){return}this._attachments(c,b);c.addClass(this.markerClassName).keydown(this._doKeyDown).keyup(this._doKeyUp).bind("setData.timepicker",function(a,c,d){b.settings[c]=d}).bind("getData.timepicker",function(a,c){return this._get(b,c)});$.data(a,PROP_NAME,b)},_doKeyDown:function(a){var b=$.timepicker._getInst(a.target);var c=true;b._keyEvent=true;if($.timepicker._timepickerShowing){switch(a.keyCode){case 9:$.timepicker._hideTimepicker();c=false;break;case 13:$.timepicker._updateSelectedValue(b);$.timepicker._hideTimepicker();return false;break;case 27:$.timepicker._hideTimepicker();break;default:c=false}}else if(a.keyCode==36&&a.ctrlKey){$.timepicker._showTimepicker(this)}else{c=false}if(c){a.preventDefault();a.stopPropagation()}},_doKeyUp:function(a){var b=$.timepicker._getInst(a.target);$.timepicker._setTimeFromField(b);$.timepicker._updateTimepicker(b)},_attachments:function(a,b){var c=this._get(b,"appendText");var d=this._get(b,"isRTL");if(b.append){b.append.remove()}if(c){b.append=$('<span class="'+this._appendClass+'">'+c+"</span>");a[d?"before":"after"](b.append)}a.unbind("focus.timepicker",this._showTimepicker);if(b.trigger){b.trigger.remove()}var e=this._get(b,"showOn");if(e=="focus"||e=="both"){a.bind("focus.timepicker",this._showTimepicker)}if(e=="button"||e=="both"){var f=this._get(b,"button");$(f).bind("click.timepicker",function(){if($.timepicker._timepickerShowing&&$.timepicker._lastInput==a[0]){$.timepicker._hideTimepicker()}else{$.timepicker._showTimepicker(a[0])}return false})}},_inlineTimepicker:function(a,b){var c=$(a);if(c.hasClass(this.markerClassName))return;c.addClass(this.markerClassName).append(b.tpDiv).bind("setData.timepicker",function(a,c,d){b.settings[c]=d}).bind("getData.timepicker",function(a,c){return this._get(b,c)});$.data(a,PROP_NAME,b);this._setTimeFromField(b);this._updateTimepicker(b);b.tpDiv.show()},_showTimepicker:function(a){a=a.target||a;if(a.nodeName.toLowerCase()!="input"){a=$("input",a.parentNode)[0]}if($.timepicker._isDisabledTimepicker(a)||$.timepicker._lastInput==a){return}$.timepicker._hideTimepicker();var b=$.timepicker._getInst(a);if($.timepicker._curInst&&$.timepicker._curInst!=b){$.timepicker._curInst.tpDiv.stop(true,true)}var c=$.timepicker._get(b,"beforeShow");extendRemove(b.settings,c?c.apply(a,[a,b]):{});b.lastVal=null;$.timepicker._lastInput=a;$.timepicker._setTimeFromField(b);if($.timepicker._inDialog){a.value=""}if(!$.timepicker._pos){$.timepicker._pos=$.timepicker._findPos(a);$.timepicker._pos[1]+=a.offsetHeight}var d=false;$(a).parents().each(function(){d|=$(this).css("position")=="fixed";return!d});if(d&&$.browser.opera){$.timepicker._pos[0]-=document.documentElement.scrollLeft;$.timepicker._pos[1]-=document.documentElement.scrollTop}var e={left:$.timepicker._pos[0],top:$.timepicker._pos[1]};$.timepicker._pos=null;b.tpDiv.css({position:"absolute",display:"block",top:"-1000px"});$.timepicker._updateTimepicker(b);b._hoursClicked=false;b._minutesClicked=false;e=$.timepicker._checkOffset(b,e,d);b.tpDiv.css({position:$.timepicker._inDialog&&$.blockUI?"static":d?"fixed":"absolute",display:"none",left:e.left+"px",top:e.top+"px"});if(!b.inline){var f=$.timepicker._get(b,"showAnim");var g=$.timepicker._get(b,"duration");var h=$.timepicker._get(b,"zIndex");var i=function(){$.timepicker._timepickerShowing=true;var a=$.timepicker._getBorders(b.tpDiv);b.tpDiv.find("iframe.ui-timepicker-cover").css({left:-a[0],top:-a[1],width:b.tpDiv.outerWidth(),height:b.tpDiv.outerHeight()})};if(!h){h=$(a).zIndex()+1}b.tpDiv.zIndex(h);if($.effects&&$.effects[f]){b.tpDiv.show(f,$.timepicker._get(b,"showOptions"),g,i)}else{b.tpDiv[f||"show"](f?g:null,i)}if(!f||!g){i()}if(b.input.is(":visible")&&!b.input.is(":disabled")){b.input.focus()}$.timepicker._curInst=b}},_updateTimepicker:function(a){var b=this;var c=$.timepicker._getBorders(a.tpDiv);a.tpDiv.empty().append(this._generateHTML(a)).find("iframe.ui-timepicker-cover").css({left:-c[0],top:-c[1],width:a.tpDiv.outerWidth(),height:a.tpDiv.outerHeight()}).end().find(".ui-timepicker-minute-cell").bind("click",{fromDoubleClick:false},$.proxy($.timepicker.selectMinutes,this)).bind("dblclick",{fromDoubleClick:true},$.proxy($.timepicker.selectMinutes,this)).end().find(".ui-timepicker-hour-cell").bind("click",{fromDoubleClick:false},$.proxy($.timepicker.selectHours,this)).bind("dblclick",{fromDoubleClick:true},$.proxy($.timepicker.selectHours,this)).end().find(".ui-timepicker td a").bind("mouseout",function(){$(this).removeClass("ui-state-hover");if(this.className.indexOf("ui-timepicker-prev")!=-1)$(this).removeClass("ui-timepicker-prev-hover");if(this.className.indexOf("ui-timepicker-next")!=-1)$(this).removeClass("ui-timepicker-next-hover")}).bind("mouseover",function(){if(!b._isDisabledTimepicker(a.inline?a.tpDiv.parent()[0]:a.input[0])){$(this).parents(".ui-timepicker-calendar").find("a").removeClass("ui-state-hover");$(this).addClass("ui-state-hover");if(this.className.indexOf("ui-timepicker-prev")!=-1)$(this).addClass("ui-timepicker-prev-hover");if(this.className.indexOf("ui-timepicker-next")!=-1)$(this).addClass("ui-timepicker-next-hover")}}).end().find("."+this._dayOverClass+" a").trigger("mouseover").end()},_generateHTML:function(a){var b,c,d,e="",f=this._get(a,"showPeriod")==true,g=this._get(a,"showPeriodLabels")==true,h=this._get(a,"showLeadingZero")==true,i=this._get(a,"amPmText"),j=this._get(a,"rows"),k=j/2,l=k+1,m=Array(),n=this._get(a,"hours"),o=null,p=0,q=this._get(a,"hourText");for(b=n.starts;b<=n.ends;b++){m.push(b)}o=Math.round(m.length/j+.49);e='<table class="ui-timepicker-table ui-widget-content ui-corner-all"><tr>'+'<td class="ui-timepicker-hours">'+'<div class="ui-timepicker-title ui-widget-header ui-helper-clearfix ui-corner-all">'+q+"</div>"+'<table class="ui-timepicker">';for(d=1;d<=j;d++){e+="<tr>";if(d==1&&g){e+='<th rowspan="'+k.toString()+'" class="periods">'+i[0]+"</th>"}if(d==l&&g){e+='<th rowspan="'+k.toString()+'" class="periods">'+i[1]+"</th>"}while(p<o*d){e+=this._generateHTMLHourCell(a,m[p],f,h);p++}e+="</tr>"}e+="</tr></table>"+"</td>"+'<td class="ui-timepicker-minutes">';e+=this._generateHTMLMinutes(a);e+="</td></tr></table>";e+=$.browser.msie&&parseInt($.browser.version,10)<7&&!a.inline?'<iframe src="javascript:false;" class="ui-timepicker-cover" frameborder="0"></iframe>':"";return e},_updateMinuteDisplay:function(a){var b=this._generateHTMLMinutes(a);a.tpDiv.find("td.ui-timepicker-minutes").html(b).find(".ui-timepicker-minute-cell").bind("click",{fromDoubleClick:false},$.proxy($.timepicker.selectMinutes,this)).bind("dblclick",{fromDoubleClick:true},$.proxy($.timepicker.selectMinutes,this))},_generateHTMLMinutes:function(a){var b,c,d="",e=this._get(a,"rows"),f=Array(),g=this._get(a,"minutes"),h=null,i=0,j=this._get(a,"showMinutesLeadingZero")==true,k=this._get(a,"onMinuteShow"),l=this._get(a,"minuteText");if(!g.starts){g.starts=0}if(!g.ends){g.ends=59}for(b=g.starts;b<=g.ends;b+=g.interval){f.push(b)}h=Math.round(f.length/e+.49);if(k&&k.apply(a.input?a.input[0]:null,[a.hours,a.minutes])==false){for(i=0;i<f.length;i+=1){b=f[i];if(k.apply(a.input?a.input[0]:null,[a.hours,b])){a.minutes=b;break}}}d+='<div class="ui-timepicker-title ui-widget-header ui-helper-clearfix ui-corner-all">'+l+"</div>"+'<table class="ui-timepicker">';i=0;for(c=1;c<=e;c++){d+="<tr>";while(i<c*h){var b=f[i];var m="";if(b!==undefined){m=b<10&&j?"0"+b.toString():b.toString()}d+=this._generateHTMLMinuteCell(a,b,m);i++}d+="</tr>"}d+="</table>";return d},_generateHTMLHourCell:function(a,b,c,d){var e=b;if(b>12&&c){e=b-12}if(e==0&&c){e=12}if(e<10&&d){e="0"+e}var f="";var g=true;var h=this._get(a,"onHourShow");if(b==undefined){f='<td class="ui-state-default ui-state-disabled"> </td>';return f}if(h){g=h.apply(a.input?a.input[0]:null,[b])}if(g){f='<td class="ui-timepicker-hour-cell" data-timepicker-instance-id="#'+a.id.replace("\\\\","\\")+'" data-hour="'+b.toString()+'">'+'<a class="ui-state-default '+(b==a.hours?"ui-state-active":"")+'">'+e.toString()+"</a></td>"}else{f="<td>"+'<span class="ui-state-default ui-state-disabled '+(b==a.hours?" ui-state-active ":" ")+'">'+e.toString()+"</span>"+"</td>"}return f},_generateHTMLMinuteCell:function(a,b,c){var d="";var e=true;var f=this._get(a,"onMinuteShow");if(f){e=f.apply(a.input?a.input[0]:null,[a.hours,b])}if(b==undefined){d='<td class=ui-state-default ui-state-disabled"> </td>';return d}if(e){d='<td class="ui-timepicker-minute-cell" data-timepicker-instance-id="#'+a.id.replace("\\\\","\\")+'" data-minute="'+b.toString()+'" >'+'<a class="ui-state-default '+(b==a.minutes?"ui-state-active":"")+'" >'+c+"</a></td>"}else{d="<td>"+'<span class="ui-state-default ui-state-disabled" >'+c+"</span>"+"</td>"}return d},_isDisabledTimepicker:function(a){if(!a){return false}for(var b=0;b<this._disabledInputs.length;b++){if(this._disabledInputs[b]==a){return true}}return false},_checkOffset:function(a,b,c){var d=a.tpDiv.outerWidth();var e=a.tpDiv.outerHeight();var f=a.input?a.input.outerWidth():0;var g=a.input?a.input.outerHeight():0;var h=document.documentElement.clientWidth+$(document).scrollLeft();var i=document.documentElement.clientHeight+$(document).scrollTop();b.left-=this._get(a,"isRTL")?d-f:0;b.left-=c&&b.left==a.input.offset().left?$(document).scrollLeft():0;b.top-=c&&b.top==a.input.offset().top+g?$(document).scrollTop():0;b.left-=Math.min(b.left,b.left+d>h&&h>d?Math.abs(b.left+d-h):0);b.top-=Math.min(b.top,b.top+e>i&&i>e?Math.abs(e+g):0);return b},_findPos:function(a){var b=this._getInst(a);var c=this._get(b,"isRTL");while(a&&(a.type=="hidden"||a.nodeType!=1)){a=a[c?"previousSibling":"nextSibling"]}var d=$(a).offset();return[d.left,d.top]},_getBorders:function(a){var b=function(a){return{thin:1,medium:2,thick:3}[a]||a};return[parseFloat(b(a.css("border-left-width"))),parseFloat(b(a.css("border-top-width")))]},_checkExternalClick:function(a){if(!$.timepicker._curInst){return}var b=$(a.target);if(b[0].id!=$.timepicker._mainDivId&&b.parents("#"+$.timepicker._mainDivId).length==0&&!b.hasClass($.timepicker.markerClassName)&&!b.hasClass($.timepicker._triggerClass)&&$.timepicker._timepickerShowing&&!($.timepicker._inDialog&&$.blockUI))$.timepicker._hideTimepicker()},_hideTimepicker:function(a){var b=this._curInst;if(!b||a&&b!=$.data(a,PROP_NAME)){return}if(this._timepickerShowing){var c=this._get(b,"showAnim");var d=this._get(b,"duration");var e=function(){$.timepicker._tidyDialog(b);this._curInst=null};if($.effects&&$.effects[c]){b.tpDiv.hide(c,$.timepicker._get(b,"showOptions"),d,e)}else{b.tpDiv[c=="slideDown"?"slideUp":c=="fadeIn"?"fadeOut":"hide"](c?d:null,e)}if(!c){e()}var f=this._get(b,"onClose");if(f){f.apply(b.input?b.input[0]:null,[b.input?b.input.val():"",b])}this._timepickerShowing=false;this._lastInput=null;if(this._inDialog){this._dialogInput.css({position:"absolute",left:"0",top:"-100px"});if($.blockUI){$.unblockUI();$("body").append(this.tpDiv)}}this._inDialog=false}},_tidyDialog:function(a){a.tpDiv.removeClass(this._dialogClass).unbind(".ui-timepicker")},_getInst:function(a){try{return $.data(a,PROP_NAME)}catch(b){throw"Missing instance data for this timepicker"}},_get:function(a,b){return a.settings[b]!==undefined?a.settings[b]:this._defaults[b]},_setTimeFromField:function(a){if(a.input.val()==a.lastVal){return}var b=this._get(a,"defaultTime");var c=b=="now"?this._getCurrentTimeRounded(a):b;if(a.inline==false&&a.input.val()!=""){c=a.input.val()}var d=a.lastVal=c;if(c==""){a.hours=-1;a.minutes=-1}else{var e=this.parseTime(a,d);a.hours=e.hours;a.minutes=e.minutes}$.timepicker._updateTimepicker(a)},_setTimeTimepicker:function(a,b){var c=this._getInst(a);if(c){this._setTime(c,b);this._updateTimepicker(c);this._updateAlternate(c,b)}},_setTime:function(a,b,c){var d=a.hours;var e=a.minutes;var b=this.parseTime(a,b);a.hours=b.hours;a.minutes=b.minutes;if((d!=a.hours||e!=a.minuts)&&!c){a.input.trigger("change")}this._updateTimepicker(a);this._updateSelectedValue(a)},_getCurrentTimeRounded:function(a){var b=new Date;var c=this._get(a,"timeSeparator");var d=b.getMinutes();d=Math.round(d/5)*5;return b.getHours().toString()+c+d.toString()},parseTime:function(a,b){var c=new Object;c.hours=-1;c.minutes=-1;var d=this._get(a,"timeSeparator");var e=this._get(a,"amPmText");var f=b.indexOf(d);if(f==-1){return c}c.hours=parseInt(b.substr(0,f),10);c.minutes=parseInt(b.substr(f+1),10);var g=this._get(a,"showPeriod")==true;var h=b.toUpperCase();if(c.hours<12&&g&&h.indexOf(e[1].toUpperCase())!=-1){c.hours+=12}if(c.hours==12&&g&&h.indexOf(e[0].toUpperCase())!=-1){c.hours=0}return c},selectHours:function(a){var b=$(a.currentTarget);var c=b.attr("data-timepicker-instance-id");var d=b.attr("data-hour");var e=a.data.fromDoubleClick;var f=$(c);var g=this._getInst(f[0]);b.parents(".ui-timepicker-hours:first").find("a").removeClass("ui-state-active");b.children("a").addClass("ui-state-active");g.hours=d;this._updateSelectedValue(g);g._hoursClicked=true;if(g._minutesClicked||e){$.timepicker._hideTimepicker();return false}var h=this._get(g,"onMinuteShow");if(h){this._updateMinuteDisplay(g)}return false},selectMinutes:function(a){var b=$(a.currentTarget);var c=b.attr("data-timepicker-instance-id");var d=b.attr("data-minute");var e=a.data.fromDoubleClick;var f=$(c);var g=this._getInst(f[0]);b.parents(".ui-timepicker-minutes:first").find("a").removeClass("ui-state-active");b.children("a").addClass("ui-state-active");g.minutes=d;this._updateSelectedValue(g);g._minutesClicked=true;if(g._hoursClicked||e){$.timepicker._hideTimepicker();return false}return false},_updateSelectedValue:function(a){if(a.hours<0||a.hours>23){a.hours=12}if(a.minutes<0||a.minutes>59){a.minutes=0}var b="";var c=this._get(a,"showPeriod")==true;var d=this._get(a,"showLeadingZero")==true;var e=this._get(a,"amPmText");var f=a.hours?a.hours:0;var g=a.minutes?a.minutes:0;var h=f;if(!h){h=0}if(c){if(a.hours==0){h=12}if(a.hours<12){b=e[0]}else{b=e[1];if(h>12){h-=12}}}var i=h.toString();if(d&&h<10){i="0"+i}var j=g.toString();if(g<10){j="0"+j}var k=i+this._get(a,"timeSeparator")+j;if(b.length>0){k+=" "+b}if(a.input){a.input.val(k);a.input.trigger("change")}var l=this._get(a,"onSelect");if(l){l.apply(a.input?a.input[0]:null,[k,a])}this._updateAlternate(a,k);return k},_updateAlternate:function(a,b){var c=this._get(a,"altField");if(c){$(c).each(function(a,c){$(c).val(b)})}}});$.fn.timepicker=function(a){if(!$.timepicker.initialized){$(document).mousedown($.timepicker._checkExternalClick).find("body").append($.timepicker.tpDiv);$.timepicker.initialized=true}var b=Array.prototype.slice.call(arguments,1);if(typeof a=="string"&&(a=="isDisabled"||a=="getTime"||a=="widget"))return $.timepicker["_"+a+"Timepicker"].apply($.timepicker,[this[0]].concat(b));if(a=="option"&&arguments.length==2&&typeof arguments[1]=="string")return $.timepicker["_"+a+"Timepicker"].apply($.timepicker,[this[0]].concat(b));return this.each(function(){typeof a=="string"?$.timepicker["_"+a+"Timepicker"].apply($.timepicker,[this].concat(b)):$.timepicker._attachTimepicker(this,a)})};$.timepicker=new Timepicker;$.timepicker.initialized=false;$.timepicker.uuid=(new Date).getTime();$.timepicker.version="0.2.3";window["TP_jQuery_"+tpuuid]=$})(jQuery)
