﻿var TopDestinations = new function () {

	var me = this;
	this.CurrentLeft = 0;
	this.TargetLeft = 0;
	this.CurrentTab = 1;

	this.Width;
	this.Holder;

	this.StartTime;
	this.Seconds;



	this.Setup = function (sHolder, iWidth, iSeconds) {
		this.Holder = f.GetObject(sHolder);
		this.Width = iWidth;
		this.Seconds = iSeconds;
	}


	this.ShowTab = function (iTab) {

		//slide to right position
		this.TargetLeft = -(iTab * this.Width) + this.Width;
		this.StartTime = new Date();
		this.Slide();

		//set tab class
		f.RemoveClass('aDestinationTab_' + this.CurrentTab, 'selected');
		this.CurrentTab = iTab;
		f.AddClass('aDestinationTab_' + this.CurrentTab, 'selected');
	}


	this.Slide = function () {
		var nFractionDone = Math.abs((new Date() - me.StartTime) / me.Seconds / 1000);
		if (nFractionDone < 1) {
			me.Holder.style.left = me.CurrentLeft + (me.TargetLeft - me.CurrentLeft) * Math.sin(Math.PI / 2 * nFractionDone) + 'px';
			setTimeout('TopDestinations.Slide();', 20);
		} else {
			me.Holder.style.left = me.TargetLeft + 'px';
			me.CurrentLeft = me.TargetLeft;
		}
	}


	this.Search = function (iPropertyPriceCacheID) {
		ff.Call('Widgets.TopDestinations.HotelSearch', function (sResult) { TopDestinations.SearchComplete(sResult); }, iPropertyPriceCacheID);
		ShowWaitMessage();
	}


	this.SearchComplete = function (sResult) {

		if (sResult == 'Success' || sResult == 'PriceChange' || sResult == 'OtherResults') {
			window.location = '/PropertyResults.aspx';
		}

	}

}
