(function(k){function j(b){var c=k.data(b,"datetimebox");var d=c.options;k(b).datebox(k.extend({},d,{onShowPanel:function(){var m=k(b).datetimebox("getValue");i(b,m,true);d.onShowPanel.call(b)}}));k(b).removeClass("datebox-f").addClass("datetimebox-f");k(b).datebox("calendar").calendar({onSelect:function(m){d.onSelect.call(b,m)}});var f=k(b).datebox("panel");if(!c.spinner){var a=k('<div style="padding:2px"><input style="width:80px"></div>').insertAfter(f.children("div.datebox-calendar-inner"));c.spinner=a.children("input");c.spinner.timespinner({showSeconds:true}).bind("mousedown",function(m){m.stopPropagation()});i(b,d.value);var n=f.children("div.datebox-button");var e=k('<a href="javascript:void(0)" class="datebox-ok"></a>').html(d.okText).appendTo(n);e.hover(function(){k(this).addClass("datebox-button-hover")},function(){k(this).removeClass("datebox-button-hover")}).click(function(){h(b)})}}function l(c){var a=k(c).datetimebox("calendar");var b=k(c).datetimebox("spinner");var d=a.calendar("options").current;return new Date(d.getFullYear(),d.getMonth(),d.getDate(),b.timespinner("getHours"),b.timespinner("getMinutes"),b.timespinner("getSeconds"))}function g(b,a){i(b,a,true)}function h(a){var b=k.data(a,"datetimebox").options;var c=l(a);i(a,b.formatter(c));k(a).combo("hidePanel")}function i(a,b,c){var d=k.data(a,"datetimebox").options;k(a).combo("setValue",b);if(!c){if(b){var e=d.parser(b);k(a).combo("setValue",d.formatter(e));k(a).combo("setText",d.formatter(e))}else{k(a).combo("setText",b)}}var e=d.parser(b);k(a).datetimebox("calendar").calendar("moveTo",d.parser(b));k(a).datetimebox("spinner").timespinner("setValue",f(e));function f(p){function q(m){return(m<10?"0":"")+m}var r=[q(p.getHours()),q(p.getMinutes())];if(d.showSeconds){r.push(q(p.getSeconds()))}return r.join(k(a).datetimebox("spinner").timespinner("options").separator)}}k.fn.datetimebox=function(a,b){if(typeof a=="string"){var c=k.fn.datetimebox.methods[a];if(c){return c(this,b)}else{return this.datebox(a,b)}}a=a||{};return this.each(function(){var d=k.data(this,"datetimebox");if(d){k.extend(d.options,a)}else{k.data(this,"datetimebox",{options:k.extend({},k.fn.datetimebox.defaults,k.fn.datetimebox.parseOptions(this),a)})}j(this)})};k.fn.datetimebox.methods={options:function(a){return k.data(a[0],"datetimebox").options},spinner:function(a){return k.data(a[0],"datetimebox").spinner},setValue:function(a,b){return a.each(function(){i(this,b)})}};k.fn.datetimebox.parseOptions=function(b){var a=k(b);return k.extend({},k.fn.datebox.parseOptions(b),{})};k.fn.datetimebox.defaults=k.extend({},k.fn.datebox.defaults,{showSeconds:true,keyHandler:{up:function(){},down:function(){},enter:function(){h(this)},query:function(a){g(this,a)}},formatter:function(a){var d=a.getHours();var b=a.getMinutes();var e=a.getSeconds();function c(f){return(f<10?"0":"")+f}return k.fn.datebox.defaults.formatter(a)+" "+c(d)+":"+c(b)+":"+c(e)},parser:function(e){if(k.trim(e)==""){return new Date()}var c=e.split(" ");var a=k.fn.datebox.defaults.parser(c[0]);var f=c[1].split(":");var b=parseInt(f[0],10);var d=parseInt(f[1],10);var n=parseInt(f[2],10);return new Date(a.getFullYear(),a.getMonth(),a.getDate(),b,d,n)}})})(jQuery);