﻿jcContScroll = function() {
    this.buttons = null;
    this.timers = new Array();
};
jcContScroll.prototype.extend = $.extend;
jcContScroll.prototype.extend({
	initialize: function(carousel) {
		var container = carousel.container;

		this.buttons = $('div.jcarousel-next, div.jcarousel-prev', container);
		var mouseDownCallback = Function.createDelegate(this, this.buttonMouseDown);
		var mouseUpCallback = Function.createDelegate(this, this.buttonMouseUp);
		var mouseOutCallback = Function.createDelegate(this, this.buttonMouseUp);
		this.buttons.each(function() {
			$(this).bind('mousedown', mouseDownCallback);
			$(this).bind('mouseup', mouseUpCallback);
			$(this).bind('mouseout', mouseOutCallback);
		});
		
		if (
		container.find('ul.jcarousel-list, ul.jcarousel-list-horizontal').width() <=
		container.find('div.jcarousel-clip, div.jcarousel-clip-horizontal').width()) {
			$('div.jcarousel-next, div.jcarousel-prev', container).hide();
			return;
		}
	},
	buttonMouseDown: function(e) {
		var callback = Function.createDelegate(this, function() { this.onTimer(e.target); });
		this.timers[e.target] = setTimeout(callback, 500);
	},
	buttonMouseUp: function(e) {
		var timerId = this.timers[e.target];
		if (typeof (timerId) != 'undefined') {
			clearTimeout(timerId);
			this.timers[e.target] = undefined;
			return false;
		}
	},
	onTimer: function(target) {
		$(target).click();
		var timerId = this.timers[target];
		if (typeof (timerId) != 'undefined') {
			$(target).trigger('mousedown');
		}
	}
});
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();