/*!
 * jQuery UI Timepicker 0.2.1
 *
 * Copyright (c) 2009 Martin Milesich (http://milesich.com/)
 *
 * Some parts are
 *   Copyright (c) 2009 AUTHORS.txt (http://jqueryui.com/about)
 *
 * $Id: jquery.ui.timepicker.js,v 1.5 2010/10/16 12:15:25 lorenzo Exp $
 *
 * Depends:
 *  ui.core.js
 *  ui.datepicker.js
 *  ui.slider.js
 */
(function($) {

/**
 * Extending default values
 */
$.extend($.datepicker._defaults, {
	'stepMinutes': 1, // Number of minutes to step up/down
	'stepHours': 1, // Number of hours to step up/down
	'time24h': false, // True if 24h time
	'showTime': false, // Show timepicker with datepicker
	'altTimeField': '' // Selector for an alternate field to store time into
});

var dpuuid = new Date().getTime();

/**
 * _hideDatepicker must be called with null
 */
$.datepicker._connectDatepickerOverride = $.datepicker._connectDatepicker;
$.datepicker._connectDatepicker = function(target, inst) {
	$.datepicker._connectDatepickerOverride(target, inst);

	// showButtonPanel is required with timepicker
	if (this._get(inst, 'showTime')) {
		inst.settings['showButtonPanel'] = true;
	}

	var showOn = this._get(inst, 'showOn');

	if (showOn == 'button' || showOn == 'both') {
		// Unbind all click events
		inst.trigger.unbind('click');
		// Bind new click event
		inst.trigger.click(function() {
			if ($.datepicker._datepickerShowing && $.datepicker._lastInput == target)
				$.datepicker._hideDatepicker(null); // This override is all about the "null"
			else
				$.datepicker._showDatepicker(target);
			return false;
		});
	}
};

$.datepicker._generateHTMLOverride = $.datepicker._generateHTML;
$.datepicker._generateHTML = function( inst ) {
	var today = new Date();
	today = this._daylightSavingAdjust(
		new Date(today.getFullYear(), today.getMonth(), today.getDate())); // clear time
	var isRTL = this._get(inst, 'isRTL');
	var showButtonPanel = this._get(inst, 'showButtonPanel');
	var hideIfNoPrevNext = this._get(inst, 'hideIfNoPrevNext');
	var navigationAsDateFormat = this._get(inst, 'navigationAsDateFormat');
	var numMonths = this._getNumberOfMonths(inst);
	var showCurrentAtPos = this._get(inst, 'showCurrentAtPos');
	var stepMonths = this._get(inst, 'stepMonths');
	var isMultiMonth = (numMonths[0] != 1 || numMonths[1] != 1);
	var currentDate = this._daylightSavingAdjust((!inst.currentDay ? new Date(9999, 9, 9) :
		new Date(inst.currentYear, inst.currentMonth, inst.currentDay)));
	var minDate = this._getMinMaxDate(inst, 'min');
	var maxDate = this._getMinMaxDate(inst, 'max');
	var drawMonth = inst.drawMonth - showCurrentAtPos;
	var drawYear = inst.drawYear;
	if (drawMonth < 0) {
		drawMonth += 12;
		drawYear--;
	}
	if (maxDate) {
		var maxDraw = this._daylightSavingAdjust(new Date(maxDate.getFullYear(),
			maxDate.getMonth() - (numMonths[0] * numMonths[1]) + 1, maxDate.getDate()));
		maxDraw = (minDate && maxDraw < minDate ? minDate : maxDraw);
		while (this._daylightSavingAdjust(new Date(drawYear, drawMonth, 1)) > maxDraw) {
			drawMonth--;
			if (drawMonth < 0) {
				drawMonth = 11;
				drawYear--;
			}
		}
	}
	inst.drawMonth = drawMonth;
	inst.drawYear = drawYear;
	var prevText = this._get(inst, 'prevText');
	prevText = (!navigationAsDateFormat ? prevText : this.formatDate(prevText,
		this._daylightSavingAdjust(new Date(drawYear, drawMonth - stepMonths, 1)),
		this._getFormatConfig(inst)));
	var prev = (this._canAdjustMonth(inst, -1, drawYear, drawMonth) ?
		'<a class="ui-datepicker-prev ui-corner-all" onclick="DP_jQuery_' + dpuuid +
		'.datepicker._adjustDate(\'#' + inst.id + '\', -' + stepMonths + ', \'M\');"' +
		' title="' + prevText + '"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'e' : 'w') + '">' + prevText + '</span></a>' :
		(hideIfNoPrevNext ? '' : '<a class="ui-datepicker-prev ui-corner-all ui-state-disabled" title="'+ prevText +'"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'e' : 'w') + '">' + prevText + '</span></a>'));
	var nextText = this._get(inst, 'nextText');
	nextText = (!navigationAsDateFormat ? nextText : this.formatDate(nextText,
		this._daylightSavingAdjust(new Date(drawYear, drawMonth + stepMonths, 1)),
		this._getFormatConfig(inst)));
	var next = (this._canAdjustMonth(inst, +1, drawYear, drawMonth) ?
		'<a class="ui-datepicker-next ui-corner-all" onclick="DP_jQuery_' + dpuuid +
		'.datepicker._adjustDate(\'#' + inst.id + '\', +' + stepMonths + ', \'M\');"' +
		' title="' + nextText + '"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'w' : 'e') + '">' + nextText + '</span></a>' :
		(hideIfNoPrevNext ? '' : '<a class="ui-datepicker-next ui-corner-all ui-state-disabled" title="'+ nextText + '"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'w' : 'e') + '">' + nextText + '</span></a>'));
	var currentText = this._get(inst, 'currentText');
	var gotoDate = (this._get(inst, 'gotoCurrent') && inst.currentDay ? currentDate : today);
	currentText = (!navigationAsDateFormat ? currentText :
		this.formatDate(currentText, gotoDate, this._getFormatConfig(inst)));
	var controls = '';
	if (!inst.inline) controls+='<button type="button" class="ui-datepicker-close ui-state-default ui-priority-primary ui-corner-all" onclick="DP_jQuery_' + dpuuid +
		'.datepicker._hideDatepicker(';
	if (this._get(inst, 'showTime')) {
		controls+="null";
	}
	if (!inst.inline) controls+=');">' + this._get(inst, 'closeText') + '</button>';
	var buttonPanel = (showButtonPanel) ? '<div class="ui-datepicker-buttonpane ui-widget-content">' + (isRTL ? controls : '') +
		(this._isInRange(inst, gotoDate) ? '<button type="button" class="ui-datepicker-current ui-state-default ui-priority-secondary ui-corner-all" onclick="DP_jQuery_' + dpuuid +
		'.datepicker._gotoToday(\'#' + inst.id + '\');"' +
		'>' + currentText + '</button>' : '') + (isRTL ? '' : controls) + '</div>' : '';
	var firstDay = parseInt(this._get(inst, 'firstDay'),10);
	firstDay = (isNaN(firstDay) ? 0 : firstDay);
	var showWeek = this._get(inst, 'showWeek');
	var dayNames = this._get(inst, 'dayNames');
	var dayNamesShort = this._get(inst, 'dayNamesShort');
	var dayNamesMin = this._get(inst, 'dayNamesMin');
	var monthNames = this._get(inst, 'monthNames');
	var monthNamesShort = this._get(inst, 'monthNamesShort');
	var beforeShowDay = this._get(inst, 'beforeShowDay');
	var showOtherMonths = this._get(inst, 'showOtherMonths');
	var selectOtherMonths = this._get(inst, 'selectOtherMonths');
	var calculateWeek = this._get(inst, 'calculateWeek') || this.iso8601Week;
	var defaultDate = this._getDefaultDate(inst);
	var html = '';
	for (var row = 0; row < numMonths[0]; row++) {
		var group = '';
		for (var col = 0; col < numMonths[1]; col++) {
			var selectedDate = this._daylightSavingAdjust(new Date(drawYear, drawMonth, inst.selectedDay));
			var cornerClass = ' ui-corner-all';
			var calender = '';
			if (isMultiMonth) {
				calender += '<div class="ui-datepicker-group';
				if (numMonths[1] > 1)
					switch (col) {
						case 0: calender += ' ui-datepicker-group-first';
							cornerClass = ' ui-corner-' + (isRTL ? 'right' : 'left'); break;
						case numMonths[1]-1: calender += ' ui-datepicker-group-last';
							cornerClass = ' ui-corner-' + (isRTL ? 'left' : 'right'); break;
						default: calender += ' ui-datepicker-group-middle'; cornerClass = ''; break;
					}
				calender += '">';
			}
			calender += '<div class="ui-datepicker-header ui-widget-header ui-helper-clearfix' + cornerClass + '">' +
				(/all|left/.test(cornerClass) && row == 0 ? (isRTL ? next : prev) : '') +
				(/all|right/.test(cornerClass) && row == 0 ? (isRTL ? prev : next) : '') +
				this._generateMonthYearHeader(inst, drawMonth, drawYear, minDate, maxDate,
				row > 0 || col > 0, monthNames, monthNamesShort) + // draw month headers
				'</div><table class="ui-datepicker-calendar"><thead>' +
				'<tr>';
			var thead = (showWeek ? '<th class="ui-datepicker-week-col">' + this._get(inst, 'weekHeader') + '</th>' : '');
			for (var dow = 0; dow < 7; dow++) { // days of the week
				var day = (dow + firstDay) % 7;
				thead += '<th' + ((dow + firstDay + 6) % 7 >= 5 ? ' class="ui-datepicker-week-end"' : '') + '>' +
					'<span title="' + dayNames[day] + '">' + dayNamesMin[day] + '</span></th>';
			}
			calender += thead + '</tr></thead><tbody>';
			var daysInMonth = this._getDaysInMonth(drawYear, drawMonth);
			if (drawYear == inst.selectedYear && drawMonth == inst.selectedMonth)
				inst.selectedDay = Math.min(inst.selectedDay, daysInMonth);
			var leadDays = (this._getFirstDayOfMonth(drawYear, drawMonth) - firstDay + 7) % 7;
			var numRows = (isMultiMonth ? 6 : Math.ceil((leadDays + daysInMonth) / 7)); // calculate the number of rows to generate
			var printDate = this._daylightSavingAdjust(new Date(drawYear, drawMonth, 1 - leadDays));
			for (var dRow = 0; dRow < numRows; dRow++) { // create date picker rows
				calender += '<tr>';
				var tbody = (!showWeek ? '' : '<td class="ui-datepicker-week-col">' +
					this._get(inst, 'calculateWeek')(printDate) + '</td>');
				for (var dow = 0; dow < 7; dow++) { // create date picker days
					var daySettings = (beforeShowDay ?
						beforeShowDay.apply((inst.input ? inst.input[0] : null), [printDate]) : [true, '']);
					var otherMonth = (printDate.getMonth() != drawMonth);
					var unselectable = (otherMonth && !selectOtherMonths) || !daySettings[0] ||
						(minDate && printDate < minDate) || (maxDate && printDate > maxDate);
					tbody += '<td class="' +
						((dow + firstDay + 6) % 7 >= 5 ? ' ui-datepicker-week-end' : '') + // highlight weekends
						(otherMonth ? ' ui-datepicker-other-month' : '') + // highlight days from other months
						((printDate.getTime() == selectedDate.getTime() && drawMonth == inst.selectedMonth && inst._keyEvent) || // user pressed key
						(defaultDate.getTime() == printDate.getTime() && defaultDate.getTime() == selectedDate.getTime()) ?
						// or defaultDate is current printedDate and defaultDate is selectedDate
						' ' + this._dayOverClass : '') + // highlight selected day
						(unselectable ? ' ' + this._unselectableClass + ' ui-state-disabled': '') +  // highlight unselectable days
						(otherMonth && !showOtherMonths ? '' : ' ' + daySettings[1] + // highlight custom dates
						(printDate.getTime() == currentDate.getTime() ? ' ' + this._currentClass : '') + // highlight selected day
						(printDate.getTime() == today.getTime() ? ' ui-datepicker-today' : '')) + '"' + // highlight today (if different)
						((!otherMonth || showOtherMonths) && daySettings[2] ? ' title="' + daySettings[2] + '"' : '') + // cell title
						(unselectable ? '' : ' onclick="DP_jQuery_' + dpuuid + '.datepicker._selectDay(\'#' +
						inst.id + '\',' + printDate.getMonth() + ',' + printDate.getFullYear() + ', this);return false;"') + '>' + // actions
						(otherMonth && !showOtherMonths ? '&#xa0;' : // display for other months
						(unselectable ? '<span class="ui-state-default">' + printDate.getDate() + '</span>' : '<a class="ui-state-default' +
						(printDate.getTime() == today.getTime() ? ' ui-state-highlight' : '') +
						(printDate.getTime() == selectedDate.getTime() ? ' ui-state-active' : '') + // highlight selected day
						(otherMonth ? ' ui-priority-secondary' : '') + // distinguish dates from other months
						'" href="#">' + printDate.getDate() + '</a>')) + '</td>'; // display selectable date
					printDate.setDate(printDate.getDate() + 1);
					printDate = this._daylightSavingAdjust(printDate);
				}
				calender += tbody + '</tr>';
			}
			drawMonth++;
			if (drawMonth > 11) {
				drawMonth = 0;
				drawYear++;
			}
			calender += '</tbody></table>' + (isMultiMonth ? '</div>' + 
						((numMonths[0] > 0 && col == numMonths[1]-1) ? '<div class="ui-datepicker-row-break"></div>' : '') : '');
			group += calender;
		}
		html += group;
	}
	html += buttonPanel + ($.browser.msie && parseInt($.browser.version,10) < 7 && !inst.inline ?
		'<iframe src="javascript:false;" class="ui-datepicker-cover" frameborder="0"></iframe>' : '');
	inst._keyEvent = false;
	return html;
}

/**
 * Datepicker does not have an onShow event so I need to create it.
 * What I actually doing here is copying original _showDatepicker
 * method to _showDatepickerOverload method.
 */
$.datepicker._showDatepickerOverride = $.datepicker._showDatepicker;
$.datepicker._showDatepicker = function (input) {
	// Call the original method which will show the datepicker
	$.datepicker._showDatepickerOverride(input);

	input = input.target || input;

	// find from button/image trigger
	if (input.nodeName.toLowerCase() != 'input') input = $('input', input.parentNode)[0];

	// Do not show timepicker if datepicker is disabled
	if ($.datepicker._isDisabledDatepicker(input)) return;

	// Get instance to datepicker
	var inst = $.datepicker._getInst(input);

	var showTime = $.datepicker._get(inst, 'showTime');

	// If showTime = True show the timepicker
	if (showTime) $.timepicker.show(input);
};

/**
 * Same as above. Here I need to extend the _checkExternalClick method
 * because I don't want to close the datepicker when the sliders get focus.
 */
$.datepicker._checkExternalClickOverride = $.datepicker._checkExternalClick;
$.datepicker._checkExternalClick = function (event) {
	if (!$.datepicker._curInst) return;
	var $target = $(event.target);

	if (($target.parents('#' + $.timepicker._mainDivId).length == 0)) {
		$.datepicker._checkExternalClickOverride(event);
	}
};

/**
 * Datepicker has onHide event but I just want to make it simple for you
 * so I hide the timepicker when datepicker hides.
 * SL 101016 - update to conform jquery ui 1.8.5
 */
$.datepicker._hideDatepickerOverride = $.datepicker._hideDatepicker;
$.datepicker._hideDatepicker = function(input, duration) {
	var inst = this._curInst;
	var showTime = this._get(inst,'showTime');

	if (showTime) {
		if (typeof inst == "undefined" || (input && inst != $.data(input, PROP_NAME))) return;

		if (typeof input != 'undefined' && inst.input) {
			$.timepicker.update(this._formatDate(inst));
			/*
			inst.input.val( this._formatDate( inst ) );
			inst.input.trigger('change');
			this._updateAlternate(inst);
			*/
		}
		this._hideDatepickerOverride( input , duration );
		$.timepicker.hide();
	} else {
		this._hideDatepickerOverride( input , duration );
		return;
	}
};

/**
 * This is a complete replacement of the _selectDate method.
 * If showed with timepicker do not close when date is selected.
 */
$.datepicker._selectDate = function(id, dateStr) {
	var target = $(id);
	var inst = this._getInst(target[0]);
	var showTime = this._get(inst, 'showTime');
	dateStr = (dateStr != null ? dateStr : this._formatDate(inst));
	if (!showTime) {
		if (inst.input)
			inst.input.val(dateStr);
		this._updateAlternate(inst);
	}
	var onSelect = this._get(inst, 'onSelect');
	if (onSelect)
		onSelect.apply((inst.input ? inst.input[0] : null), [dateStr, inst]);  // trigger custom callback
	else if (inst.input && !showTime)
		inst.input.trigger('change'); // fire the change event
	if (inst.inline)
		this._updateDatepicker(inst);
	else if (!inst.stayOpen) {
		if (showTime) {
			this._updateDatepicker(inst);
		} else {
			this._hideDatepicker(null, this._get(inst, 'duration'));
			this._lastInput = inst.input[0];
			if (typeof(inst.input[0]) != 'object')
				inst.input[0].focus(); // restore focus
			this._lastInput = null;
		}
	}
};

/**
 * We need to resize the timepicker when the datepicker has been changed.
 */
$.datepicker._updateDatepickerOverride = $.datepicker._updateDatepicker;
$.datepicker._updateDatepicker = function(inst) {
	$.datepicker._updateDatepickerOverride(inst);
	$.timepicker.resize();
};

function Timepicker() {}

Timepicker.prototype = {
	init: function()
	{
		this._mainDivId = 'ui-timepicker-div';
		this._inputId   = null;
		this._orgValue  = null;
		this._orgHour   = null;
		this._orgMinute = null;
		this._colonPos  = -1;
		this._hourText  = 'hour';
		this._minText   = 'min';
		this._initialized = false;

		this._visible   = false;
		this.tpDiv	  = $('<div id="' + this._mainDivId + '" class="ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all ui-helper-hidden-accessible" style="width: 100px; display: none; position: absolute;"></div>');
	},

	show: function (input)
	{
		// Get instance to datepicker
		var inst = $.datepicker._getInst(input);

		this._time24h = $.datepicker._get(inst, 'time24h');
		this._altTimeField = $.datepicker._get(inst, 'altTimeField');
		this._hourText = $.datepicker._get(inst,'hourText');
		this._minText = $.datepicker._get(inst,'minText');
		
		this._generateTimepickerHtml();

		var stepMinutes = parseInt($.datepicker._get(inst, 'stepMinutes'), 10) || 1;
		var stepHours   = parseInt($.datepicker._get(inst, 'stepHours'), 10)   || 1;

		if (60 % stepMinutes != 0) { stepMinutes = 1; }
		if (24 % stepHours != 0)   { stepHours   = 1; }

		$('#hourSlider').slider('option', 'max', 24 - stepHours);
		$('#hourSlider').slider('option', 'step', stepHours);

		$('#minuteSlider').slider('option', 'max', 60 - stepMinutes);
		$('#minuteSlider').slider('option', 'step', stepMinutes);

		this._inputId = input.id;

		if (!this._visible) {
			this._parseTime();
			this._orgValue = $('#' + this._inputId).val();
		}

		this.resize();

		$('#' + this._mainDivId).show();

		this._visible = true;

		var dpDiv	 = $('#' + $.datepicker._mainDivId);
		var dpDivPos  = dpDiv.position();

		var viewWidth = (window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth) + $(document).scrollLeft();
		var tpRight   = this.tpDiv.offset().left + this.tpDiv.outerWidth();

		if (tpRight > viewWidth) {
			dpDiv.css('left', dpDivPos.left - (tpRight - viewWidth) - 5);
			this.tpDiv.css('left', dpDiv.offset().left + dpDiv.outerWidth() + 'px');
		}
	},

	update: function (fd)
	{
		var curTime = $('#' + this._mainDivId + ' span.fragHours').text()
					+ ':'
					+ $('#' + this._mainDivId + ' span.fragMinutes').text();

		if (!this._time24h) {
			curTime += ' ' + $('#' + this._mainDivId + ' span.fragAmpm').text();
		}

		var curDate = $('#' + this._inputId).val();

		$('#' + this._inputId).val(fd + ' ' + curTime);

		if (this._altTimeField) {
			$(this._altTimeField).each(function() { $(this).val(curTime); });
		}
	},

	hide: function ()
	{
		this._visible = false;
		$('#' + this._mainDivId).hide();
	},

	resize: function ()
	{
		var dpDiv = $('#' + $.datepicker._mainDivId);
		var dpDivPos = dpDiv.position();

		var hdrHeight = $('#' + $.datepicker._mainDivId +  ' > div.ui-datepicker-header:first-child').height();

		$('#' + this._mainDivId + ' > div.ui-datepicker-header:first-child').css('height', hdrHeight);

		this.tpDiv.css({
			'height': dpDiv.height(),
			'top'   : dpDivPos.top,
			'left'  : dpDivPos.left + dpDiv.outerWidth() + 'px'
		});

		$('#hourSlider').css('height',   this.tpDiv.height() - (3.5 * hdrHeight));
		$('#minuteSlider').css('height', this.tpDiv.height() - (3.5 * hdrHeight));
	},

	_generateTimepickerHtml: function ()
	{
		if (this._initialized) return;

		var html = '';

		html += '<div class="ui-datepicker-header ui-widget-header ui-helper-clearfix ui-corner-all">';
		html += '<div class="ui-datepicker-title" style="margin:0">';
		html += '<span class="fragHours">08</span><span class="delim">:</span><span class="fragMinutes">45</span> <span class="fragAmpm"></span></div></div><table>';
		html += '<tr><th>'+this._hourText+'</th><th>'+this._minText+'</th></tr>';
		html += '<tr><td align="center"><div id="hourSlider" class="slider"></div></td><td align="center"><div id="minuteSlider" class="slider"></div></td></tr>';
		html += '</table>';

		this.tpDiv.empty().append(html);
		$('body').append(this.tpDiv);

		var self = this;

		$('#hourSlider').slider({
			orientation: "vertical",
			range: 'min',
			min: 0,
			max: 23,
			step: 1,
			slide: function(event, ui) {
				self._writeTime('hour', ui.value);
			},
			stop: function(event, ui) {
				$('#' + self._inputId).focus();
			}
		});

		$('#minuteSlider').slider({
			orientation: "vertical",
			range: 'min',
			min: 0,
			max: 59,
			step: 1,
			slide: function(event, ui) {
				self._writeTime('minute', ui.value);
			},
			stop: function(event, ui) {
				$('#' + self._inputId).focus();
			}
		});

		$('#hourSlider > a').css('padding', 0);
		$('#minuteSlider > a').css('padding', 0);
		this._initialized = true;
	},

	_writeTime: function (type, value)
	{
		if (type == 'hour') {
			if (!this._time24h) {
				if (value < 12) {
					$('#' + this._mainDivId + ' span.fragAmpm').text('am');
				} else {
					$('#' + this._mainDivId + ' span.fragAmpm').text('pm');
					value -= 12;
				}

				if (value == 0) value = 12;
			} else {
				$('#' + this._mainDivId + ' span.fragAmpm').text('');
			}

			if (value < 10) value = '0' + value;
			$('#' + this._mainDivId + ' span.fragHours').text(value);
		}

		if (type == 'minute') {
			if (value < 10) value = '0' + value;
			$('#' + this._mainDivId + ' span.fragMinutes').text(value);
		}
	},

	_parseTime: function ()
	{
		var dt = $('#' + this._inputId).val();

		this._colonPos = dt.search(':');

		var m = 0, h = 0, a = '';

		if (this._colonPos != -1) {
			h = parseInt(dt.substr(this._colonPos - 2, 2), 10);
			m = parseInt(dt.substr(this._colonPos + 1, 2), 10);
			a = jQuery.trim(dt.substr(this._colonPos + 3, 3));
		}

		a = a.toLowerCase();

		if (a != 'am' && a != 'pm') {
			a = '';
		}

		if (h < 0) h = 0;
		if (m < 0) m = 0;

		if (h > 23) h = 23;
		if (m > 59) m = 59;

		if (a == 'pm' && h  < 12) h += 12;
		if (a == 'am' && h == 12) h  = 0;

		this._setTime('hour',   h);
		this._setTime('minute', m);

		this._orgHour   = h;
		this._orgMinute = m;
	},

	_setTime: function (type, value)
	{
		if (isNaN(value)) value = 0;
		if (value < 0)	value = 0;
		if (value > 23 && type == 'hour')   value = 23;
		if (value > 59 && type == 'minute') value = 59;

		if (type == 'hour') {
			$('#hourSlider').slider('value', value);
		}

		if (type == 'minute') {
			$('#minuteSlider').slider('value', value);
		}

		this._writeTime(type, value);
	}
};

$.timepicker = new Timepicker();
$('document').ready(function () {$.timepicker.init();});

window['DP_jQuery_' + dpuuid] = $;

})(jQuery);

