﻿// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Permissive License.
// See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx.
// All other rights reserved.


/// <reference name="MicrosoftAjax.debug.js" />
/// <reference name="MicrosoftAjaxTimer.debug.js" />
/// <reference name="MicrosoftAjaxWebForms.debug.js" />
/// <reference path="../ExtenderBase/BaseScripts.js" />
/// <reference path="../Common/Common.js" />
/// <reference path="../DynamicPopulate/DynamicPopulateBehavior.js" />


Type.registerNamespace("TripzoomLib");

TripzoomLib.ScrollBars = function() { }
TripzoomLib.ScrollBars.prototype = {
    None : 0x00,
    Horizontal : 0x01,
    Vertical : 0x02,
    Both : 0x03,
    Auto : 0x04
}
TripzoomLib.ScrollBars.registerEnum("TripzoomLib.ScrollBars", true);

TripzoomLib.TabContainer = function(element) {
	TripzoomLib.TabContainer.initializeBase(this, [element]);
	this._cachedActiveTabIndex = -1;
	this._activeTabIndex = -1;
	this._scrollBars = TripzoomLib.ScrollBars.None;
	this._tablines = null;
	this._tabs = null;
	this._header = null;
	this._body = null;
	this._loaded = false;
	this._autoPostBackId = null;
	this._tabscroller = null;
	this._resizeDelegate = null;
	this._app_onload$delegate = Function.createDelegate(this, this._app_onload);


}
TripzoomLib.TabContainer.prototype = {

	add_activeTabChanged: function(handler) {
		this.get_events().addHandler("activeTabChanged", handler);
	},
	remove_activeTabChanged: function(handler) {
		this.get_events().removeHandler("activeTabChanged", handler);
	},
	raiseActiveTabChanged: function() {
		var eh = this.get_events().getHandler("activeTabChanged");
		if (eh) {
			eh(this, Sys.EventArgs.Empty);
		}
		if (this._autoPostBackId) {
			__doPostBack(this._autoPostBackId, "activeTabChanged:" + this.get_activeTabIndex());
		}
	},

	get_activeTabIndex: function() {
		if (this._cachedActiveTabIndex > -1) {
			return this._cachedActiveTabIndex;
		}
		return this._activeTabIndex;
	},
	set_activeTabIndex: function(value) {
		if (!this.get_isInitialized()) {
			this._cachedActiveTabIndex = value;
		} else {

			if (value < -1 || value >= this.get_tabs().length) {
				throw Error.argumentOutOfRange("value");
			}
			if (this._activeTabIndex != -1) {
				this.get_tabs()[this._activeTabIndex]._set_active(false);
			}
			this._activeTabIndex = value;
			if (this._activeTabIndex != -1) {
				this.get_tabs()[this._activeTabIndex]._set_active(true);
			}
			if (this._loaded) {
				this.raiseActiveTabChanged();
			}
			this.raisePropertyChanged("activeTabIndex");
		}
	},

	get_tabs: function() {
		if (this._tabs == null) {
			this._tabs = [];
		}
		return this._tabs;
	},

	get_tablines: function() {
		if (this._tablines == null) {
			this._tablines = [];
		}
		return this._tablines;
	},

	get_activeTab: function() {
		if (this._activeTabIndex > -1) {
			return this.get_tabs()[this._activeTabIndex];
		}
		return null;
	},
	set_activeTab: function(value) {
		var i = Array.indexOf(this.get_tabs(), value);
		if (i == -1) {
			throw Error.argument("value", AjaxControlToolkit.Resources.Tabs_ActiveTabArgumentOutOfRange);
		}
		this.set_activeTabIndex(i);
	},

	get_autoPostBackId: function() {
		return this._autoPostBackId;
	},
	set_autoPostBackId: function(value) {
		this._autoPostBackId = value;
	},
	get_scrollBars: function() {
		return this._scrollBars;
	},
	set_scrollBars: function(value) {
		if (this._scrollBars != value) {
			this._scrollBars = value;
			this._invalidate();
			this.raisePropertyChanged("scrollBars");
		}
	},

	get_tabscroller: function() {
		return this._tabscroller;
	},
	set_tabscroller: function(value) {
		this._tabscroller = value;
	},

	get_header: function() {
		return this._header;
	},
	get_body: function() {
		return this._body;
	},

	initialize: function() {
		TripzoomLib.TabContainer.callBaseMethod(this, "initialize");

		//Sys.Debug.trace("TabContainer.initialize() : " + this.get_id());

		var elt = this.get_element();
		elt.style.position = "relative";
		var header = this._header = $get(this.get_id() + "_header");
		var body = this._body = $get(this.get_id() + "_body");

		// default classes
		$common.addCssClasses(elt, [
            "ajax__tab_container",
            "ajax__tab_default"
        ]);
		Sys.UI.DomElement.addCssClass(header, "ajax__tab_header");
		Sys.UI.DomElement.addCssClass(body, "ajax__tab_body");


		this._invalidate();

		if (!this._resizeDelegate)
			this._resizeDelegate = Function.createDelegate(this, this._raiseResize);
		$addHandler(window, "resize", this._resizeDelegate); 	  // ie resize event
		$addHandler(document.body, "resize", this._resizeDelegate);   // firefox resize event

		//run delegate function on Application Load event
		Sys.Application.add_load(this._app_onload$delegate);
	},

	dispose: function() {
		Sys.Application.remove_load(this._app_onload$delegate);
		TripzoomLib.TabContainer.callBaseMethod(this, "dispose");
	},

	getFirstTab: function(includeDisabled) {
		var tabs = this.get_tabs();
		for (var i = 0; i < tabs.length; i++) {
			if (includeDisabled || tabs[i].get_enabled()) {
				return tabs[i];
			}
		}
		return null;
	},

	/// <summary>Used in TabScroller</summary>
	getFirstVisibleTab: function(includeDisabled) {
		var tabs = this.get_tabs();
		for (var i = 0; i < tabs.length; i++) {
			if (tabs[i].get_visible() && (includeDisabled || tabs[i].get_enabled())) {
				return tabs[i];
			}
		}
		return null;
	},


	getLastTab: function(includeDisabled) {
		var tabs = this.get_tabs();
		for (var i = tabs.length - 1; i >= 0; i--) {
			if (includeDisabled || tabs[i].get_enabled()) {
				return tabs[i];
			}
		}
		return null;
	},

	getLastHiddenTab: function(includeDisabled) {
		/// <summary>Used in TabScroller</summary>
		var tabs = this.get_tabs();
		for (var i = tabs.length - 1; i >= 0; i--) {
			if (!tabs[i].get_visible() && (includeDisabled || tabs[i].get_enabled())) {
				return tabs[i];
			}
		}
		return null;
	},

	getNextTab: function(includeDisabled) {
		var tabs = this.get_tabs();
		var active = this.get_activeTabIndex();
		for (var i = 1; i < tabs.length; i++) {
			var tabIndex = (active + i) % tabs.length;
			var tab = tabs[tabIndex];
			if (includeDisabled || tab.get_enabled())
				return tab;
		}
		return null;
	},
	getPreviousTab: function(includeDisabled) {
		var tabs = this.get_tabs();
		var active = this.get_activeTabIndex();
		for (var i = 1; i < tabs.length; i++) {
			var tabIndex = (tabs.length + (active - i)) % tabs.length;
			var tab = tabs[tabIndex];
			if (includeDisabled || tab.get_enabled())
				return tab;
		}
		return null;
	},
	getNearestTab: function() {
		var prev = this.getPreviousTab(false);
		var next = this.getNextTab(false);
		if (prev && prev.get_tabIndex() < this._activeTabIndex) {
			return prev;
		} else if (next && next.get_tabIndex() > this._activeTabIndex) {
			return next;
		}
		return null;
	},
	saveClientState: function() {
		var tabs = this.get_tabs();
		var tabState = [];
		for (var i = 0; i < tabs.length; i++) {
			Array.add(tabState, tabs[i].get_enabled());
		}
		var state = {
			ActiveTabIndex: this._activeTabIndex,
			TabState: tabState
		};
		return Sys.Serialization.JavaScriptSerializer.serialize(state);
	},

	_invalidate: function() {
		if (this.get_isInitialized()) {
			$common.removeCssClasses(this._body, [
                "ajax__scroll_horiz",
                "ajax__scroll_vert",
                "ajax__scroll_both",
                "ajax__scroll_auto"
            ]);
			switch (this._scrollBars) {
				case TripzoomLib.ScrollBars.Horizontal:
					Sys.UI.DomElement.addCssClass(this._body, "ajax__scroll_horiz");
					break;
				case TripzoomLib.ScrollBars.Vertical:
					Sys.UI.DomElement.addCssClass(this._body, "ajax__scroll_vert");
					break;
				case TripzoomLib.ScrollBars.Both:
					Sys.UI.DomElement.addCssClass(this._body, "ajax__scroll_both");
					break;
				case TripzoomLib.ScrollBars.Auto:
					Sys.UI.DomElement.addCssClass(this._body, "ajax__scroll_auto");
					break;
			}

		}
	},

	_raiseResize: function(evt) {
		if (this.get_tabscroller()) {
			var tabs = this.get_tabs();
			for (var i = 0; i < tabs.length; i++) {
				var tab = tabs[i];
				if (tab) 
					tab.set_visible(true);
			}
			this._init_tabscroller();
		}
	},

	_init_tabscroller: function() {
		if (this.get_tabscroller()) {
			var bounds_body = Sys.UI.DomElement.getBounds(this.get_body());
			var bounds_tab = Sys.UI.DomElement.getBounds(this.getLastTab(false).get_headerTab());
			var max_x = bounds_body.x + bounds_body.width;
			this.get_tabscroller().set_visible((bounds_tab.x + bounds_tab.width >= max_x));
		}
	},

	_app_onload: function(sender, e) {
		if (this._cachedActiveTabIndex != -1) {
			this.set_activeTabIndex(this._cachedActiveTabIndex);
			this._cachedActiveTabIndex = -1;
		}

		this._init_tabscroller();
		this._loaded = true;
	}
}
TripzoomLib.TabContainer.registerClass("TripzoomLib.TabContainer", AjaxControlToolkit.ControlBase);




