!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):a(jQuery)}(function(a){function g(a){if(a.minTime&&(a.minTime=w(a.minTime)),a.maxTime&&(a.maxTime=w(a.maxTime)),a.durationTime&&"function"!=typeof a.durationTime&&(a.durationTime=w(a.durationTime)),a.disableTimeRanges.length>0){for(var b in a.disableTimeRanges)a.disableTimeRanges[b]=[w(a.disableTimeRanges[b][0]),w(a.disableTimeRanges[b][1])];a.disableTimeRanges=a.disableTimeRanges.sort(function(a,b){return a[0]-b[0]});for(var b=a.disableTimeRanges.length-1;b>0;b--)a.disableTimeRanges[b][0]<=a.disableTimeRanges[b-1][1]&&(a.disableTimeRanges[b-1]=[Math.min(a.disableTimeRanges[b][0],a.disableTimeRanges[b-1][0]),Math.max(a.disableTimeRanges[b][1],a.disableTimeRanges[b-1][1])],a.disableTimeRanges.splice(b,1))}return a}function h(b){var d=b.data("timepicker-settings"),e=b.data("timepicker-list");if(e&&e.length&&(e.remove(),b.data("timepicker-list",!1)),d.useSelect){e=a("<select />",{"class":"ui-timepicker-select"});var g=e}else{e=a("<ul />",{"class":"ui-timepicker-list"});var g=a("<div />",{"class":"ui-timepicker-wrapper",tabindex:-1});g.css({display:"none",position:"absolute"}).append(e)}d.noneOption&&(d.useSelect?e.append(a('<option value="">Time...</option>')):e.append(a("<li>None</li>"))),d.className&&g.addClass(d.className),null===d.minTime&&null===d.durationTime||!d.showDuration||g.addClass("ui-timepicker-with-duration");var h=d.minTime;"function"==typeof d.durationTime?h=w(d.durationTime()):null!==d.durationTime&&(h=d.durationTime);var j=null!==d.minTime?d.minTime:0,k=null!==d.maxTime?d.maxTime:j+c-1;j>=k&&(k+=c),k===c-1&&-1!==d.timeFormat.indexOf("H")&&(k=c);for(var m=d.disableTimeRanges,o=0,p=m.length,r=j;k>=r;r+=60*d.step){var s=r,x=v(s,d.timeFormat);if(d.useSelect){var y=a("<option />",{value:x});y.text(x)}else{var y=a("<li />");y.data("time",86400>=s?s:s%86400),y.text(x)}if((null!==d.minTime||null!==d.durationTime)&&d.showDuration){var z=u(r-h);if(d.useSelect)y.text(y.text()+" ("+z+")");else{var A=a("<span />",{"class":"ui-timepicker-duration"});A.text(" ("+z+")"),y.append(A)}}p>o&&(s>=m[o][1]&&(o+=1),m[o]&&s>=m[o][0]&&s<m[o][1]&&(d.useSelect?y.prop("disabled",!0):y.addClass("ui-timepicker-disabled"))),e.append(y)}if(g.data("timepicker-input",b),b.data("timepicker-list",g),d.useSelect)e.val(i(b.val(),d)),e.on("focus",function(){a(this).data("timepicker-input").trigger("showTimepicker")}),e.on("blur",function(){a(this).data("timepicker-input").trigger("hideTimepicker")}),e.on("change",function(){q(b,a(this).val(),"select")}),b.hide().after(e);else{var B=d.appendTo;"string"==typeof B?B=a(B):"function"==typeof B&&(B=B(b)),B.append(g),n(b,e),e.on("click","li",function(){b.off("focus.timepicker"),b.on("focus.timepicker-ie-hack",function(){b.off("focus.timepicker-ie-hack"),b.on("focus.timepicker",f.show)}),l(b)||b[0].focus(),e.find("li").removeClass("ui-timepicker-selected"),a(this).addClass("ui-timepicker-selected"),t(b)&&(b.trigger("hideTimepicker"),g.hide())})}}function i(b,c){if(a.isNumeric(b)||(b=w(b)),null===b)return null;var d=60*c.step;return v(Math.round(b/d)*d,c.timeFormat)}function j(){return new Date(1970,1,1,0,0,0)}function k(b){var c=a(b.target),d=c.closest(".ui-timepicker-input");0===d.length&&0===c.closest(".ui-timepicker-wrapper").length&&(f.hide(),a(document).unbind(".ui-timepicker"))}function l(a){var b=a.data("timepicker-settings");return(window.navigator.msMaxTouchPoints||"ontouchstart"in document)&&b.disableTouchKeyboard}function m(b,c,d){if(!d&&0!==d)return!1;var e=b.data("timepicker-settings"),f=!1,g=30*e.step;return c.find("li").each(function(b,c){var e=a(c),h=e.data("time")-d;return Math.abs(h)<g||h==g?(f=e,!1):void 0}),f}function n(a,b){b.find("li").removeClass("ui-timepicker-selected");var c=w(p(a));if(null!==c){var d=m(a,b,c);if(d){var e=d.offset().top-b.offset().top;(e+d.outerHeight()>b.outerHeight()||0>e)&&b.scrollTop(b.scrollTop()+d.position().top-d.outerHeight()),d.addClass("ui-timepicker-selected")}}}function o(){if(""!==this.value){var b=a(this),c=b.data("timepicker-list");if(!c||!c.is(":visible")){var d=w(this.value);if(null===d)return b.trigger("timeFormatError"),void 0;var e=b.data("timepicker-settings"),f=!1;if(null!==e.minTime&&d<e.minTime?f=!0:null!==e.maxTime&&d>e.maxTime&&(f=!0),a.each(e.disableTimeRanges,function(){return d>=this[0]&&d<this[1]?(f=!0,!1):void 0}),e.forceRoundTime){var g=d%(60*e.step);g>=30*e.step?d+=60*e.step-g:d-=g}var h=v(d,e.timeFormat);f?q(b,h,"error")&&b.trigger("timeRangeError"):q(b,h)}}}function p(a){return a.is("input")?a.val():a.data("ui-timepicker-value")}function q(a,b,c){if(a.is("input")){a.val(b);var d=a.data("timepicker-settings");d.useSelect&&a.data("timepicker-list").val(i(b,d))}return a.data("ui-timepicker-value")!=b?(a.data("ui-timepicker-value",b),"select"==c?a.trigger("selectTime").trigger("changeTime").trigger("change"):"error"!=c&&a.trigger("changeTime"),!0):(a.trigger("selectTime"),!1)}function r(b){var c=a(this),d=c.data("timepicker-list");if(!d||!d.is(":visible")){if(40!=b.keyCode)return!0;l(c)||c.focus()}switch(b.keyCode){case 13:return t(c)&&f.hide.apply(this),b.preventDefault(),!1;case 38:var e=d.find(".ui-timepicker-selected");return e.length?e.is(":first-child")||(e.removeClass("ui-timepicker-selected"),e.prev().addClass("ui-timepicker-selected"),e.prev().position().top<e.outerHeight()&&d.scrollTop(d.scrollTop()-e.outerHeight())):(d.find("li").each(function(b,c){return a(c).position().top>0?(e=a(c),!1):void 0}),e.addClass("ui-timepicker-selected")),!1;case 40:return e=d.find(".ui-timepicker-selected"),0===e.length?(d.find("li").each(function(b,c){return a(c).position().top>0?(e=a(c),!1):void 0}),e.addClass("ui-timepicker-selected")):e.is(":last-child")||(e.removeClass("ui-timepicker-selected"),e.next().addClass("ui-timepicker-selected"),e.next().position().top+2*e.outerHeight()>d.outerHeight()&&d.scrollTop(d.scrollTop()+e.outerHeight())),!1;case 27:d.find("li").removeClass("ui-timepicker-selected"),f.hide();break;case 9:f.hide();break;default:return!0}}function s(b){var c=a(this),d=c.data("timepicker-list");if(!d||!d.is(":visible"))return!0;if(!c.data("timepicker-settings").typeaheadHighlight)return d.find("li").removeClass("ui-timepicker-selected"),!0;switch(b.keyCode){case 96:case 97:case 98:case 99:case 100:case 101:case 102:case 103:case 104:case 105:case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:case 65:case 77:case 80:case 186:case 8:case 46:n(c,d);break;default:return}}function t(a){var b=a.data("timepicker-settings"),c=a.data("timepicker-list"),d=null,e=c.find(".ui-timepicker-selected");if(e.hasClass("ui-timepicker-disabled"))return!1;if(e.length?d=e.data("time"):p(a)&&(d=w(p(a)),n(a,c)),null!==d){var f=v(d,b.timeFormat);q(a,f,"select")}return!0}function u(a){var c,b=Math.round(a/60);if(Math.abs(b)<60)c=[b,e.mins];else if(60==b)c=["1",e.hr];else{var d=(b/60).toFixed(1);"."!=e.decimal&&(d=d.replace(".",e.decimal)),c=[d,e.hrs]}return c.join(" ")}function v(a,d){if(null!==a){var e=new Date(b.valueOf()+1e3*a);if(!isNaN(e.getTime())){for(var g,h,f="",i=0;i<d.length;i++)switch(h=d.charAt(i)){case"a":f+=e.getHours()>11?"pm":"am";break;case"A":f+=e.getHours()>11?"PM":"AM";break;case"g":g=e.getHours()%12,f+=0===g?"12":g;break;case"G":f+=e.getHours();break;case"h":g=e.getHours()%12,0!==g&&10>g&&(g="0"+g),f+=0===g?"12":g;break;case"H":g=e.getHours(),a===c&&(g=24),f+=g>9?g:"0"+g;break;case"i":var j=e.getMinutes();f+=j>9?j:"0"+j;break;case"s":a=e.getSeconds(),f+=a>9?a:"0"+a;break;default:f+=h}return f}}}function w(a){if(""===a)return null;if(!a||a+0==a)return a;"object"==typeof a&&(a=a.getHours()+":"+x(a.getMinutes())+":"+x(a.getSeconds())),a=a.toLowerCase(),new Date(0);var c;if(-1===a.indexOf(":")?(c=a.match(/^([0-9]):?([0-5][0-9])?:?([0-5][0-9])?\s*([pa]?)m?$/),c||(c=a.match(/^([0-2][0-9]):?([0-5][0-9])?:?([0-5][0-9])?\s*([pa]?)m?$/))):c=a.match(/^(\d{1,2})(?::([0-5][0-9]))?(?::([0-5][0-9]))?\s*([pa]?)m?$/),!c)return null;var e,d=parseInt(1*c[1],10);e=c[4]?12==d?"p"==c[4]?12:0:d+("p"==c[4]?12:0):d;var f=1*c[2]||0,g=1*c[3]||0;return 3600*e+60*f+g}function x(a){return("0"+a).slice(-2)}var b=j(),c=86400,d={className:null,minTime:null,maxTime:null,durationTime:null,step:30,showDuration:!1,timeFormat:"g:ia",scrollDefaultNow:!1,scrollDefaultTime:!1,selectOnBlur:!1,disableTouchKeyboard:!1,forceRoundTime:!1,appendTo:"body",disableTimeRanges:[],closeOnWindowScroll:!1,typeaheadHighlight:!0,noneOption:!1},e={decimal:".",mins:"mins",hr:"hr",hrs:"hrs"},f={init:function(b){return this.each(function(){var c=a(this),i=[];for(key in d)c.data(key)&&(i[key]=c.data(key));var j=a.extend({},d,i,b);j.lang&&(e=a.extend(e,j.lang)),j=g(j),c.data("timepicker-settings",j),c.addClass("ui-timepicker-input"),j.useSelect?h(c):(c.prop("autocomplete","off"),c.on("click.timepicker focus.timepicker",f.show),c.on("change.timepicker",o),c.on("keydown.timepicker",r),c.on("keyup.timepicker",s),o.call(c.get(0)))})},show:function(b){b&&b.preventDefault();var c=a(this),d=c.data("timepicker-settings");if(d.useSelect)return c.data("timepicker-list").focus(),void 0;l(c)&&c.blur();var e=c.data("timepicker-list");if(!c.prop("readonly")&&(e&&0!==e.length&&"function"!=typeof d.durationTime||(h(c),e=c.data("timepicker-list")),!e.is(":visible"))){f.hide(),e.show(),c.offset().top+c.outerHeight(!0)+e.outerHeight()>a(window).height()+a(window).scrollTop()?e.offset({left:c.offset().left+parseInt(e.css("marginLeft").replace("px",""),10),top:c.offset().top-e.outerHeight()+parseInt(e.css("marginTop").replace("px",""),10)}):e.offset({left:c.offset().left+parseInt(e.css("marginLeft").replace("px",""),10),top:c.offset().top+c.outerHeight()+parseInt(e.css("marginTop").replace("px",""),10)});var g=e.find(".ui-timepicker-selected");if(g.length||(p(c)?g=m(c,e,w(p(c))):d.scrollDefaultNow?g=m(c,e,w(new Date)):d.scrollDefaultTime!==!1&&(g=m(c,e,w(d.scrollDefaultTime)))),g&&g.length){var i=e.scrollTop()+g.position().top-g.outerHeight();e.scrollTop(i)}else e.scrollTop(0);return a(document).on("touchstart.ui-timepicker mousedown.ui-timepicker",k),d.closeOnWindowScroll&&a(document).on("scroll.ui-timepicker",k),c.trigger("showTimepicker"),this}},hide:function(){var c=a(this),d=c.data("timepicker-settings");return d&&d.useSelect&&c.blur(),a(".ui-timepicker-wrapper:visible").each(function(){var b=a(this),c=b.data("timepicker-input"),d=c.data("timepicker-settings");d&&d.selectOnBlur&&t(c),b.hide(),c.trigger("hideTimepicker")}),this},option:function(b,c){var d=this,e=d.data("timepicker-settings"),f=d.data("timepicker-list");if("object"==typeof b)e=a.extend(e,b);else if("string"==typeof b&&"undefined"!=typeof c)e[b]=c;else if("string"==typeof b)return e[b];return e=g(e),d.data("timepicker-settings",e),f&&(f.remove(),d.data("timepicker-list",!1)),e.useSelect&&h(d),this},getSecondsFromMidnight:function(){return w(p(this))},getTime:function(a){var b=this,c=p(b);return c?(a||(a=new Date),a.setHours(0,0,0,0),new Date(a.valueOf()+1e3*w(c))):null},setTime:function(a){var b=this,c=v(w(a),b.data("timepicker-settings").timeFormat);return q(b,c),b.data("timepicker-list")&&n(b,b.data("timepicker-list")),this},remove:function(){var a=this;if(a.hasClass("ui-timepicker-input"))return a.removeAttr("autocomplete","off"),a.removeClass("ui-timepicker-input"),a.removeData("timepicker-settings"),a.off(".timepicker"),a.data("timepicker-list")&&a.data("timepicker-list").remove(),a.removeData("timepicker-list"),this}};a.fn.timepicker=function(b){return this.length?f[b]?f[b].apply(this,Array.prototype.slice.call(arguments,1)):"object"!=typeof b&&b?(a.error("Method "+b+" does not exist on jQuery.timepicker"),void 0):f.init.apply(this,arguments):this}});
