YAHOO.namespace("cx.exp.widget.navigation");
YAHOO.cx.exp.widget.navigation = function(config) {
	
	this.isInformation = false;
	this.availDisplay = 'none';
	
	if(config != null)
	{
		this.isInformation = config.isInformation;
		this.availDisplay = config.availDisplay;
	}
	
	this.navigate = function(e, obj)
	{
		var link = YAHOO.util.Dom.get(obj.id + '_link');
		var linkPathName = "";
		if (link) linkPathName = link.pathname;
		var windowLocationPathName = window.location.pathname;
		if (link && windowLocationPathName.indexOf(linkPathName) < 0) {
			window.location.href = link.href;
			return false;
		}
	}
	
	this.select = function(e, obj)
	{
		YAHOO.util.Dom.addClass(obj.id + '_link', 'xp-t-legal');
		YAHOO.util.Dom.removeClass(obj.id + '_highlight', 'xp-b-noXpend');
		YAHOO.util.Dom.removeClass(obj.id + '_link', 'linkUnderline');
		YAHOO.util.Dom.addClass(obj.id + '_link', 'linkNoline');
		YAHOO.util.Dom.addClass(obj.id + '_link', 'isSelectedNow');
	}
	
	this.deselect = function(e, obj)
	{
		YAHOO.util.Dom.removeClass(obj.id + '_link', 'xp-t-legal');
		YAHOO.util.Dom.addClass(obj.id + '_highlight', 'xp-b-noXpend');
		YAHOO.util.Dom.addClass(obj.id + '_link', 'linkUnderline');
		YAHOO.util.Dom.removeClass(obj.id + '_link', 'linkNoline');
		YAHOO.util.Dom.removeClass(obj.id + '_link', 'isSelectedNow');
	}
	
	this.highlight = function(e, obj)
	{
		if(YAHOO.util.Dom.hasClass(obj.id + '_link', 'linkUnderline'))
		{
			YAHOO.util.Dom.removeClass(obj.id + '_link', 'linkUnderline');
			YAHOO.util.Dom.addClass(obj.id + '_link', 'linkNoline');
			YAHOO.util.Dom.addClass(obj.id + '_link', 'xp-t-legal');
			YAHOO.util.Dom.removeClass(obj.id + '_highlight', 'xp-b-noXpend');
		}
	}

	this.lowlight = function(e, obj)
	{
		if(YAHOO.util.Dom.hasClass(obj.id + '_link', 'linkNoline') && !YAHOO.util.Dom.hasClass(obj.id + '_link', 'isSelectedNow'))
		{
			YAHOO.util.Dom.removeClass(obj.id + '_link', 'linkNoline');
			YAHOO.util.Dom.addClass(obj.id + '_link', 'linkUnderline');
			YAHOO.util.Dom.removeClass(obj.id + '_link', 'xp-t-legal');
			YAHOO.util.Dom.addClass(obj.id + '_highlight', 'xp-b-noXpend');
		}
	}

	
	this.pauseAnimations = function()
	{
		if (typeof pauseScroll == 'function') 
				pauseScroll();
				
		if (typeof pauseSlideShow == 'function')
				pauseSlideShow();
	}
	
	// Eliminating the section=tabId parameter from query.
	this.removeSectionParameter = function(queryString)
	{
		var result = queryString.replace(/section\=([^&]*)(&)?/, '');
		
		if(result == "?")
		{
			result = "";
		}
		
		return result;
	}
	
	this.bindNavigation = function(obj)
	{
		YAHOO.util.Event.addListener(obj.id, "click", function (evt) {
				link = YAHOO.util.Dom.get(obj.id + '_link');
				href = link.getAttribute("href");
				section = YAHOO.util.History.getQueryStringParameter("section", href);

				// if we navigate to a page not changeable by js -->
				if (link)
				{
					linkPathName = link.pathname;
					linkQueryString = navigation.removeSectionParameter(link.search);						
				}
				var windowLocationPathName = window.location.pathname;
				if (href && windowLocationPathName.indexOf(linkPathName) < 0) {
					window.location.href = linkPathName + linkQueryString + "#nav=" + section;
					return false;
				}
				
				try {
					YAHOO.util.History.navigate("nav", section);
				} catch (e) {
					navigation.loadSection(section);
				}
				YAHOO.util.Event.preventDefault(evt);
				window.scrollTo(0, 0);
		});
	}
	
	// Event handler for anchors to support the new JS navigation with Borwser History Manager.
	this.bindLinkNavigation = function(e, obj)
	{
		try {
			YAHOO.util.History.navigate("nav", obj.nav);
		} catch (e) {
			this.loadSection(obj.nav);
		}
		YAHOO.util.Event.preventDefault(e);
	}
	
	this.loadSection = function(section)
	{
		
		if (section == 'overview')
		{
			this.changeDisplayGroup(null, {group: 1, id: ""});
		}
		else if (section == 'picturesAndTours')
		{
			this.changeDisplayGroup(null, {group: 2, id: ""});
		}
		else if (section == 'details')
		{
			this.changeDisplayGroup(null, {group: 3, id: ""});
		}
		else if (section == 'roomsAndRates')
		{
			this.changeDisplayGroup(null, {group: 4, id: ""});
		}
		else if (this.isInformation)
		{
				this.changeDisplayGroup(null, {group: 5, id: ""});
		}
		else
		{
				this.changeDisplayGroup(null, {group: 0, id: ""});
		}
		return false;
	}
	

	
	this.changeDisplayGroup = function(e, o)
	{
		var link = YAHOO.util.Dom.get(o.id + '_link');
		var group = o.group;
		var linkPathName = "";
		if (link) linkPathName = link.pathname;
		var windowLocationPathName = window.location.pathname;
		if (link && windowLocationPathName.indexOf(linkPathName) < 0) {
			window.location.href = link.href;
			return false;
		}
		
		
		var galleryMediaPreviewWidget = document.getElementById('galleryMediaPreview');
		var overviewWidget = document.getElementById('hotel-infosite-overview');
		var reviewSummaryWidget = document.getElementById('hotel-infosite-reviewSummary');
		var recentReviewsWidget = document.getElementById('hotel-infosite-recentReviews');
		var recentReviewsWriteNewReviewLink = document.getElementById('hotel-infosite-write-review-link');
		var writeFirstReviewLink = document.getElementById('hotel-infosite-write-first-review-link');
		var merchandisingTextWidget = document.getElementById('merchandisingTextWidget');
		var advisoryWidget = document.getElementById('hotel-infosite-advisory');
		var themesAndPromotionsWidget = document.getElementById('hotel-infosite-themesAndPromotions');
		var crossLinksWidget = document.getElementById('hotel-infosite-crosslinks');
		var picturesAndToursWidget = document.getElementById('hotel-infosite-picturesAndTours');
		var detailsWidget = document.getElementById('hotel-infosite-details');
		var roomsAndRatesWidgetWizard = document.getElementById('availability-wizard');
		var roomsAndRatesWidgetResult = document.getElementById('hotel-infosite-roomsAndRatesResult');
		var roomsAndRatesWidgetResultGrid = document.getElementById('hotel-infosite-roomsAndRatesResultGrid');
		var continueToBookingWidget = document.getElementById('hotel-infosite-continueToBooking');
		var continueToBookingWidgetCallCentre = document.getElementById('hotel-infosite-continueToBookingCallCentre');
		
			switch (group)
			{
				case 1:
				this.select(null, {id: 'hotelInformation'});
				this.deselect(null, {id: 'picturesAndToursTab'});
				this.deselect(null, {id: 'hotelDetails'});
				this.deselect(null, {id: 'roomsAndRatesTab'});

				if (galleryMediaPreviewWidget) {
					galleryMediaPreviewWidget.style.display = 'block';
					if (typeof galleryMediaPreview != 'undefined')
						galleryMediaPreview.startAnimation();
				}				
				if (overviewWidget)
					overviewWidget.style.display = 'block';
				if (merchandisingTextWidget)
					merchandisingTextWidget.style.display = 'block';
				if (reviewSummaryWidget)
					reviewSummaryWidget.style.display = 'block';
				if (recentReviewsWidget)
					recentReviewsWidget.style.display = 'block';
				if (recentReviewsWriteNewReviewLink)
					recentReviewsWriteNewReviewLink.style.display = 'block';
				if (writeFirstReviewLink)
					writeFirstReviewLink.style.display = 'block';
				if (advisoryWidget)
					advisoryWidget.style.display = 'block';
				if (themesAndPromotionsWidget)
					themesAndPromotionsWidget.style.display = 'block';
				if (crossLinksWidget)
					crossLinksWidget.style.display = 'block';
				if (picturesAndToursWidget) {
					this.pauseAnimations();
					picturesAndToursWidget.style.display = 'none';
				}
				if (detailsWidget)
					detailsWidget.style.display = 'none';
				if (roomsAndRatesWidgetWizard)
					roomsAndRatesWidgetWizard.style.display = this.availDisplay;
				if (roomsAndRatesWidgetResult)
					roomsAndRatesWidgetResult.style.display = 'none';
				if (roomsAndRatesWidgetResultGrid)
					roomsAndRatesWidgetResultGrid.style.display = 'block';
				if (continueToBookingWidget)
					continueToBookingWidget.style.display = 'block';
				if (continueToBookingWidgetCallCentre)
					continueToBookingWidgetCallCentre.style.display = 'block';
				updateBreadCrumbs('#nav=overview');
				break;

				case 2:
				this.deselect(null, {id: 'hotelInformation'});
				this.select(null, {id: 'picturesAndToursTab'});
				this.deselect(null, {id: 'hotelDetails'});
				this.deselect(null, {id: 'roomsAndRatesTab'});

				if (galleryMediaPreviewWidget) {
					galleryMediaPreviewWidget.style.display = 'none';
					if (typeof galleryMediaPreview != 'undefined')
						galleryMediaPreview.stopAnimation();
				}
				if (overviewWidget)
					overviewWidget.style.display = 'none';
				if (merchandisingTextWidget)
					merchandisingTextWidget.style.display = 'none';
				if (reviewSummaryWidget)
					reviewSummaryWidget.style.display = 'none';
				if (recentReviewsWidget)
					recentReviewsWidget.style.display = 'none';
				if (recentReviewsWriteNewReviewLink)
					recentReviewsWriteNewReviewLink.style.display = 'none';
				if (writeFirstReviewLink)
					writeFirstReviewLink.style.display = 'none';
				if (advisoryWidget)
					advisoryWidget.style.display = 'none';
				if (themesAndPromotionsWidget)
					themesAndPromotionsWidget.style.display = 'none';
				if (crossLinksWidget)
					crossLinksWidget.style.display = 'none';
				if (picturesAndToursWidget)
					picturesAndToursWidget.style.display = 'block';
				if (detailsWidget)
					detailsWidget.style.display = 'none';
				if (roomsAndRatesWidgetWizard)
					roomsAndRatesWidgetWizard.style.display = 'none';
				if (roomsAndRatesWidgetResult)
					roomsAndRatesWidgetResult.style.display = 'none';
				if (roomsAndRatesWidgetResultGrid)
					roomsAndRatesWidgetResultGrid.style.display = 'none';
				if (continueToBookingWidget)
					continueToBookingWidget.style.display = 'block';
				if (continueToBookingWidgetCallCentre)
					continueToBookingWidgetCallCentre.style.display = 'block';
				updateBreadCrumbs('#nav=picturesAndTours');
				break;

				case 3:
				this.deselect(null, {id: 'hotelInformation'});
				this.deselect(null, {id: 'picturesAndToursTab'});
				this.select(null, {id: 'hotelDetails'});
				this.deselect(null, {id: 'roomsAndRatesTab'});

				if (galleryMediaPreviewWidget) {
					galleryMediaPreviewWidget.style.display = 'none';
					if (typeof galleryMediaPreview != 'undefined')
						galleryMediaPreview.stopAnimation();
				}
				if (overviewWidget)
					overviewWidget.style.display = 'none';
				if (merchandisingTextWidget)
					merchandisingTextWidget.style.display = 'none';
				if (reviewSummaryWidget)
					reviewSummaryWidget.style.display = 'none';
				if (recentReviewsWidget)
					recentReviewsWidget.style.display = 'none';
				if (recentReviewsWriteNewReviewLink)
					recentReviewsWriteNewReviewLink.style.display = 'none';
				if (writeFirstReviewLink)
					writeFirstReviewLink.style.display = 'none';
				if (advisoryWidget)
					advisoryWidget.style.display = 'none';
				if (themesAndPromotionsWidget)
					themesAndPromotionsWidget.style.display = 'none';
				if (crossLinksWidget)
					crossLinksWidget.style.display = 'none';
				if (picturesAndToursWidget) {
					this.pauseAnimations();
					picturesAndToursWidget.style.display = 'none';
				}
				if (detailsWidget)
					detailsWidget.style.display = 'block';
				if (roomsAndRatesWidgetWizard)
					roomsAndRatesWidgetWizard.style.display = this.availDisplay;
				if (roomsAndRatesWidgetResult)
					roomsAndRatesWidgetResult.style.display = 'none';
				if (roomsAndRatesWidgetResultGrid)
					roomsAndRatesWidgetResultGrid.style.display = 'block';
				if (continueToBookingWidget)
					continueToBookingWidget.style.display = 'block';
				if (continueToBookingWidgetCallCentre)
					continueToBookingWidgetCallCentre.style.display = 'block';
				updateBreadCrumbs('#nav=details');
				break;
				
				case 4:
				this.deselect(null, {id: 'hotelInformation'});
				this.deselect(null, {id: 'picturesAndToursTab'});
				this.deselect(null, {id: 'hotelDetails'});
				this.select(null, {id: 'roomsAndRatesTab'});

				if (galleryMediaPreviewWidget) {
					galleryMediaPreviewWidget.style.display = 'none';
					if (typeof galleryMediaPreview != 'undefined')
						galleryMediaPreview.stopAnimation();
				}
				if (overviewWidget)
					overviewWidget.style.display = 'none';
				if (merchandisingTextWidget)
					merchandisingTextWidget.style.display = 'none';
				if (reviewSummaryWidget)
					reviewSummaryWidget.style.display = 'none';
				if (recentReviewsWidget)
					recentReviewsWidget.style.display = 'none';
				if (recentReviewsWriteNewReviewLink)
					recentReviewsWriteNewReviewLink.style.display = 'none';
				if (writeFirstReviewLink)
					writeFirstReviewLink.style.display = 'none';
				if (advisoryWidget)
					advisoryWidget.style.display = 'none';
				if (themesAndPromotionsWidget)
					themesAndPromotionsWidget.style.display = 'none';
				if (crossLinksWidget)
					crossLinksWidget.style.display = 'none';
				if (picturesAndToursWidget) {
					this.pauseAnimations();
					picturesAndToursWidget.style.display = 'none';
				}	
				if (detailsWidget)
					detailsWidget.style.display = 'none';
				if (roomsAndRatesWidgetWizard)
					roomsAndRatesWidgetWizard.style.display = 'block';
				if (roomsAndRatesWidgetResult)
					roomsAndRatesWidgetResult.style.display = 'block';
				if (roomsAndRatesWidgetResultGrid)
					roomsAndRatesWidgetResultGrid.style.display = 'none';
				updateBreadCrumbs('#nav=roomsAndRates');
				if (continueToBookingWidget)
					continueToBookingWidget.style.display = 'none';
				if (continueToBookingWidgetCallCentre)
					continueToBookingWidgetCallCentre.style.display = 'none';
				break;

				case 5:
				this.select(null, {id: 'hotelInformation'});
				this.deselect(null, {id: 'picturesAndToursTab'});
				this.deselect(null, {id: 'hotelDetails'});
				this.deselect(null, {id: 'roomsAndRatesTab'});
				if (galleryMediaPreviewWidget) {
					galleryMediaPreviewWidget.style.display = 'block';
					if (typeof galleryMediaPreview != 'undefined')
						galleryMediaPreview.startAnimation();
				}
				if (overviewWidget)
					overviewWidget.style.display = 'block';
				if (merchandisingTextWidget)
					merchandisingTextWidget.style.display = 'block';
				if (reviewSummaryWidget)
					reviewSummaryWidget.style.display = 'block';
				if (recentReviewsWidget)
					recentReviewsWidget.style.display = 'block';
				if (recentReviewsWriteNewReviewLink)
					recentReviewsWriteNewReviewLink.style.display = 'block';
				if (writeFirstReviewLink)
					writeFirstReviewLink.style.display = 'block';
				if (advisoryWidget)
					advisoryWidget.style.display = 'block';
				if (themesAndPromotionsWidget)
					themesAndPromotionsWidget.style.display = 'block';
				if (crossLinksWidget)
					crossLinksWidget.style.display = 'block';
				if (picturesAndToursWidget) {
					this.pauseAnimations();
					picturesAndToursWidget.style.display = 'none';
				}
				if (detailsWidget)
					detailsWidget.style.display = 'none';
				if (roomsAndRatesWidgetWizard)
					roomsAndRatesWidgetWizard.style.display = this.availDisplay;
				if (roomsAndRatesWidgetResult)
					roomsAndRatesWidgetResult.style.display = 'none';
				if (roomsAndRatesWidgetResultGrid)
					roomsAndRatesWidgetResultGrid.style.display = 'block';
				if (continueToBookingWidget)
					continueToBookingWidget.style.display = 'block';
				if (continueToBookingWidgetCallCentre)
					continueToBookingWidgetCallCentre.style.display = 'block';
				break;

				default:
				this.deselect(null, {id: 'hotelInformation'});
				this.deselect(null, {id: 'picturesAndToursTab'});
				this.deselect(null, {id: 'hotelDetails'});
				this.deselect(null, {id: 'roomsAndRatesTab'});
				
				if (galleryMediaPreviewWidget) {
					galleryMediaPreviewWidget.style.display = 'block';
					if (typeof galleryMediaPreview != 'undefined')
						galleryMediaPreview.startAnimation();
				}
				if (overviewWidget)
					overviewWidget.style.display = 'block';
				if (merchandisingTextWidget)
					merchandisingTextWidget.style.display = 'block';
				if (reviewSummaryWidget)
					reviewSummaryWidget.style.display = 'block';
				if (recentReviewsWidget)
					recentReviewsWidget.style.display = 'block';
				if (recentReviewsWriteNewReviewLink)
					recentReviewsWriteNewReviewLink.style.display = 'block';
				if (writeFirstReviewLink)
					writeFirstReviewLink.style.display = 'block';
				if (advisoryWidget)
					advisoryWidget.style.display = 'block';
				if (themesAndPromotionsWidget)
					themesAndPromotionsWidget.style.display = 'block';
				if (crossLinksWidget)
					crossLinksWidget.style.display = 'block';
				if (picturesAndToursWidget) {
					this.pauseAnimations();
					picturesAndToursWidget.style.display = 'none';
				}
				if (detailsWidget)
					detailsWidget.style.display = 'none';
				if (roomsAndRatesWidgetWizard)
					roomsAndRatesWidgetWizard.style.display = 'block';
				if (roomsAndRatesWidgetResult)
					roomsAndRatesWidgetResult.style.display = 'none';
				if (roomsAndRatesWidgetResultGrid)
					roomsAndRatesWidgetResultGrid.style.display = 'block';
				if (continueToBookingWidget)
					continueToBookingWidget.style.display = 'block';
				if (continueToBookingWidgetCallCentre)
					continueToBookingWidgetCallCentre.style.display = 'block';
				break;
			}
		return false;
	}
	
	this.initInfositeNavigation = function ()
	{
		var hashLink = window.location.hash;
		var hashTagParam = YAHOO.util.History.getQueryStringParameter('hashTag');
		
		if ((hashLink == '') && (hashTagParam != ''))
		{
			hashLink = '#' + hashTagParam;
		}

		if (hashLink == '#nav=overview' || hashLink == '#overview' )
		{
			this.changeDisplayGroup(null, {group: 1, id: ""});
		}
		else if (hashLink == '#nav=picturesAndTours' || hashLink == '#picturesAndTours' )
		{
			this.changeDisplayGroup(null, {group: 2, id: ""});
		}
		else if (hashLink == '#nav=details' || hashLink == '#details' )
		{
			this.changeDisplayGroup(null, {group: 3, id: ""});
		}
		else if (hashLink == '#nav=roomsAndRates' || hashLink == '#roomsAndRates' || (hashLink.indexOf('#nav=roomsAndRates') != -1))
		{
			this.changeDisplayGroup(null, {group: 4, id: ""});
		}
		else if (this.isInformation)
		{
				this.changeDisplayGroup(null, {group: 5, id: ""});
		}
		else
		{
				this.changeDisplayGroup(null, {group: 0, id: ""});
		}
	}
	
};