TripzoomLib.TabLine = function(element) {
	TripzoomLib.TabLine.initializeBase(this, [element]);
	this._owner = null;
	this._active = false;
	this._cachedActiveTabIndex = -1;
	this._activeTabIndex = -1;
	this._scrollBars = TripzoomLib.ScrollBars.None;
	this._tabs = null;
	this._tabLineIndex = -1;
};

TripzoomLib.TabLine.prototype = {

	get_owner: function() {
		return this._owner;
	},
	set_owner: function(value) {
		if (this._owner != value) {
			if (this.get_isInitialized()) {
				throw Error.invalidOperation(String.format(AjaxControlToolkit.Resources.Tabs_PropertySetAfterInitialization, 'owner'));
			}
			this._owner = value;
			this.raisePropertyChanged("owner");
		}
	},

	get_tabs: function() {
		if (this._tabs == null) {
			this._tabs = [];
		}
		return this._tabs;
	},

	get_active: function() {
		return this._active;
	},
	set_active: function(value) {
		this._active = value;
		if (value)
			this._activate();
		else
			this._deactivate();
	},

	_activate: function() {
		var lines = this.get_owner().get_tablines();
		for (var i = 0; i < lines.length; i++) {
			Sys.UI.DomElement.removeCssClass(lines[i].get_element(), "ajax__tabline_active");
		}


		var elt = this.get_element();
		$common.setVisible(elt, true);
		var parent = elt.parentNode;
		parent.removeChild(elt);
		parent.appendChild(elt);

		Sys.UI.DomElement.addCssClass(elt, "ajax__tabline_active");

	},

	_deactivate: function() {
		//Sys.Debug.trace("deactivate : " + this.get_element().id);
		var elt = this.get_element();


		$common.setVisible(elt, false);
	},

	initialize: function() {
		TripzoomLib.TabLine.callBaseMethod(this, "initialize");

		//Sys.Debug.trace("TripzoomLib.TabLine.initialize() : " + this.get_id());

		var owner = this.get_owner();
		if (!owner) {
			throw Error.invalidOperation(AjaxControlToolkit.Resources.Tabs_OwnerExpected);
		}

		this._tabLineIndex = owner.get_tablines().length;

		Array.add(owner.get_tablines(), this);

		var elt = this.get_element();
		Sys.UI.DomElement.addCssClass(elt, "ajax__tabline");

	},
	dispose: function() {
		TripzoomLib.TabLine.callBaseMethod(this, "dispose");
	}
};

