PricesController.prototype = new PastelBaseController();
PricesController.prototype.constructor = PricesController;

/**
 * @constructor
 * @base PastelBaseController
 */
function PricesController() {
	// options ====================================================================================
	this.setOpts({
		viewClass: PricesView,
		viewSelector: "div.id_prices_page_cont",
		wrapperSelector: "div.left",
		viewRemoveOnHide: true,
		ajaxSingleRequest: false,
		ajaxUrl: "/index/prices/"
	});

	// setup ======================================================================================
	/** @param {PricesView} view */
	this._setupView = function(view) {
		// setup cursors
		this._setupCursors(view);
	};
	
	/** @param {PricesView} view */
	this._setupCursors = function(view) {
		
		var subscriptionCalc = new SubscriptionCalc();
		
		// price cursor
		var priceLeftOffset = 0;
		var priceGridSize = 12;
		view.priceCursor().draggable({
			axis: "x",
			containment: "parent",
			scroll: false,
			grid: [priceGridSize, 0],
			drag: $.proxy(function() {
				var offset = view.getCursorOffset(view.priceCursor());
				if(offset != priceLeftOffset) {
					priceLeftOffset = offset;
					var step = offset / priceGridSize;
					var priceProps = subscriptionCalc.calculatePrice(step);
					view.updatePriceSummary(priceProps);
				}
			}, this)			
		});
		
		var monthLeftOffset = 0;
		var monthGridSize = 30;
		
		view.monthCursor().draggable({
			axis: "x",
			containment: "parent",
			scroll: false,
			grid: [monthGridSize, 0],
			drag: $.proxy(function() {
				var offset = view.getCursorOffset(view.monthCursor());
				if(offset != monthLeftOffset) {
					monthLeftOffset = offset;
					var step = offset / monthGridSize;
					var priceProps = subscriptionCalc.calculateDiscount(step);
					view.updatePriceSummary(priceProps);
				}
			}, this)				
		});			
	};
}

