
//this file needs jquery to work
//please minify this file when making changes to winchester.min.js for uploading to live
//use yui compressor here http://developer.yahoo.com/yui/compressor/ to do it
//example: 
//H:\>java -jar L:\Shared_JS\yuicompressor-2.3.5.jar
//--type js -o W:\visitwinchester2009\website\javascript\winchester.min.js W:\visitwinchester2009\website\javascript\winchester.js

(function() {

	/**
	* @author NPrice 
	update - LT 26/5/09 - stripped out unused image stuff & hover/colour classes. Altered to allowed traversing to third level.
				04/6/09 - added empty 'ul li' elements to navigation for full rollover style issues
	*/
	var NewMind = window.NewMind || {};
	NewMind.Site = window.NewMind.Site || {};

	/**
	* RolloverNav
	* @Requires JQuery.1.2.2
	*/
	NewMind.Site.RolloverNav = function(selector) {

		//add hover mouseover and mouseout events for the selected element
		//hover is used because it caters for bubbling problems 
		//that mouseover and mouseout dont do separately
		$(selector).hover(
			function() {

				var liObj = $(this);

				//add hover class to the li
				liObj.addClass('hover');

			},
			function() {
				//for mouseout just remove class from the li and its parent
				$(this).removeClass('hover');
			}
		)
	};

	NewMind.Site.InsertSubNav = function() {
	// search through each li in the main nav and add an empty 'ul li' if required
		// temp fix here, I've added an additonal empty 'ul li' to capture the third empty level
		$('#mainNav li').not(
			$('#mainNav li > ul.subCategories').parent()
			).append('<ul class="subCategories subEmpty"><li class="hidden"><ul class="subCategories subEmpty"><li class="hidden"></li></ul></li></ul>');
	};

	$(document).ready(
		function() {

			//optional extra bit for IE - fixes background image load flickering when hovering anchors
			//this issue will not happen if a user goes to tools > internet options > settings... > selects 'automatically'
			if ($.browser.msie) {
				try {
					document.execCommand('BackgroundImageCache', false, true);
				} catch (e) {
					// just in case this fails dont do anything
				}
			}

			//selector adds rollover to main nav direct child li of a direct child ul
			NewMind.Site.InsertSubNav();
			NewMind.Site.RolloverNav('#mainNav ul li');

		}
	);



})();

(function() {


	//NameSpace
	window.NewMind = window.NewMind || {};
	var NewMind = window.NewMind;
	NewMind.WebPlatform = NewMind.WebPlatform || {};


	//Winchester Specific
	NewMind.WebPlatform.Winchester = function() {

		/**
		* Adding a class to use CSS to hide the itinerary basket when it is empty, this is so the ajax posts adding
		* items to the itinerary will then be able to display the basket without reloading the page.
		* This is a workaround for Config("ExPlanner_HideBasketWhenEmpty")
		**/
		var hideItinWhenEmpty = function() {
			if ($('#excursionHelp .ex_baskettable').length === 0) {
				$('#excursionHelp').addClass('hidden');
			}
		};


		/**
		* replace text of an element by passing in the jquery selector expression and the text
		* Using this for a couple of the search box headers instead of image replacement styling
		**/
		var replaceText = function(strSelExp, strText) {
			try {
				$(strSelExp).text(strText);
			} catch (e) {

			}
		};

		/**
		* Toggle the display of product facilities in their groups
		*
		**/
		var prodFacilities = function(sContainer) {
			$(sContainer + " h3").wrapInner('<a href="#" title="Show / Hide"></a>').toggle(function(event) {
				$(this).parent().find("ul." + this.className + ", ul." + this.className + " + h4").show();
			}, function(event) {
				$(this).parent().find("ul." + this.className + ", ul." + this.className + " + h4").hide();
			}).parent().find("ul, h4").hide();
		};

		//public
		return {
			init: function() {

				//itinerary hiding (not using this for the time being)
				//hideItinWhenEmpty();

				replaceText('#ir_book_online', 'Where to stay');
				replaceText('#ir_search_wheretostay', 'Where to stay');
				replaceText('#ir_yourexcursionplanner', 'Plan each day');
				replaceText('#ir_search_attractions', 'Find attractions');
				replaceText("#ir_search_whatson", "What's on");
				replaceText("#ir_book_summary", "Search summary");
				replaceText("#ir_search_eatingdrinking", "Search eating & drinking");
				replaceText("#ir_search_shopping", "Search shopping");
				replaceText("#ir_search_thingstodo", "Search things to do");

				$('#colCenter div#downloads').prepend('<h2 class="downloads_ttl">Related downloads</h2>');

				//product facilities dropdown
				prodFacilities("#facilitiesList");

				// customise the site map text as its HC by the platform
				$('#footerList li:last a').text('Site map');

				// customise the product detail page titles
				$('h2#contactinfo').text('Contact information');
				//$('#roomInfo h2').text('Accommodation information'); //we can't do this; #roomInfo is shared by different types
				$('#openingTimes h2').text('Opening times');
				$('#roadDirections h2').text('Road directions');
				$('#publicDirections h2').text('Public transport directions');
				$('#relatedSpecialoffers h2').text('Special offer');
				$('#roomInfo dl dt').text('Number of rooms or units:');
				$('#detailedproductInfo .locationMapLink a').text('Location map');

				// customise the search options
				$('#refineBy .accommodationSearchAdvanced a#SearchAZ').text('A-Z listing');
				$('#refineByDefList dt.refine-unittype label').text('Unit or room type');
				$('#refineByDefList #refine-GreenFilter label').text('Green accreditation');

				$('#refineByDefList dd div.row span.field label#tfaLabel').text('Accessibility information');

				$('#hpaccosearch span.row span.labelwide').text('Date of stay');
				$('#hpaccosearch div.row span.labelwide').text('Accommodation type');
				
				$('#hpaccosearch span.AddAnotherUnit a').text('Add another room');
				$('#refineByDefList dl dt').text('Number of rooms or units:');

				// customise itin basket & detail
				$('#excursionHelp table.ex_baskettable thead tr th').text('Current additions:');
				$('#ex_exitems h3').text('Itinerary items');
				$('#ex_distances h3').text('Itinerary distances');

				// booking
				$('pnAvailClassKey h2').text('Availability key');
			}

		};
	} ();

	$(document).ready(NewMind.WebPlatform.Winchester.init);
})();