TripzoomLib.TabLine.registerClass("TripzoomLib.TabLine", AjaxControlToolkit.ControlBase);




TripzoomLib.TabPanel = function(element) {
	TripzoomLib.TabPanel.initializeBase(this, [element]);
	this._active = false;
	this._tab = null;
	this._headerOuter = null;
	this._headerInner = null;
	this._header = null;
	this._owner = null;
	this._enabled = true;
	this._visible = true;
	this._tabIndex = -1;
	this._dynamicContextKey = null;
	this._dynamicServicePath = null;
	this._dynamicServiceMethod = null;
	this._dynamicPopulateBehavior = null;
	this._scrollBars = TripzoomLib.ScrollBars.None;
	this._header_onclick$delegate = Function.createDelegate(this, this._header_onclick);
	this._header_onmouseover$delegate = Function.createDelegate(this, this._header_onmouseover);
	this._header_onmouseout$delegate = Function.createDelegate(this, this._header_onmouseout);
	this._header_onmousedown$delegate = Function.createDelegate(this, this._header_onmousedown);
	this._dynamicPopulate_onpopulated$delegate = Function.createDelegate(this, this._dynamicPopulate_onpopulated);
	this._oncancel$delegate = Function.createDelegate(this, this._oncancel);
}
TripzoomLib.TabPanel.prototype = {

	add_click: function(handler) {
		this.get_events().addHandler("click", handler);
	},
	remove_click: function(handler) {
		this.get_events().removeHandler("click", handler);
	},
	raiseClick: function() {
		var eh = this.get_events().getHandler("click");
		if (eh) {
			eh(this, Sys.EventArgs.Empty);
		}
	},

	add_populating: function(handler) {
		this.get_events().addHandler("populating", handler);
	},
	remove_populating: function(handler) {
		this.get_events().removeHandler("populating", handler);
	},
	raisePopulating: function() {
		var eh = this.get_events().getHandler("populating");
		if (eh) {
			eh(this, Sys.EventArgs.Empty);
		}
	},

	add_populated: function(handler) {
		this.get_events().addHandler("populated", handler);
	},
	remove_populated: function(handler) {
		this.get_events().removeHandler("populated", handler);
	},
	raisePopulated: function() {
		var eh = this.get_events().getHandler("populated");
		if (eh) {
			eh(this, Sys.EventArgs.Empty);
		}
	},

	get_headerText: function() {
		if (this.get_isInitialized()) {
			return this._header.innerHTML;
		}
		return "";
	},
	set_headerText: function(value) {
		if (!this.get_isInitialized()) {
			throw Error.invalidOperation(String.format(AjaxControlToolkit.Resources.Tabs_PropertySetBeforeInitialization, 'headerText'));
		}
		if (this._headerText != value) {
			this._headerTab.innerHTML = value;
			this.raisePropertyChanged("headerText");
		}
	},

	get_headerTab: function() {
		return this._header;
	},
	set_headerTab: function(value) {
		if (this._header != value) {
			if (this.get_isInitialized()) {
				throw Error.invalidOperation(String.format(AjaxControlToolkit.Resources.Tabs_PropertySetAfterInitialization, 'headerTab'));
			}
			this._header = value;
			this.raisePropertyChanged("value");
		}
	},

	get_visible: function() {
		return this._visible;
	},
	set_visible: function(value) {
		if (value != this._visible) {
			this._visible = value;
			if (this.get_isInitialized()) {
				if (!this._visible) {
					this._hide();
				} else if (this._enabled) {
					this._show();
				}
			}
			this.raisePropertyChanged("visible");
		}
	},

	get_enabled: function() {
		return this._enabled;
	},
	set_enabled: function(value) {
		if (value != this._enabled) {
			this._enabled = value;
			if (this.get_isInitialized()) {
				if (!this._enabled) {
					this._hide();
				} else if (this._visible) {
					this._show();
				}
			}
			this.raisePropertyChanged("enabled");
		}
	},

	get_container: function() {
		return this._container;
	},
	set_container: function(value) {
		if (this._container != value) {
			if (this.get_isInitialized()) {
				throw Error.invalidOperation(String.format(AjaxControlToolkit.Resources.Tabs_PropertySetAfterInitialization, 'container'));
			}
			this._container = value;
			this.raisePropertyChanged("container");
		}
	},


	get_owner: function() {
		return this._owner;
	},
	set_owner: function(value) {
		if (this._owner != value) {
			if (this.get_isInitialized()) {
				throw Error.invalidOperation(String.format(AjaxControlToolkit.Resources.Tabs_PropertySetAfterInitialization, 'owner'));
			}
			this._owner = value;
			this.raisePropertyChanged("owner");
		}
	},

	get_scrollBars: function() {
		return this._scrollBars;
	},
	set_scrollBars: function(value) {
		if (this._scrollBars != value) {
			this._scrollBars = value;
			this.raisePropertyChanged("scrollBars");
		}
	},

	get_tabIndex: function() {
		return this._tabIndex;
	},

	get_dynamicContextKey: function() {
		return this._dynamicContextKey;
	},
	set_dynamicContextKey: function(value) {
		if (this._dynamicContextKey != value) {
			this._dynamicContextKey = value;
			this.raisePropertyChanged('dynamicContextKey');
		}
	},

	get_dynamicServicePath: function() {
		return this._dynamicServicePath;
	},
	set_dynamicServicePath: function(value) {
		if (this._dynamicServicePath != value) {
			this._dynamicServicePath = value;
			this.raisePropertyChanged('dynamicServicePath');
		}
	},

	get_dynamicServiceMethod: function() {
		return this._dynamicServiceMethod;
	},
	set_dynamicServiceMethod: function(value) {
		if (this._dynamicServiceMethod != value) {
			this._dynamicServiceMethod = value;
			this.raisePropertyChanged('dynamicServiceMethod');
		}
	},

	_get_active: function() {
		return this._active;
	},
	_set_active: function(value) {
		this._active = value;
		if (value)
			this._activate();
		else
			this._deactivate();
	},

	initialize: function() {
		TripzoomLib.TabPanel.callBaseMethod(this, "initialize");

		//Sys.Debug.trace("TripzoomLib.TabPanel.initialize() : " + this.get_id())

		var container = this.get_container();
		if (!container) {
			throw Error.invalidOperation(AjaxControlToolkit.Resources.Tabs_OwnerExpected);
		}

		this._tabIndex = container.get_tabs().length;

		Array.add(container.get_tabs(), this);

		this._headerOuterWrapper = document.createElement('span');
		this._headerInnerWrapper = document.createElement('span');
		this._tab = document.createElement('span');
		this._tab.id = this.get_id() + "_tab";
		this._header.parentNode.replaceChild(this._tab, this._header);
		this._tab.appendChild(this._headerOuterWrapper);
		this._headerOuterWrapper.appendChild(this._headerInnerWrapper);
		this._headerInnerWrapper.appendChild(this._header);
		$addHandlers(this._header, {
			click: this._header_onclick$delegate,
			mouseover: this._header_onmouseover$delegate,
			mouseout: this._header_onmouseout$delegate,
			mousedown: this._header_onmousedown$delegate,
			dragstart: this._oncancel$delegate,
			selectstart: this._oncancel$delegate,
			select: this._oncancel$delegate
		});
		Sys.UI.DomElement.addCssClass(this._headerOuterWrapper, "ajax__tab_outer");
		Sys.UI.DomElement.addCssClass(this._headerInnerWrapper, "ajax__tab_inner");
		Sys.UI.DomElement.addCssClass(this._header, "ajax__tab_tab");
		Sys.UI.DomElement.addCssClass(this.get_element(), "ajax__tab_panel");

		if (!this._enabled || !this._visible) {
			this._hide();
		}
	},

	dispose: function() {
		if (this._dynamicPopulateBehavior) {
			this._dynamicPopulateBehavior.dispose();
			this._dynamicPopulateBehavior = null;
		}
		$common.removeHandlers(this._header, {
			click: this._header_onclick$delegate,
			mouseover: this._header_onmouseover$delegate,
			mouseout: this._header_onmouseout$delegate,
			mousedown: this._header_onmousedown$delegate,
			dragstart: this._oncancel$delegate,
			selectstart: this._oncancel$delegate,
			select: this._oncancel$delegate
		});
		TripzoomLib.TabPanel.callBaseMethod(this, "dispose");
	},

	populate: function(contextKeyOverride) {
		if (this._dynamicPopulateBehavior && (this._dynamicPopulateBehavior.get_element() != this.get_element())) {
			this._dynamicPopulateBehavior.dispose();
			this._dynamicPopulateBehavior = null;
		}
		if (!this._dynamicPopulateBehavior && this._dynamicServiceMethod) {
			this._dynamicPopulateBehavior = $create(AjaxControlToolkit.DynamicPopulateBehavior, { "ContextKey": this._dynamicContextKey, "ServicePath": this._dynamicServicePath, "ServiceMethod": this._dynamicServiceMethod }, { "populated": this._dynamicPopulate_onpopulated$delegate }, null, this.get_element());
		}
		if (this._dynamicPopulateBehavior) {
			this.raisePopulating();
			this._dynamicPopulateBehavior.populate(contextKeyOverride ? contextKeyOverride : this._dynamicContextKey);
		}
	},

	_activate: function() {
		var elt = this.get_element();
		$common.setVisible(elt, true);
		Sys.UI.DomElement.addCssClass(this._tab, "ajax__tab_active");

		this.get_owner().set_active(true);

		this.populate();

		this._show();

		this._container.get_element().style.visibility = 'visible';
	},
	_deactivate: function() {
		var elt = this.get_element();
		$common.setVisible(elt, false);
		Sys.UI.DomElement.removeCssClass(this._tab, "ajax__tab_active");
	},
	_show: function() {
		this._tab.style.display = '';
	},
	_hide: function() {
		this._tab.style.display = 'none';
		if (this.get_visible()) {
			if (this._get_active()) {
				var next = this._container.getNearestTab(false);
				if (!!next) {
					this._container.set_activeTab(next);
				}
			}
			this._deactivate();
		}
	},
	_header_onclick: function(e) {
		this.raiseClick();
		this.get_container().set_activeTab(this);
	},
	_header_onmouseover: function(e) {
		Sys.UI.DomElement.addCssClass(this._tab, "ajax__tab_hover");
	},
	_header_onmouseout: function(e) {
		Sys.UI.DomElement.removeCssClass(this._tab, "ajax__tab_hover");
	},
	_header_onmousedown: function(e) {
		e.preventDefault();
	},
	_oncancel: function(e) {
		e.stopPropagation();
		e.preventDefault();
	},
	_dynamicPopulate_onpopulated: function(sender, e) {
		this.raisePopulated();
	}
}
TripzoomLib.TabPanel.registerClass("TripzoomLib.TabPanel", Sys.UI.Control);

Type.registerNamespace("TripzoomLib");

TripzoomLib.TabScrollDirection = function() { };
TripzoomLib.TabScrollDirection.prototype = {
	Left : 0x00,
	Right : 0x01
};

TripzoomLib.TabScrollDirection.registerEnum("TripzoomLib.TabScrollDirection", false);

TripzoomLib.TabScroller = function(element) {
	TripzoomLib.TabScroller.initializeBase(this, [element]);

	this._visible = false;
	this._container = null;

	this._scrollLeft = null;
	this._scrollRight = null;

	this._scrollLeftDelegate = null;
	this._scrollRightDelegate = null;

	this._scrollLeftMouseOverDelegate = null;
	this._scrollLeftMouseOutDelegate = null;
	
	this._scrollRightMouseOverDelegate = null;
	this._scrollRightMouseOutDelegate = null;
}

TripzoomLib.TabScroller.prototype = {
	initialize: function() {
		TripzoomLib.TabScroller.callBaseMethod(this, "initialize");

		//Sys.Debug.trace("TripzoomLib.TabScroller.initialize()");

		var elt = this.get_element();

		elt.className = "ajax__tabscroller";
		this._scrollLeft = document.createElement("div");
		this._scrollLeft.className = "ajax__tabscroller_left";
		elt.appendChild(this._scrollLeft);

		this._scrollRight = document.createElement("div");
		this._scrollRight.className = "ajax__tabscroller_right";
		elt.appendChild(this._scrollRight);



		if (!this._scrollLeftDelegate) {
			this._scrollLeftDelegate = Function.createDelegate(this, this._raiseScrollLeft);
		}
		$addHandler(this._scrollLeft, "click", this._scrollLeftDelegate);


		if (!this._scrollLeftMouseOverDelegate) {
			this._scrollLeftMouseOverDelegate = Function.createDelegate(this, this._raiseScrollLeftMouseOver);
		}
		$addHandler(this._scrollLeft, "mouseover", this._scrollLeftMouseOverDelegate);

		if (!this._scrollLeftMouseOutDelegate) {
			this._scrollLeftMouseOutDelegate = Function.createDelegate(this, this._raiseScrollLeftMouseOut);
		}
		$addHandler(this._scrollLeft, "mouseout", this._scrollLeftMouseOutDelegate);


		if (!this._scrollRightDelegate) {
			this._scrollRightDelegate = Function.createDelegate(this, this._raiseScrollRight);
		}
		$addHandler(this._scrollRight, "click", this._scrollRightDelegate);


		if (!this._scrollRightMouseOverDelegate) {
			this._scrollRightMouseOverDelegate = Function.createDelegate(this, this._raiseScrollRightMouseOver);
		}
		$addHandler(this._scrollRight, "mouseover", this._scrollRightMouseOverDelegate);

		if (!this._scrollRightMouseOutDelegate) {
			this._scrollRightMouseOutDelegate = Function.createDelegate(this, this._raiseScrollRightMouseOut);
		}
		$addHandler(this._scrollRight, "mouseout", this._scrollRightMouseOutDelegate);




		if (!this._visible) {
			this._hide();
		}
	},

	dispose: function() {
		TripzoomLib.TabScroller.callBaseMethod(this, "dispose");

		$clearHandlers(this._scrollLeft);
		$clearHandlers(this._scrollRight);


	
	},


	_raiseScrollLeftMouseOver: function(evt) {
		this._scrollLeft.className = "ajax__tabscroller_left_over";
	},

	_raiseScrollLeftMouseOut: function(evt) {
		this._scrollLeft.className = "ajax__tabscroller_left";
	},

	_raiseScrollRightMouseOver: function(evt) {
		this._scrollRight.className = "ajax__tabscroller_right_over";
	},

	_raiseScrollRightMouseOut: function(evt) {
		this._scrollRight.className = "ajax__tabscroller_right";
	},


	_raiseScrollRight: function(evt) {
		var tab = this._container.getLastHiddenTab(false);
		if (tab) {
			tab.set_visible(true);
		} 
	},


	_raiseScrollLeft: function(evt) {
		var tab = this._container.getFirstVisibleTab(false);
		if (tab) {
			tab.set_visible(false);
		}
	},

	get_container: function() {
		return this._container;
	},
	set_container: function(value) {
		this._container = value;
	},
	get_visible: function() {
		return this._visible;
	},

	set_visible: function(value) {
		if (this._visible != value) {
			this._visible = value;
			if (this._visible) {
				this._show();
			} else {
				this._hide();
			}
		}
	},

	_show: function() {
		this.get_element().style.display = '';
	},
	_hide: function() {
		this.get_element().style.display = 'none';
	}

};

TripzoomLib.TabScroller.registerClass("TripzoomLib.TabScroller", Sys.UI.Control);

if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();