﻿/*jQuery */
/*extern $, jQuery */
/* VistLondon */
/*extern currentMonth, currentYear, currentDay,  dcsMultiTrack, vlCopy */
/* IE */
/*extern ActiveXObject */
/* WebTrends */
/*extern dcsMultiTrack */


/*  Sections in this file:
- Global variables
- Generic Functions
- Flash
- Expanders
- External Links
- Explorer
- Tabs
- Multi Selector
- Registration
- Top Nav
- Search
- Loader
*/

/* ################ Global variables ################  */
var whichVid, playlistURL, tl = false, videoColor, navTimer;


/* ################  Generic Functions  ################ */
function leapYear (inYear) { if ((inYear % 4 === 0) && ((inYear % 100 !== 0) || (inYear % 400 === 0))) {return true;}}
/* ################  End Generic Functions  ################ */

/* Copyright (c) 2006 Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 * Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
 * Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
 *
 * $LastChangedDate: 2007-12-20 09:02:08 -0600 (Thu, 20 Dec 2007) $
 * $Rev: 4265 $
 *
 * Version: 3.0
 * 
 * Requires: $ 1.2.2+
 */

(function($) {
$.event.special.mousewheel = {
	setup: function() {
		var handler = $.event.special.mousewheel.handler;
		// Fix pageX, pageY, clientX and clientY for mozilla
		if ( $.browser.mozilla ) {
			$(this).bind('mousemove.mousewheel', function(event) {
				$.data(this, 'mwcursorposdata', {
					pageX: event.pageX,
					pageY: event.pageY,
					clientX: event.clientX,
					clientY: event.clientY
				});
			});
		}
		if ( this.addEventListener ) {
			this.addEventListener( ($.browser.mozilla ? 'DOMMouseScroll' : 'mousewheel'), handler, false);
		} else {
			this.onmousewheel = handler;
		}
	},
	teardown: function() {
		var handler = $.event.special.mousewheel.handler;
		$(this).unbind('mousemove.mousewheel');
		if ( this.removeEventListener ) {
			this.removeEventListener( ($.browser.mozilla ? 'DOMMouseScroll' : 'mousewheel'), handler, false);
		} else {
			this.onmousewheel = function(){};
		}
		$.removeData(this, 'mwcursorposdata');
	},
	
	handler: function(event) {
		var args = Array.prototype.slice.call( arguments, 1 );
		
		event = $.event.fix(event || window.event);
		// Get correct pageX, pageY, clientX and clientY for mozilla
		$.extend( event, $.data(this, 'mwcursorposdata') || {} );
		var delta = 0, returnValue = true;
		
		if ( event.wheelDelta ) {delta = event.wheelDelta/120;}
		if ( event.detail     ) {delta = -event.detail/3;}
		if ( $.browser.opera  ) {delta = -event.wheelDelta;}
		
		event.data  = event.data || {};
		event.type  = "mousewheel";
		
		// Add delta to the front of the arguments
		args.unshift(delta);
		// Add event to the front of the arguments
		args.unshift(event);

		return $.event.handle.apply(this, args);
	}
};

$.fn.extend({
	mousewheel: function(fn) {
		return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel");
	},
	
	unmousewheel: function(fn) {
		return this.unbind("mousewheel", fn);
	}
});

})(jQuery);




/* ################  Flashemebed ################ */
/** 
 * flashembed 0.31. Adobe Flash embedding script
 * 
 * http://flowplayer.org/tools/flash-embed.html
 *
 * Copyright (c) 2008 Tero Piirainen (tipiirai@gmail.com)
 *
 * Released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 * 
 * >> Basically you can do anything you want but leave this header as is <<
 *
 * version 0.01 - 03/11/2008 
 * version 0.31 - Tue Jul 22 2008 06:30:34 GMT+0200 (GMT+02:00)
 *
 * modified - Thu Oct 22 2008 15:23:00 GMT+0100 (GMT+00:00)
 * modified by Steve Pugh (spugh@visitlondon.com)
 * output Microsoft or standards compliant <object> element based on browser
 * output flashvars as URL encoded strings rather than quoted strings
*/
function flashembed(root, userParams, flashvars) {	
	function getHTML() {
		var html = "";
		if (typeof flashvars == 'function') { flashvars = flashvars(); }
		if($.browser.mozilla || $.browser.webkit) {
			html = '<embed ';
			html += 'src="'+ params.src +'" ';
			params.src = null;
			for (var k in params) {
				if (params[k] !== null) {
					html += k +'="'+ params[k] +'" ';
				}
			}
			if (flashvars) {
				html += 'flashvars="' + concatVars(flashvars) + '" ';
			}
			html += '\n\t</embed>';
		} else {
			html = '<object ';
			if ($.browser.msie) {
				html += 'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" ';			
				html += 'classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
				if (!params.id) {
					params.id = "_" + ("" + Math.random()).substring(5);
				}
			} else {
				html += ' type="application/x-shockwave-flash" ';
				html += ' data="'+ params.src +'" ';
			}
			html += 'width="' + params.width + '" height="' + params.height + '"'; 
			if (params.id) {html += ' id="' + params.id + '"';} 
			html += '>';  
			if ($.browser.msie) {
				html += '\n\t<param name="movie" value="'+ params.src +'" />';
			}
			params.id = params.src = params.width = params.height = null;
			for (var j in params) {
				if (params[j] !== null) {
					html += '\n\t<param name="'+ j +'" value="'+ params[j] +'" />';
				}
			}
			if (flashvars) {
				html += '\n\t<param name="flashvars" value="' + concatVars(flashvars) + '" />';
			}
			html += "\n\t</object>";
		}
			if (debug) { 
				alert(html);
			}
			
			
		return html;
	}
	function init(name) {
		var timer = setInterval(function() {
			var doc = document;
			var el = doc.getElementById(name); 
			if (el) {
				flashembed(el, userParams, flashvars);
				clearInterval(timer); 
			} else if (doc && doc.getElementsByTagName && doc.getElementById && doc.body) {
				clearInterval(timer);
			}
		}, 13);
		return true;
	}
	// override extend params function 
	function extend(to, from) {
		if (from) {
			for (key in from) {
				if (from.hasOwnProperty(key)) {
					to[key] = from[key];
				}
			}
		}
	}		
	// setup params
	var params = {
		// very common params
		src: '#',
		width: '100%',
		height: '100%',		
		// flashembed specific options
		version:null,
		onFail:null,
		expressInstall:null,  
		debug: false,
		// flashembed defaults
		bgcolor: '#ffffff',
		allowfullscreen: true,
		allowscriptaccess: 'always',
		quality: 'high',
		type: 'application/x-shockwave-flash',
		pluginspage: 'http://www.adobe.com/go/getflashplayer'
	};
	if (typeof userParams == 'string') { userParams = {src: userParams}; }
	extend(params, userParams);
	var version = flashembed.getVersion(); 
	var required = params.version; 
	var express = params.expressInstall;		 
	var debug = params.debug;
	if (typeof root == 'string') {  
		var el = document.getElementById(root);
		if (el) {
			root = el;	
		} else {
			return init(root);		
		} 
	}
	if (!root) { return; }
	// is supported 
	if (flashembed.isSupported(required)) {
		params.onFail = params.version = params.expressInstall = params.debug = null; 
		root.innerHTML = getHTML();	
		// return our API			
		return root.firstChild;
	} 
	function concatVars(vars) {		
		var out = "";
		for (var key in vars) { 
			if (vars[key]) {
				out += [key] + '=' + asString(vars[key]) + '&';
			}
		}			
		return out.substring(0, out.length -1);				
	}  
	// JSON.asString() function
	function asString(obj) {
		switch (typeOf(obj)){
			case 'array':
				return '['+ map(obj, function(el) {
					return asString(el);
				}).join(',') +']'; 
			case 'function':
				return '"function()"';
			case 'object':
				var str = [];
				for (var prop in obj) {
					if (obj.hasOwnProperty(prop)) {
						str.push('"'+prop+'":'+ asString(obj[prop]));
					}
				}
				return '{'+str.join(',')+'}';
			default: 
				return obj;
		}
		//  remove spaces
		return escape(String(obj).replace(/\s/g, " "));
	}
	// private functions
	function typeOf(obj) {
		if (obj === null || obj === undefined) { return false; }
		var type = typeof obj;
		return (type == 'object' && obj.push) ? 'array' : type;
	}
	// version 9 bugfix: (http://blog.deconcept.com/2006/07/28/swfobject-143-released/)
	if (window.attachEvent) {
		window.attachEvent("onbeforeunload", function() {
			__flash_unloadHandler = function() {};
			__flash_savedUnloadHandler = function() {};
		});
	}
	function map(arr, func) {
		var newArr = []; 
		for (var i in arr) {
			if (arr.hasOwnProperty(i)) {
				newArr[i] = func(arr[i]);
			}
		}
		return newArr;
	}
	return root;
}
// setup jquery support
if (typeof jQuery == 'function') {
	(function($) { 
		$.fn.extend({
			flashembed: function(params, flashvars) {  
				return this.each(function() { 
					flashembed(this, params, flashvars);
				});
			}		
		}); 
	})(jQuery);
}
flashembed = flashembed || {};
// arr[major, minor, fix]
flashembed.getVersion = function() {
	var version = [0, 0];
	if (navigator.plugins && typeof navigator.plugins["Shockwave Flash"] == "object") {
		var _d = navigator.plugins["Shockwave Flash"].description;
		if (typeof _d != "undefined") {
			_d = _d.replace(/^.*\s+(\S+\s+\S+$)/, "$1");
			var _m = parseInt(_d.replace(/^(.*)\..*$/, "$1"), 10);
			var _r = /r/.test(_d) ? parseInt(_d.replace(/^.*r(.*)$/, "$1"), 10) : 0;
			version = [_m, _r];
		}
		
	} else if (window.ActiveXObject) {
		try { // avoid fp 6 crashes
			var _a = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		} catch(e) {
			try { 
				_a = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
				version = [6, 0];
				_a.AllowScriptAccess = "always"; // throws if fp < 6.47 
				
			} catch(ee) {
				if (version[0] == 6) { return; }
			}
			try {
				_a = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			} catch(eee) {
			}
		}
		if (typeof _a == "object") {
			_d = _a.GetVariable("$version"); // bugs in fp 6.21 / 6.23
			if (typeof _d != "undefined") {
				_d = _d.replace(/^\S+\s+(.*)$/, "$1").split(",");
				version = [parseInt(_d[0], 10), parseInt(_d[2], 10)];
			}
		}
	} 
	return version;
};
flashembed.isSupported = function(version) {
	var now = flashembed.getVersion();
	var ret = (now[0] > version[0]) || (now[0] == version[0] && now[1] >= version[1]);			
	return ret;
};
/* ################ End Flashemebed ################ */

/* ################ Flash ################ */
function drawMovie(tagID, myMovie, w, h, isTV) {
	$("#" + tagID).flashembed({
		src: 		myMovie,
		width: 		w, 
		height: 	h,
		play: 		"true",
		wmode: 		"transparent",
		version:	[8,0]
	});
}

if (!videoColor || videoColor === '') {
	switch (location.pathname.split("/")[1]) {
		case 'accommodation': videoColor = 'purplestay'; break; 
		case 'attractions'	: videoColor = 'blueplaces'; break; 
		case 'travel'		: videoColor = 'bluetravel'; break; 
		case 'events'		: videoColor = 'yellow'; break; 
		case 'areas'		: videoColor = 'orange'; break; 
		case 'maps'			: videoColor = 'purplemap'; break; 
		case 'people'		: videoColor = 'green'; break; 
		case 'offers'		: videoColor = 'pink'; break; 
		default				: videoColor = 'grey'; break; 
	}
	if (location.hostname.indexOf('traveltrade') != -1) {videoColor = 'bluetravel';}
	if (location.hostname.indexOf('awards') != -1) {videoColor = 'purplemap';}
}

function drawTV() {
var w, h, xml = whichVid + ".xml";
if(playlistURL && playlistURL !== "") {
if($("#playlist").size !== 0) {
		$("#playlist").flashembed({
			src: 		"http://static.visitlondon.com/assets/video/vl-video-player-large.swf?playerSize=PL&xmltouse="+playlistURL+".xml&PageColour=" + videoColor,
			width: 		'540', 
			height: 	'353',
			play: 		"true",
			wmode: 		"transparent",
			allowFullScreen: "true",
			version:	[8,0]
		});
		$("#playlist").height(360);
}
}

if(whichVid && whichVid !== "") {
	if($("#video").size !== 0) {
		if ($.browser.msie || $.browser.safari) { w = '540'; h = '352'; } else { w = '240'; h = '184'; }
		$("#video").flashembed({
			src: 		"http://static.visitlondon.com/assets/video/vl-video-player.swf?xmltouse="+xml+"&PageColour=" + videoColor,
			width: 		w, 
			height: 	h,
			play: 		"true",
			wmode: 		"transparent",
			allowFullScreen: "true",
			scale: 		"noscale",
			salign: 	"rt",
			version:	[8,0]
		});
		if (tl === true ) {
			$("#video").append('<a id="transcriptLink" href="http://static.visitlondon.com/assets/video/transcripts/'+whichVid+'.html"><img src="http://static.visitlondon.com/images/icons/transcript.gif" alt="" />'+vlCopy.tltext+'</a>');
			$("#transcriptLink").css('cursor','pointer').css('display','block').css('margin-top','188px').css('margin-bottom','10px').click(
			function() {
				window.open('http://static.visitlondon.com/assets/video/transcripts/'+whichVid+'.html', 'trans', 'width=600, height=550, location=no, scrollbars=yes');
				return false;
				}
			);
			$("#video").height(200);
		}
		else {	
			$("#video").height(188);
		}
		if ($.browser.safari) {
			$("#video object, #video embed").css('clip','rect(0,540px,184px,300px)');
		}
	}
	if($("#videolarge").size !== 0) {
		$("#videolarge").flashembed({
			src: 		"http://static.visitlondon.com/assets/video/vl-video-player-large.swf?playerSize=SL&xmltouse="+xml+"&PageColour=" + videoColor,
			width: 		'540', 
			height: 	'353',
			play: 		"true",
			wmode: 		"transparent",
			allowFullScreen: "true",
			version:	[8,0]
		});
		if (tl === true) {
			$("#videolarge").append('<a id="transcriptLink" href="http://static.visitlondon.com/assets/video/transcripts/'+whichVid+'.html"><img src="http://static.visitlondon.com/images/icons/transcript.gif" alt="" />'+vlCopy.tltext+'</a>');
			$("#transcriptLink").css('cursor','pointer').css('display','block').css('margin-top','360px').css('margin-bottom','10px').click(
			function() {
				window.open('http://static.visitlondon.com/assets/video/transcripts/'+whichVid+'.html', 'trans', 'width=600, height=550, location=no, scrollbars=yes');
				return false;
				}
			);
			$("#videolarge").height(375);
		} else {	
			$("#videolarge").height(360);
		}
	}
}
}

function goBig() {
	if (!$.browser.msie) {
		$("#video object, #video embed").width(540).height(352);
		if ($.browser.safari) {
			$("#video object, #video embed").css('clip','auto'); 
		}
	}
}

function goSmall() {
	if (!$.browser.msie) {
		$("#video object, #video embed").width(240).height(184);
		if ($.browser.safari) {
			$("#video object, #video embed").css('clip','rect(0,540px,184px,300px)');
		}
	}
}
 
function videoMultiTrackWrapper(trackPath,trackTitle,trackEvent) {
	switch (trackEvent) {
		case 'WT.z_ltvView'     : dcsMultiTrack("WT.ti","","WT.cg_n","","WT.cg_s","","WT.mc_id","","WT.si_n","","WT.si_p","","WT.z_vlSupplier","","DCS.dcsuri",trackPath,"WT.z_ltvName","Video: "+trackTitle,"WT.z_ltvView","1","WT.z_ltvPlay","","WT.z_ltvFinished",""); break;	
		case 'WT.z_ltvPlay'     : dcsMultiTrack("WT.ti","","WT.cg_n","","WT.cg_s","","WT.mc_id","","WT.si_n","","WT.si_p","","WT.z_vlSupplier","","DCS.dcsuri",trackPath,"WT.z_ltvName","Video: "+trackTitle,"WT.z_ltvView","","WT.z_ltvPlay","1","WT.z_ltvFinished",""); break;	
		case 'WT.z_ltvFinished'	: dcsMultiTrack("WT.ti","","WT.cg_n","","WT.cg_s","","WT.mc_id","","WT.si_n","","WT.si_p","","WT.z_vlSupplier","","DCS.dcsuri",trackPath,"WT.z_ltvName","Video: "+trackTitle,"WT.z_ltvView","","WT.z_ltvPlay","","WT.z_ltvFinished","1"); break;	
	}
}

function gameMultiTrackWrapper(trackPath,trackTitle,trackEvent) {
	switch (trackEvent) {
		case 'WT.z_ltvView'     : dcsMultiTrack("WT.ti","","WT.cg_n","","WT.cg_s","","WT.mc_id","","WT.si_n","","WT.si_p","","WT.z_vlSupplier","","DCS.dcsuri",trackPath,"WT.z_ltvName","Video: "+trackTitle,"WT.z_ltvView","1","WT.z_ltvPlay","","WT.z_ltvSend",""); break;	
		case 'WT.z_ltvPlay'     : dcsMultiTrack("WT.ti","","WT.cg_n","","WT.cg_s","","WT.mc_id","","WT.si_n","","WT.si_p","","WT.z_vlSupplier","","DCS.dcsuri",trackPath,"WT.z_ltvName","Video: "+trackTitle,"WT.z_ltvView","","WT.z_ltvPlay","1","WT.z_ltvSend",""); break;	
		case 'WT.z_ltvSend'	: dcsMultiTrack("WT.ti","","WT.cg_n","","WT.cg_s","","WT.mc_id","","WT.si_n","","WT.si_p","","WT.z_vlSupplier","","DCS.dcsuri",trackPath,"WT.z_ltvName","Video: "+trackTitle,"WT.z_ltvView","","WT.z_ltvPlay","","WT.z_ltvSend","1"); break;	
	}
}
/* ################ End Flash ################ */


/* ################  Expanders  ################ */
function setupHidden() {
	$("#content .hidden").hide();
	$("#content .foot-extend a").append('<i></i>');
	$("#content .foot-extend a").click(function() {
		$(this).toggleClass('pm').blur();
		$("div.hidden",$(this).parents('div.secondary')).slideToggle(1000);
	});
}

function setupUserReviews() {
	$("#prod-user .ta-full").hide();
	$("#prod-user .ta-summary").show();
	$("#prod-user .expand-this").empty().append(vlCopy.readRev).addClass('plus').css('display','inline').click(function(){
		if ($(this).text() == vlCopy.readRev) {
			$(this).text(vlCopy.hideRev).removeClass('plus').addClass('minus').siblings(".ta-full").show().siblings(".ta-summary").hide();
		} else {
			$(this).text(vlCopy.readRev).removeClass('minus').addClass('plus').siblings(".ta-full").hide().siblings(".ta-summary").show();
		}});
	$("#expand-all").empty().append(vlCopy.exAllRev).addClass('plus').click(function(){
		if ($(this).text() == vlCopy.exAllRev) {
			$(this).text(vlCopy.hideAllRev).removeClass('plus').addClass('minus');
			$("#prod-user .ta-full").show();
			$("#prod-user .ta-summary").hide();
			$("#prod-user .expand-this").removeClass('plus').addClass('minus').text(vlCopy.hideRev);
		} else {
			$(this).text(vlCopy.exAllRev).removeClass('minus').addClass('plus');
			$("#prod-user .ta-full").hide();
			$("#prod-user .ta-summary").show();
			$("#prod-user .expand-this").removeClass('minus').addClass('plus').text(vlCopy.readRev);
		}
	});
}

function showOfferTac() { $('#book-offer-tac').addClass("dynamic").show();}
function hideOfferTac() { $('#book-offer-tac').hide();}
/* ################ End Expanders ################ */

/* ################  Extenal Links  ################ */
function externalLinks() { 
	var intLink = /^https?\:\/\/[a-z0-9\-]*.?visitlondon\.com/, server = /(web[1234]|preview|vl\-dev\-web1)/;
	$("a[href^='http']").filter(function() {return  !intLink.test($(this).attr("href"));}).filter(function() {return !server.test($(this).attr("href"));}).add("a.ext, a[href$='mp3'], a[href$='pdf'], a[href$='doc']").not(".gallery").not(".map-pop").attr('title','Link will open in a new window').not("a.pop").click(function() {window.open($(this).attr('href')); return false;});
	$("#content a[href^='http']").filter(function() {return !intLink.test($(this).attr("href"));}).filter(function() {return  !server.test($(this).attr("href"));}).add("#content a.ext, #content a[href$='mp3'], #content a[href$='pdf'], #content a[href$='doc']").not(".advert a").not(".yedda a").not(".button").not(".gallery").not(".map-pop").not(".noicon").append('<img src="http://static.visitlondon.com/images/icons/external-links.gif" alt=""	width="16" height="11" />');
	$("#content a[href$='.mp3']").after(" (Right click to download) ");
	$("#content a.pop").click(function() {window.open($(this).attr('href'),'','width=350,height=400,location=no,scrollbars=yes'); return false;});
}
/* ################  External Links  ################ */

/* ################  Explorer  ################ */
function overMap(whLink,whText,whCoords) {
	var points = whCoords.split(','), chooserW = (+points[2]) - (+points[0]), chooserH = (+points[3]) - (+points[1]); 
	$("#chooser").width(chooserW).height(chooserH).css('top',points[1] + "px").css('left',points[0] + "px").show().click(function() {showTube(whLink);});
}
function hoverBox(whVenue, whCoords) {
	 var points = whCoords.split(','), calX, calY;
	 if (points[0] > 386) {
	 	calX = 547 - parseInt(points[0],10);
	 	$("#venPop"+whVenue).css('right', calX + "px");
	 } else {
  	 	 calX = parseInt(points[0],10) + 11;
	 	 $("#venPop"+whVenue).css('left',  calX + "px");
	 }
	 if (points[1] < 120) {
	 	calY = parseInt(points[1],10) - 11;
	 	$("#venPop"+whVenue).css('top',  calY + "px");
	 } else {
		 calY = 525 - parseInt(points[1],10);
		 $("#venPop"+whVenue).css('bottom',  calY + "px");
	 }
	 $("#venPop"+whVenue).show('slow');
}

function closeHoverBox(whVenue) {
	 $("#venPop"+whVenue).hide('slow');
}
/* ################  End Explorer  ################ */

/* ################ Tabs  ################ */
function trackSwitchTabs(el) { 
var tab_title, tab_code, product_name = $("h1:first").text;
	switch (el) {
		case 'prod-menu'	:	dcsMultiTrack("WT.cg_n","","WT.cg_s","","WT.mc_id","","WT.si_n","","WT.si_p","","WT.z_vlSupplier","WT.z_ltvName","Tabs: "+product_name,"DCS.dcsuri","/js/showTab/Menu","WT.ti","Show Tab: Menu","WT.z_ltvDesc","","WT.z_ltvMenu","1","WT.z_ltvRev","","WT.z_ltvUser","","WT.z_ltvEvent","","WT.z_ltvOffer","","WT.z_ltvBook","","WT.z_ltvMap","","WT.z_ltvQAA","0"); break;	
		case 'prod-desc'       : dcsMultiTrack("WT.cg_n","","WT.cg_s","","WT.mc_id","","WT.si_n","","WT.si_p","","WT.z_vlSupplier","WT.z_ltvName","Tabs: "+product_name,"DCS.dcsuri","/js/showTab/Description","WT.ti","Show Tab: Description","WT.z_ltvDesc","1","WT.z_ltvMenu","","WT.z_ltvRev","","WT.z_ltvUser","","WT.z_ltvEvent","","WT.z_ltvOffer","","WT.z_ltvBook","","WT.z_ltvMap","","WT.z_ltvQAA","0"); break;	
		case 'prod-rev'        : dcsMultiTrack("WT.cg_n","","WT.cg_s","","WT.mc_id","","WT.si_n","","WT.si_p","","WT.z_vlSupplier","WT.z_ltvName","Tabs: "+product_name,"DCS.dcsuri","/js/showTab/Reviews","WT.ti","Show Tab: Reviews","WT.z_ltvDesc","","WT.z_ltvMenu","","WT.z_ltvRev","1","WT.z_ltvUser","","WT.z_ltvEvent","","WT.z_ltvOffer","","WT.z_ltvBook","","WT.z_ltvMap","","WT.z_ltvQAA","0"); break;	
		case 'prod-user'       : dcsMultiTrack("WT.cg_n","","WT.cg_s","","WT.mc_id","","WT.si_n","","WT.si_p","","WT.z_vlSupplier","WT.z_ltvName","Tabs: "+product_name,"DCS.dcsuri","/js/showTab/User Reviews","WT.ti","Show Tab: User Reviews","WT.z_ltvDesc","","WT.z_ltvMenu","","WT.z_ltvRev","","WT.z_ltvUser","1","WT.z_ltvEvent","","WT.z_ltvOffer","","WT.z_ltvBook","","WT.z_ltvMap","","WT.z_ltvQAA","0"); break;	
		case 'prod-event'      : dcsMultiTrack("WT.cg_n","","WT.cg_s","","WT.mc_id","","WT.si_n","","WT.si_p","","WT.z_vlSupplier","WT.z_ltvName","Tabs: "+product_name,"DCS.dcsuri","/js/showTab/Events","WT.ti","Show Tab: Events","WT.z_ltvDesc","","WT.z_ltvMenu","","WT.z_ltvRev","","WT.z_ltvUser","","WT.z_ltvEvent","1","WT.z_ltvOffer","","WT.z_ltvBook","","WT.z_ltvMap","","WT.z_ltvQAA","0"); break;	
		case 'prod-offer'	   : dcsMultiTrack("WT.cg_n","","WT.cg_s","","WT.mc_id","","WT.si_n","","WT.si_p","","WT.z_vlSupplier","WT.z_ltvName","Tabs: "+product_name,"DCS.dcsuri","/js/showTab/Offers","WT.ti","Show Tab: Offers","WT.z_ltvDesc","","WT.z_ltvMenu","","WT.z_ltvRev","","WT.z_ltvUser","","WT.z_ltvEvent","","WT.z_ltvOffer","1","WT.z_ltvBook","","WT.z_ltvMap","","WT.z_ltvQAA","0"); break;	
		case 'prod-book'	   : dcsMultiTrack("WT.cg_n","","WT.cg_s","","WT.mc_id","","WT.si_n","","WT.si_p","","WT.z_vlSupplier","WT.z_ltvName","Tabs: "+product_name,"DCS.dcsuri","/js/showTab/Prices and Booking","WT.ti","Show Tab: Prices and Booking","WT.z_ltvDesc","","WT.z_ltvMenu","","WT.z_ltvRev","","WT.z_ltvUser","","WT.z_ltvEvent","","WT.z_ltvOffer","","WT.z_ltvBook","1","WT.z_ltvMap","","WT.z_ltvQAA","0"); break;	
		case 'prod-map'	   	   : dcsMultiTrack("WT.cg_n","","WT.cg_s","","WT.mc_id","","WT.si_n","","WT.si_p","","WT.z_vlSupplier","WT.z_ltvName","Tabs: "+product_name,"DCS.dcsuri","/js/showTab/Map","WT.ti","Show Tab: Map","WT.z_ltvDesc","","WT.z_ltvMenu","","WT.z_ltvRev","","WT.z_ltvUser","","WT.z_ltvEvent","","WT.z_ltvOffer","","WT.z_ltvBook","","WT.z_ltvMap","1","WT.z_ltvQAA","0"); break;	
		case 'prod-qaa'	   	   : dcsMultiTrack("WT.cg_n","","WT.cg_s","","WT.mc_id","","WT.si_n","","WT.si_p","","WT.z_vlSupplier","WT.z_ltvName","Tabs: "+product_name,"DCS.dcsuri","/js/showTab/Map","WT.ti","Show Tab: Q and A","WT.z_ltvDesc","","WT.z_ltvMenu","","WT.z_ltvRev","","WT.z_ltvUser","","WT.z_ltvEvent","","WT.z_ltvOffer","","WT.z_ltvBook","","WT.z_ltvMap","0","WT.z_ltvQAA","1"); break;	
		default: tab_title="Unknown"; 
	}
}

function showtab(iTab) {
	if (iTab && iTab !== '') {
		$("#content .tabcnt").hide();
		$("#header .current").removeClass('current');
		$("#header .before-current").removeClass('before-current');
		$("#header #"+iTab+"-tab").addClass('current').prev().addClass("before-current");
	}
	var theTab = $("#header .current").attr('id').replace('-tab', ''), whichTab="#" + theTab;
	$(whichTab).show();
	trackSwitchTabs(theTab);
}

function setupTabs() {
	if($("#header .tablnk").size() === 0 || $(".tabcnt").size() === 0) {return false;}

	var links = $("#header .tablnk:last").addClass('last');
	$("#content .tabcnt").hide();
	$("#header .tablnk").css('cursor','pointer').click(function(event){
		$("#content .tabcnt").hide();
		$("#header .current").removeClass('current');
		$("#header .before-current").removeClass('before-current');
		$(this).parent().addClass('current').prev().addClass("before-current");
		$(this).blur();		
		showtab();
		return false;});
	showtab();
}
/* ################ End Tabs ################ */

/* ################  Multi Selector  ################ */
function multiPanel(whichPanel) {
	$("#selector-window > div").fadeOut(1000);
	$("#selector-window > div object").remove();
	$("#selector-controls li").removeClass("current");
	$("#selector-window > div:eq("+whichPanel+")").fadeIn(1000);
	var panelId = $("#selector-window > div:eq("+whichPanel+")").attr('id'), panelTitle = $("#selector-window > div:eq("+whichPanel+")").attr('title');
	$("#selector-controls li#link"+whichPanel).addClass("current");
	if($("#selector-window > div:eq("+whichPanel+") *").hasClass('hasFlash') ) {
		var flashProps = $("#selector-window > div:eq("+whichPanel+") .hasFlash").attr('title').split(',');
		$("#selector-window > div:eq("+whichPanel+") .hasFlash").flashembed({
			src: flashProps[0],
			width: flashProps[1],
			height: flashProps[2],
			version: [8,0]
		});
	}
	dcsMultiTrack("WT.cg_n","","WT.cg_s","","WT.mc_id","","DCS.dcsuri","/js/msclick/"+panelId,"WT.z_ltvName","MultiSelector: "+panelTitle,"WT.z_ltvView","1","WT.ti","MultiSelector: "+panelTitle);
}

function setupMultiPanel() {
	$("#selector-panel").addClass('withJS');
	$("#selector-panel").append('<ul id="selector-controls"></ul>');
	$("#selector-window > div").hide().css('position','absolute').css('top','0px').css('left','0px').each(
	function(n) {
		$("#selector-controls").append('<li id="link'+n+'">'+this.title+'</li>');
		$("#link"+n).click( function(event) {multiPanel(n); } );
	});	
	if($.browser.msie || $.browser.opera)  {
		$("#selector-controls li").append('<i class="br"></i><i class="bl"></i>');
	}
	multiPanel(0);
}
/* ################ End Multi Selector  ################ */


/* ################ Top Nav ################ */
function topmenuClear() {
	$("#topmenu *").removeClass("over");
	$("#topmenu .current").removeClass("fade");
}
/* ################ End Top Nav ################ */

/* ################ Search  ################ */
/* Dates */
function getMaxDay(selectedMonth,selectedYear) {
	var maxDay;
	if (selectedMonth == '2') { if (leapYear(selectedYear) ) {maxDay = 29;} else {maxDay = 28;} }    else { if  (selectedMonth == '4' || selectedMonth == '6' || selectedMonth == '9' || selectedMonth == '11') { maxDay = 30;} else { maxDay = 31; } }
  return maxDay;
}
function getMinDay(selectedMonth,selectedYear) {
	var minDay;
	if (selectedMonth == currentMonth && selectedYear == currentYear) { minDay = currentDay; }
	else { minDay = 1; }
	return minDay;
}
function checkMonths(whichEnd,dftOpt,formID) {
	if (!dftOpt || dftOpt === "") {dftOpt = 0;}
	if (!formID	|| formID === "") {formID = "search";}
	var	f = document.getElementById(formID), 
		whichMonth = $("#"+formID+" select[name="+whichEnd+".month-year]").get(0),
		whichDay = $("#"+formID+" select[name="+whichEnd+".day]").get(0);
		// whichMonth = f.elements[whichEnd + ".month-year"], whichDay = f.elements[whichEnd + ".day"];
	if (whichMonth.options[whichMonth.selectedIndex].value === "") {return false;}
	var inDateArray = whichMonth.options[whichMonth.selectedIndex].value.split("-"), selectedMonth = parseInt(inDateArray[0],10), selectedYear =  parseInt(inDateArray[1],10), selectedDay = whichDay.options[whichDay.selectedIndex].value, maxDay = getMaxDay(selectedMonth,selectedYear), minDay = getMinDay(selectedMonth,selectedYear);
	while (whichDay.length > dftOpt) { whichDay.remove(dftOpt); }
	for (var k = minDay; k <= maxDay; k++) {
		var kpos = k - minDay + dftOpt, ksel = false; 
		if (k == selectedDay) { ksel = true; }
     	whichDay.options[kpos] = new Option(k, k, false, ksel);
	}
}

function checkDates(whichEnd,dftOpt,formID,minDur) {
	if (!dftOpt || dftOpt === "") { dftOpt = 0;}
	if (!formID || formID === "") { formID = "search";}
	var f = document.getElementById(formID), toMonth, fromMonth, toDay, fromDay;
	if (f.elements['from.month-year'] && f.elements['to.month-year']) {
		toMonth = f.elements['to.month-year']; 
		fromMonth = f.elements['from.month-year'];
		toDay = f.elements['to.day']; 
		fromDay = f.elements['from.day'];
		if (dftOpt == 1 && (toMonth.selectedIndex === 0 || fromMonth.selectedIndex === 0)) {return false;} 
		if (toMonth.selectedIndex < fromMonth.selectedIndex || (toMonth.selectedIndex == fromMonth.selectedIndex && toDay.selectedIndex <= fromDay.selectedIndex))  {
		// if end date is before start date
			if (minDur === 0) {
				if (whichEnd == 'from') {
					toMonth.selectedIndex = fromMonth.selectedIndex; checkMonths('to',dftOpt,formID); toDay.selectedIndex = fromDay.selectedIndex;
					// sent end date to same as start date
				} else {
					if (whichEnd == 'to') {
						fromMonth.selectedIndex = toMonth.selectedIndex; checkMonths('from',dftOpt,formID); fromDay.selectedIndex = toDay.selectedIndex;
						// sent start date to same as end date
					}
				}
			} else {
				if (whichEnd == 'from') {
					if (fromDay.selectedIndex == fromDay.length-1) {
						toMonth.selectedIndex = fromMonth.selectedIndex+1; checkMonths('to',dftOpt,formID); toDay.selectedIndex = 0;
					}
					// if start date is last day of the month
					// set end date to first day of the next month
					else {
						toMonth.selectedIndex = fromMonth.selectedIndex; checkMonths('to',dftOpt,formID); toDay.selectedIndex = fromDay.selectedIndex+1;
					}
				// set end date to day after start date
				} else { 
					if (whichEnd == 'to') {
						if (toDay.selectedIndex === 0) {
						// if end date is first day of month
							if ( toMonth.selectedIndex !== 0) {
								fromMonth.selectedIndex = toMonth.selectedIndex-1; checkMonths('from',dftOpt,formID); fromDay.selectedIndex = fromDay.length-1;
							} 
							// if end date is not first possible month
							// set start date to last day of the previous month
							else {
								fromMonth.selectedIndex = toMonth.selectedIndex; checkMonths('from',dftOpt,formID); fromDay.selectedIndex = 0; toDay.selectedIndex = 1; 
							}
					// set start date to first possible date and end date to the day after that
						} else {
							fromMonth.selectedIndex = toMonth.selectedIndex; checkMonths('from',dftOpt,formID); fromDay.selectedIndex = toDay.selectedIndex-1;
						}
				// set start date to day before end date
					}
				}
			}
		}
	}
}

function isNumber(v) {return typeof v === 'number' && isFinite(v);}

function getDatePeriod() {
	var currentDate = new Date(), searchFromDate = new Date(), searchToDate = new Date(), selectedOption = $("#days-ahead").val(), selectedOptionNumber = parseInt(selectedOption,10);
	currentDate.setFullYear(currentYear,currentMonth-1,currentDay);
	if (isNumber(selectedOptionNumber)) {
		searchFromDate.setFullYear(currentYear,currentMonth-1,currentDay+1); searchToDate.setFullYear(currentYear,currentMonth-1,currentDay+selectedOptionNumber);
	} else {
		switch (selectedOption) {
			case 'Today': 			searchFromDate = currentDate; searchToDate = currentDate; break; 
			case 'This Weekend': switch (currentDate.getDay()) {
				case 0 : searchFromDate = currentDate; searchToDate = currentDate; break; // Sunday
				case 1 : searchFromDate.setFullYear(currentYear,currentMonth-1,currentDay+5); searchToDate.setFullYear(currentYear,currentMonth-1,currentDay+6); break;
				case 2 : searchFromDate.setFullYear(currentYear,currentMonth-1,currentDay+4); searchToDate.setFullYear(currentYear,currentMonth-1,currentDay+5); break;
				case 3 : searchFromDate.setFullYear(currentYear,currentMonth-1,currentDay+5); searchToDate.setFullYear(currentYear,currentMonth-1,currentDay+4); break;
				case 4 : searchFromDate.setFullYear(currentYear,currentMonth-1,currentDay+2); searchToDate.setFullYear(currentYear,currentMonth-1,currentDay+3); break;
				case 5 : searchFromDate.setFullYear(currentYear,currentMonth-1,currentDay+1); searchToDate.setFullYear(currentYear,currentMonth-1,currentDay+2); break;
				case 6 : searchFromDate = currentDate; searchToDate.setFullYear(currentYear,currentMonth-1,currentDay+1);break; 
			} break; 
			case 'Next Weekend': 	switch (currentDate.getDay()) {
				case 0 : searchFromDate.setFullYear(currentYear,currentMonth-1,currentDay+13); searchToDate.setFullYear(currentYear,currentMonth-1,currentDay+14); break;   // Sunday
				case 1 : searchFromDate.setFullYear(currentYear,currentMonth-1,currentDay+12); searchToDate.setFullYear(currentYear,currentMonth-1,currentDay+13); break;
				case 2 : searchFromDate.setFullYear(currentYear,currentMonth-1,currentDay+11); searchToDate.setFullYear(currentYear,currentMonth-1,currentDay+12); break;
				case 3 : searchFromDate.setFullYear(currentYear,currentMonth-1,currentDay+10); searchToDate.setFullYear(currentYear,currentMonth-1,currentDay+11); break;
				case 4 : searchFromDate.setFullYear(currentYear,currentMonth-1,currentDay+9);  searchToDate.setFullYear(currentYear,currentMonth-1,currentDay+10); break;
				case 5 : searchFromDate.setFullYear(currentYear,currentMonth-1,currentDay+8);  searchToDate.setFullYear(currentYear,currentMonth-1,currentDay+9);  break;
				case 6 : searchFromDate.setFullYear(currentYear,currentMonth-1,currentDay+7);  searchToDate.setFullYear(currentYear,currentMonth-1,currentDay+8);  break;
			} break; 
			case 'Tomorrow': 		searchFromDate.setFullYear(currentYear,currentMonth-1,currentDay+1); searchToDate.setFullYear(currentYear,currentMonth-1,currentDay+1); break; 
			case 'Next Month': 		searchFromDate.setFullYear(currentYear,currentMonth-1,currentDay+1); searchToDate.setFullYear(currentYear,currentMonth,currentDay); break; 
			case 'Next 3 Months': 	searchFromDate.setFullYear(currentYear,currentMonth-1,currentDay+1); searchToDate.setFullYear(currentYear,currentMonth+2,currentDay); break; 
			case 'Next 6 Months': 	searchFromDate.setFullYear(currentYear,currentMonth-1,currentDay+1); searchToDate.setFullYear(currentYear,currentMonth+5,currentDay); break; 
			case 'Next Year': 		searchFromDate.setFullYear(currentYear,currentMonth-1,currentDay+1); searchToDate.setFullYear(currentYear,currentMonth+11,currentDay); break; 
			default: searchFromDate = null; searchToDate = null; break;
		}
	}
	if (searchFromDate !== null) {
		$("#from-day-h").val(searchFromDate.getDate());
		$("#from-month-year-h").val(searchFromDate.getMonth()+1 + '-' + searchFromDate.getFullYear());
	} else {
		$("#from-day-h").val('');
		$("#from-month-year-h").val('');
	}
	if (searchToDate !== null) {
		$("#to-day-h").val(searchToDate.getDate());
		$("#to-month-year-h").val(searchToDate.getMonth()+1 + '-' + searchToDate.getFullYear());
	} else {
		$("#to-day-h").val('');
		$("#to-month-year-h").val('');
	}
}



/* Rooms related */
function checkRooms(formID) {
if (!formID || formID === "") {formID = "search";}
var searchSuffix;
switch (formID) {
		case 'lpsearch' : searchSuffix = "lp"; break;
		case 'pdsearch' : searchSuffix = "pd"; break;
		case 'assearch' : searchSuffix = "as"; break;
		case 'search'   : searchSuffix = "sb"; break;
}
/* Only 3 rooms permitted so crude but effective switch can be used */
switch($("#"+formID+" select[name=roomsNum]").val()) {
	case '1' : 
		$("#r2-" + searchSuffix).hide();
		$("#r2-" + searchSuffix + " select").attr('disabled','disabled');
		$("#r3-" + searchSuffix).hide();
		$("#r3-" + searchSuffix + " select").attr('disabled','disabled');
		break;
	case '2' : 
		$("#r2-" + searchSuffix).show();
		$("#r2-" + searchSuffix + " select").removeAttr('disabled');
		$("#r3-" + searchSuffix).hide();
		$("#r3-" + searchSuffix + " select").attr('disabled','disabled');
		break;
	case '3' :
		$("#r2-" + searchSuffix).show();
		$("#r2-" + searchSuffix + " select").removeAttr('disabled');
		$("#r3-" + searchSuffix).show();
		$("#r3-" + searchSuffix + " select").removeAttr('disabled');
		break;
}
}


function getTotal(formID) {
	var total = 0.00;
	$("#"+formID+" input:radio:checked").each(
		function() {
			total += +($(this).attr('class'));
		}
	);
	$("#partyprice-"+formID).html(vlCopy.totalPrice + " \xA3"+total.toFixed(2));
}

(function($){
$.fn.dynamicSelect = function() {
	return this.filter('select').each(function() {
		var s0id = this.id, s1id = s0id+'-s1', s2id = s0id+'-s2';
		$(this).parent().append('<select id="'+s1id+'" name="'+s0id+'" class="rtxtbox"></select><br/><select id="'+s2id+'" name="'+this.name+'" class="rtxtbox"></select>');
		$("label[for="+s0id+"]").attr('for',s1id);
		if($(this).hasClass('adv')) {$('#'+s1id+', #'+s2id).addClass('adv');}
		$(this).children('option:first').clone().appendTo($('#'+s1id));
		$(this).children('optgroup').each(function() {
				var isSelected='';
				if ( $('#'+s0id+' option:selected').parent('optgroup').attr('id') == this.id) {isSelected='selected="selected"';}
				$('#'+s1id).append('<option value="'+this.id+'" '+isSelected+'>'+this.label+'</option>');
			}
		);
		$('#'+s1id).change(
			function() {
				var srcID = $('#'+s1id+ " option:selected").val();
				var srcOG = '#'+s0id + ' optgroup#'+srcID;
			
				if (srcID === '' || $(srcOG).size() === 0) {
					$('#'+s2id).empty().append('<option value="">' + vlCopy.pleaseChoose + '</option>').attr('disabled','disabled').after('<input type="hidden" name="' + $('#'+s2id).attr('name') + '" value="'+ $('#'+s1id).children('option:first').val()  +'" id="'+ s0id +'-nulloption" />');					
				} else {
					$('#'+ s0id +'-nulloption').remove();
					$('#'+s2id).empty().removeAttr('disabled');
					$(srcOG+' option').clone().appendTo($('#'+s2id));
					$('#'+s2id).children('option:first').prepend(vlCopy.all);	
					var trgVal = $(srcOG+' option:selected').val();
					$('#'+s2id).children('option[value='+trgVal+']').attr('selected','selected'); /* hack forIE - works without this in other browsers */
				}
			}
		).trigger('change');

		$(this).hide().attr('disabled','disabled').removeClass('adv');
		$('#'+s0id+' option:selected').removeAttr('selected');
	});
	};
})(jQuery);


function toggleOptions(p1,p2) {
// hide everything in p1, show everything in p2
	$("#"+p1).hide().removeClass('current-option');
	$("#" + p1 +" .adv").attr('disabled','disabled');
	$("#"+p2).show().addClass('current-option');
	$("#" + p2 + " .adv").removeAttr('disabled');
	$("#"+p2+" .fTrg").get(0).focus();
}

var searchToggle = location.pathname.indexOf('search') != -1 ? 'advanced' : 'simple'; 
// make it a global variable for now
// searchToggle is the state the search form will switch to the NEXT time configureSearch is used.

function configureSearch(formID) {
	if (searchToggle == "simple") {
		$("#"+formID+" div.advanced-search fieldset.advanced").hide();
		$("#advanced-search-link").text(vlCopy.moreOptions).addClass('plus').removeClass('minus');				
		$("#"+formID+" .adv").attr('disabled', 'disabled');
		searchToggle = "advanced";
	} else {
		$("#"+formID+" div.advanced-search fieldset.advanced").show();
		$("#"+formID+" .adv").removeAttr('disabled');
		$("#sbGeoLocation").hasClass('current-option') ? toggleOptions('sbGeoArea','sbGeoLocation') : toggleOptions('sbGeoLocation','sbGeoArea');
		$("#sbDatePeriod").hasClass('current-option') ? toggleOptions('sbDateSpecific','sbDatePeriod') : toggleOptions('sbDatePeriod','sbDateSpecific');
		$("#advanced-search-link").text(vlCopy.fewerOptions).addClass('minus').removeClass('plus');
		searchToggle = "simple";
	}			
}

$.fn.setupSearch = function() {
	return this.each(function() {
		if (typeof this.id != "undefined" && this.id.length > 1) {
			var formID  = this.id;

			$("#"+formID+" div.advanced-search fieldset").addClass('advanced');
			$("#"+formID+" div.advanced-search").append('<fieldset><a id="advanced-search-link" class="plus"></a></fieldset>');
			
			$("#advanced-search-link").click(function(){configureSearch(formID);});

			if (location.pathname.indexOf('/accommodation/') != -1) {
			// do this better
				if ($("select[name='from.month-year']".length > 0)) {checkMonths('from',0,formID);}
				if ($("select[name='to.month-year']".length > 0)) {checkMonths('to',0,formID);}
			} else {
				if ($("select[name='from.month-year']".length > 0)) {checkMonths('from',0,formID);}
				if ($("select[name='to.month-year']".length > 0)) {checkMonths('to',1,formID);}
			}

			$("#sbGeoLocation").append('<span class="note"><a class="toggle-link">'+vlCopy.orArea+'</a></span>');
			$("#sbGeoLocation a.toggle-link").click(function() {toggleOptions('sbGeoLocation','sbGeoArea');});
		
			$("#sbGeoArea").append('<span class="note"><a class="toggle-link">'+vlCopy.orPostcode+'</a></span>');
			$("#sbGeoArea a.toggle-link").click(function() {toggleOptions('sbGeoArea','sbGeoLocation');});

			$("#sbDatePeriod").append('<span class="note"><a class="toggle-link">'+vlCopy.orDates+'</a></span>');  
			$("#sbDatePeriod a.toggle-link").click(function() {toggleOptions('sbDatePeriod','sbDateSpecific');});
			$("#sbDatePeriod a.toggle-link").click(function() {toggleOptions('sbDatePeriod','sbDateSpecific');});

			$("#sbDateSpecific").append('<span class="note"><a class="toggle-link">'+vlCopy.orPeriod+'</a></span>');  
			$("#sbDateSpecific a.toggle-link").click(function() {toggleOptions('sbDateSpecific','sbDatePeriod');});

			$("#days-ahead").removeAttr('name').change(function() {getDatePeriod()});
			$("#days-ahead option:eq(1)").after('<option value="This Weekend">This Weekend</option><option value="Next Weekend">Next Weekend</option>').before('<option value="Today">Today</option>');

			configureSearch(formID);
		}
	});
};

function setupAcc(formID) {
	if (!formID || formID === "") {formID = "search";}
	var bgPic = new Image(), overlayImage = new Image(), today = new Date(), hamperEndDate=new Date();
	bgPic.src = "http://static.visitlondon.com/images/explorer-map/white.png";
	overlayImage.src = "http://static.visitlondon.com/assets/accommodation/interstitial.png";
	$("select[name=roomsNum]").change(function() {checkRooms(formID);});
	$("#"+formID+" .room select[name=adults] option[value=0]").remove();
	checkRooms(formID);
	if (formID != 'rfsearch') {checkMonths('from',0,formID); checkMonths('to',0,formID);}
	if (formID == 'search' && document.getElementById('search-summary')) {$("#search").hide();}
}

function searchOverlay() {
	var wf = '754', hf = '429', wi = '748', hi ='423', oVideo, oImg, today = new Date(), hamperEndDate=new Date();
	oVideo = "http://static.visitlondon.com/assets/accommodation/interstitial.swf";
	oImg = "http://static.visitlondon.com/assets/accommodation/interstitial.png";
	$("body").append('<div id="search-overlay" class="search-overlay"><br/></div>').unload(function() {
		if ($.browser.msie ) { $("applet", "iframe", "select", "embed", "object").css('visibility','visible'); }
		$("#search-overlay").remove();
	});
	if ($.browser.msie ) { 
		$("#search-overlay").flashembed({
			src: 		oVideo,
			width: 		wf, 
			height: 	hf,
			play: 		"true",
			wmode:		"transparent",
			version:	[8,0]
		});
		if (!flashembed.isSupported([8, 0])) { $("#search-overlay").empty().append('<img src="'+oImg+'" alt="" width="'+wi+'" height="'+hi+'"/>'); }
		$("applet", "iframe", "select", "embed", "object").css('visibility','hidden');
	} else {
		$("#search-overlay").empty().append('<img src="'+oImg+'" alt="" width="'+wi+'" height="'+hi+'"/>');
	}
	dcsMultiTrack("WT.cg_n","","WT.cg_s","","WT.mc_id","","WT.z_vlSupplier","","DCS.dcsuri","/accommodation/search/overlay","WT.ti","Accommodation Search Overlay","WT.si_n","BookingSearch","WT.si_p","Splash");	
}
/* ################ End Search  ################ */

function showBookmarks() {
	if(window.print) {
		$('#addPrint').html('<a href="#" onclick="window.print(); return false;">'+vlCopy.printPage+'</a>');
	}
	if($.browser.msie) {
		$('#addBook').html('<a href="#" onclick="window.external.AddFavorite(window.location.href,document.title);return false;">'+vlCopy.bookmarkPage+'</a>');
	}
}

/* ################ Trips  ################ */

function numberTrips() {
  var k;
	$("#trips fieldset").each(function(i){
		k = i+1; $(this).children("h3").text(vlCopy.trip + ' ' + k);
	});
  $("#trips-count").val(k);
  if ($("#trips fieldset").length == 10) {
    $("#addButton, #tripsControls span").hide();
  } else {
    $("#addButton, #tripsControls span").show();
  }
	if ($("#trips fieldset").length == 1) {
		$("#trips div.remove").hide();
	} else {
		$("#trips div.remove").show();
	}
}

function validateTrips() {
  var errorMsg = "";
  $("#trips fieldset").each(function(i){
	var k = i+1, aDate, dDate, f = $(this);
    if ($(this).find("input.textbox").val() == "") {
      errorMsg += vlCopy.errorTripNoName(k)  + '\n';
    }
	if ($(this).find("select:eq(0)").val() == "" || $(this).find("select:eq(1)").val() == "" || $(this).find("select:eq(2)").val() == "") {
      errorMsg += vlCopy.errorTripNoArrival(k) + '\n';
    }
    if ($(this).find("select:eq(3)").val() == "" || $(this).find("select:eq(4)").val() == "" || $(this).find("select:eq(5)").val() == "") {
      errorMsg += vlCopy.errorTripNoDeparture(k) + '\n';
    }
    aDate = new Date($(this).find("select:eq(2)").val(), $(this).find("select:eq(1)").val() -1, $(this).find("select:eq(0)").val());
	dDate = new Date($(this).find("select:eq(5)").val(), $(this).find("select:eq(4)").val() -1, $(this).find("select:eq(3)").val());
	if (dDate.getTime() < aDate.getTime())	{
		errorMsg += vlCopy.errorTripNoAfter(k) + '\n';
	}
	if ($(this).find("input[name=reason]:checked").length === 0) {
      errorMsg += vlCopy.errorTripNoReason(k)  + '\n';
    }
  });
  if (errorMsg != "") {
    alert(errorMsg); 
	return false;
  } else {
    return true;
  }
}

function validateTrip(f) {
	var errorMsg = "", aDate, dDate;
    if ($(f).find("input.textbox").val() == "") {
      errorMsg += vlCopy.errorTripThisName + '\n';
    }
    if ($(f).find("select:eq(0)").val() == "" || $(f).find("select:eq(1)").val() == "" || $(f).find("select:eq(2)").val() == "") {
      errorMsg += vlCopy.errorTripThisArrival + '\n';
    }
    if ($(f).find("select:eq(3)").val() == "" || $(f).find("select:eq(4)").val() == "" || $(f).find("select:eq(5)").val() == "") {
      errorMsg += vlCopy.errorTripThisDeparture + '\n';
    }
    aDate = new Date($(f).find("select:eq(2)").val(), $(f).find("select:eq(1)").val() -1, $(f).find("select:eq(0)").val());
	dDate = new Date($(f).find("select:eq(5)").val(), $(f).find("select:eq(4)").val() -1, $(f).find("select:eq(3)").val());
	if (dDate.getTime() < aDate.getTime())	{
		errorMsg += vlCopy.errorTripThisAfter + '\n';
	}
  if (errorMsg != "") {
    alert(errorMsg); 
	return false;
  } else {
    return true;
  }
}

function checkDeleteTrip(tn) {
	return confirm(vlCopy.removeTrip(tn));
}
/* ################ End Trips  ################ */

/* ################ Map  ################ */
function changeTicMap(whMap) {
	var theMap = {
		mapSrc: 'http://static.visitlondon.com/assets/maps/tourist_information/', 
		mapAlt: 'Map showing location of Tourist Information Centers and Community Wardens in ', 
		mapMap: ''
	};
	switch (whMap) {
        case 'north'    : theMap.mapSrc+='north-large.gif';    theMap.mapAlt+='North London';     theMap.mapMap='#ticMapNorth';      break;  
        case 'south'    : theMap.mapSrc+='south-large.gif';    theMap.mapAlt+='South London';     theMap.mapMap='#ticMapSouth';      break;  
        case 'east'     : theMap.mapSrc+='east-large.gif';     theMap.mapAlt+='East London';      theMap.mapMap='#ticMapEast';       break;  
        case 'west'     : theMap.mapSrc+='west-large.gif';     theMap.mapAlt+='West London';      theMap.mapMap='#ticMapWest';       break;  
        case 'central'  : theMap.mapSrc+='central-large.gif';  theMap.mapAlt+='Central London';   theMap.mapMap='#ticMapCentral';    break;  
        case 'all'      : theMap.mapSrc+='overview-large.gif'; theMap.mapAlt+='London';           theMap.mapMap='#ticMapAll';        break;  
    }
    $('#ticMap').attr({src: theMap.mapSrc, alt: theMap.mapAlt, useMap: theMap.mapMap});
}

function repoMap(e) {
	var i, mox, moy, pox, poy, offset = $("#venueMap").offset(), newURL = "http://maps.visitlondon.com/?", oldx, oldy, mapScale, meterScale, mapWidth, mapHeight, newx, newy, elArray = $('#venueMap').attr('src').split(/[\?\&]/), product_name = $("h1:first").text();
	for (i = 1; i < elArray.length; i++) { if (elArray[i].indexOf('x=') == -1 && elArray[i].indexOf('y=') == -1 && elArray[i].indexOf('arrow=') == -1 ) {newURL+= elArray[i]+'&';}}
	for (i = 0; i < elArray.length; i++) {  
		if (elArray[i].indexOf('x=') === 0 ) { oldx = elArray[i].substring(2);}	
		if (elArray[i].indexOf('y=') === 0 ) { oldy = elArray[i].substring(2);}	
		if (elArray[i].indexOf('scale=') === 0 ) { mapScale = elArray[i].substring(6);}
		if (elArray[i].indexOf('w=') === 0 ) { mapWidth = elArray[i].substring(2);}
		if (elArray[i].indexOf('h=') === 0 ) { mapHeight = elArray[i].substring(2);}
	}
	meterScale = 1.333 / +mapScale;
	
	// Find click offset from map centre in pixels
	pox = Math.floor((e.pageX - Math.floor(offset.left)) - (+mapWidth / 2));
	poy = Math.floor((+mapHeight / 2) - (e.pageY - Math.floor(offset.top)));	
	
	// Find click offset from map centre in meters
	mox = Math.floor(pox * meterScale);
	moy = Math.floor(poy * meterScale);
	newx = +oldx + mox;
	newy = +oldy + moy;
	newURL+= 'x='+newx+'&y='+newy;
	$("#venueMap").attr('src', newURL);
	dcsMultiTrack("WT.cg_n","","WT.cg_s","","WT.mc_id","","WT.si_n","","WT.si_p","","WT.z_vlSupplier","","DCS.dcsuri","/js/map/click/","WT.ti","Map: Reposition Map","WT.z_ltvName","Map: "+product_name,"WT.z_ltvScrollMap","1","WT.z_ltvZoomIn","","WT.z_ltvZoomOut","");	
}

function zoomMap(dir) {
	var i, oldscale, oldPosition, newPosition, newURL = "http://maps.visitlondon.com/?", elArray = $('#venueMap').attr('src').split(/[\?\&]/), mapScales = [1.0, 0.711, 0.5, 0.356, 0.237, 0.178, 0.119], product_name = $("h1:first").text();
	for (i = 0; i < elArray.length; i++) {if (elArray[i].indexOf('scale=') === 0 ) { oldscale = elArray[i].substring(6);}}
	for (i=0;i<mapScales.length;i++) {if(mapScales[i]==oldscale) {oldPosition = i;break;}}
	if (dir == "up" && oldPosition !== 0) {	newPosition = +oldPosition - 1;	} else if (dir == "down" && oldPosition != 6) {	newPosition = +oldPosition + 1;} else {return false;}
	for (i = 1; i < elArray.length; i++) {if (elArray[i].indexOf('scale=') == -1) {newURL+= elArray[i]+'&';}}
	newURL+= 'scale='+mapScales[newPosition];
	$("#venueMap").attr('src', newURL);
	if (dir == "up") {
		dcsMultiTrack("WT.cg_n","","WT.cg_s","","WT.mc_id","","WT.si_n","","WT.si_p","","WT.z_vlSupplier","","DCS.dcsuri","/js/map/zoom/in","WT.ti","Map: Zoom In","WT.z_ltvName","Map: "+product_name,"WT.z_ltvScrollMap","","WT.z_ltvZoomIn","1","WT.z_ltvZoomOut","");	
	} else {
		dcsMultiTrack("WT.cg_n","","WT.cg_s","","WT.mc_id","","WT.si_n","","WT.si_p","","WT.z_vlSupplier","","DCS.dcsuri","/js/map/zoom/out","WT.ti","Map: Scroll Out","WT.z_ltvName","Map: "+product_name,"WT.z_ltvScrollMap","","WT.z_ltvZoomIn","","WT.z_ltvZoomOut","1");	
	}
}

function scrollMap(direction) {
	var i, offsetx = 0, offsety = 0, newURL = "http://maps.visitlondon.com/?", newx, newy, elArray = $('#venueMap').attr('src').split(/[\?\&]/), product_name = $("h1:first").text();
	for (i = 0; i < elArray.length; i++) {
		if (elArray[i].indexOf('offset-x') != -1 ) { offsetx = elArray[i].substring(9);}
		else if (elArray[i].indexOf('offset-y') != -1 ) { offsety = elArray[i].substring(9);}
	}
	switch (direction) {
		case 'n'    : newx=offsetx;  newy=+offsety+500;	break;	
		case 'e'    : newx=+offsetx+500;  newy=offsety;	break;	
		case 'w'    : newx=+offsetx-500;  newy=offsety;	break;	
		case 's'    : newx=offsetx;  newy=+offsety-500;	break;	
		case 'ne'   : newx=+offsetx+500;  newy=+offsety+500; break;	
		case 'nw'   : newx=+offsetx-500;  newy=+offsety+500; break;	
		case 'se'   : newx=+offsetx+500;  newy=+offsety-500; break;
		case 'sw'   : newx=+offsetx-500;  newy=+offsety-500; break;					
		default: newx=offsetx;  newy=offsety;
	}
	for (i = 1; i < elArray.length; i++) {	
		if (elArray[i].indexOf('offset-x') == -1 && elArray[i].indexOf('offset-y') == -1 ) {newURL+= elArray[i]+'&';}
	}
	newURL+= 'offset-x='+newx+'&offset-y='+newy;
	$("#venueMap").attr('src', newURL);
	dcsMultiTrack("WT.cg_n","","WT.cg_s","","WT.mc_id","","WT.si_n","","WT.si_p","","WT.z_vlSupplier","","DCS.dcsuri","/js/map/scroll/"+direction,"WT.ti","Map: Scroll "+direction,"WT.z_ltvName","Map: "+product_name,"WT.z_ltvScrollMap","1","WT.z_ltvZoomIn","","WT.z_ltvZoomOut","");	
}

function setupMap() {
if ($('#productMap').size() === 0) {return false;}
$("#productMap").append('<img class="nw" src="http://static.visitlondon.com/images/explorer-map/map-arrow-nw.gif" alt="'+vlCopy.mapNW+'" width="15" height="16" /><img class="n" src="http://static.visitlondon.com/images/explorer-map/map-arrow-n.gif"  alt="'+vlCopy.mapN+'" width="21" height="11" /><img class="ne" src="http://static.visitlondon.com/images/explorer-map/map-arrow-ne.gif"  alt="'+vlCopy.mapNE+'" width="15" height="16" /><img class="w" src="http://static.visitlondon.com/images/explorer-map/map-arrow-w.gif" alt="'+vlCopy.mapW+'" width="18" height="21" /><img class="e" src="http://static.visitlondon.com/images/explorer-map/map-arrow-e.gif"  alt="'+vlCopy.mapE+'" width="18" height="21" /><img class="sw" src="http://static.visitlondon.com/images/explorer-map/map-arrow-sw.gif" alt="'+vlCopy.mapSW+'" width="15" height="16" /><img class="s" src="http://static.visitlondon.com/images/explorer-map/map-arrow-s.gif" alt="'+vlCopy.mapS+'"   width="21" height="11"  /><img class="se" src="http://static.visitlondon.com/images/explorer-map/map-arrow-se.gif" alt="'+vlCopy.mapSE+'" width="15" height="16" />');
$("#venueMap").css('cursor','pointer').click(function(e) {repoMap(e);}).attr('title','Click to reposition the map. \nUse the + and - keys or the mouse wheel to zoom the map.');
$("#productMap > img").css('cursor','pointer').click(function() {scrollMap(this.className);});
$(document).keypress(function(e) {if (e.which == 43 || e.which == 64) {zoomMap("up");} else if (e.which == 45 ) { zoomMap("down");} });
$("#venueMap").mousewheel(function(e, delta) {if (delta > 0){zoomMap("up");} else if (delta < 0)  { zoomMap("down");} return false;});
}
/* ################ End Map  ################ */

	var now = new Date(), message;
	if (now.getHours() > 17) { message = "Good evening"; }
	else  if (now.getHours() > 11)  {message = "Good afternoon";}
	else  if (now.getHours() > 5)  {message = "Good morning";}
	else {message = "Hello";}

/* ################ Loader ################ */
 $(document).ready(function(){
	if($.browser.msie)  {$("body").addClass('isIE');}
	if($.browser.opera)  {$("body").addClass('isOp');}
	if($.browser.safari)  {$("body").addClass('isWk');}
	setupTabs();   
	setupHidden();
	setupUserReviews();
	$("#topmenu > li").hover(
		function(){ clearTimeout(navTimer); topmenuClear();  $(this).addClass("over");  $(this).find(":first").addClass("over"); if($(this).attr('id') != $("#topmenu .current").attr('id')) { $("#topmenu .current").addClass("fade"); }	},
		function(){ navTimer = setTimeout(topmenuClear,2000); }
	);
	$("img.rollover, input.rollover, a.rollover img").hover(
		function () { var tSrc = $(this).attr('src'); $(this).attr('src', tSrc.replace('-off.', '-on.')); },
		function () { var tSrc = $(this).attr('src'); $(this).attr('src', tSrc.replace('-on.', '-off.')); }	
	);
	$(".media img.pimage:odd").addClass('lcol');
	$(".innerTopTable+.media").addClass('withTT');
	
	if (location.pathname.indexOf('aus_sweeps_oct09') != -1) {$("#sidebar form#questions h3").remove();}
	
	externalLinks();
	hideOfferTac();
	drawTV();
	if (document.getElementById('tubeparent')) { showTube('tubeparent'); }
	showBookmarks();
	$('a.gallery, .gallery-icon a').lightBox(); 
	$('a.map-pop').lightBox({
		overlayClassName: 'mapOverlay',
		overlayBgColor: '#FFF'
	});

	$("form.acc-booking").each( 
		function() {
			var that = $(this).attr('id');
			getTotal(that);
			$("#"+that+" :radio").click(
				function() {
					getTotal(that);
				}
			);
		}	
	);

	$("#mapVillages").flashembed({
		src: 		"http://static.visitlondon.com/assets/areas/villages/interactive-map.swf",
		width: 		$.browser.msie ? '950':'565', 
		height: 	'564',
		play: 		"true",
		wmode: 		"transparent",
		version:	[8,0]
	});
	if ($.browser.msie) { $('#mapVillages').css('left', '-191px'); }
	
	setupMap();

	$(".explorer .results li").each(function(n){
		var i = n+1, catId = "cat" + i, picId = "pic" + i; 
		var theHtml = '<div id="venPop'+ i +'" class="popBox"><b>'+ $(this).children("h3").children("a").text() + '</b><br />';
			if (document.getElementById(catId)) {theHtml += document.getElementById(catId).innerHTML + "<br />";}
			if (document.getElementById(picId)) {theHtml += document.getElementById(picId).innerHTML;}
		theHtml += '</div>';
		$("#mapInner").append(theHtml);
		}
	);
	$("#mapInner area").hover(
		function() { hoverBox(this.tabIndex, this.coords);},
		function() { closeHoverBox(this.tabIndex);}
	);
	
	$("#refine-regions").dynamicSelect();
	$("#regions").dynamicSelect();
	$("#sections").dynamicSelect(); 
	$("form[id*=search]").setupSearch();
	
	$("p.welcome span#message").text(message);
		
	$("#jpf").flashembed({
		src: 		"http://static.visitlondon.com/fl/flash/jp/japan-video-player.swf",
		width: 		'540', 
		height: 	'353',
		play: 		"true",
		wmode: 		"transparent",
		version:	[8,0]
	});	
	
	$("#personaFlash").flashembed({
		src: 		"http://static.visitlondon.com/assets/people/persona-animation/persona-slot.swf",
		width: 		'174', 
		height: 	'131',
		play: 		"true",
		wmode: 		"transparent",
		version:	[8,0]
	});	
	
	$("#head").append("<ul id='headLangList'></ul><img id='headLangPointer' alt='' width='8' height='4' src='http://static.visitlondon.com/images/head/lang-pointer.gif'/>");
	$("#headLangList, #headLangPointer").hide();
	$("#foot ul#lang-list li").clone().appendTo("#headLangList");
	$("#head .flag").toggle( function() {$("#headLangList, #headLangPointer").show();},function() {$("#headLangList, #headLangPointer").hide();});
	$("#headLangList, #headLangPointer").click(function(e) { e.stopPropagation(); });
    $(document).click(function() {$("#headLangList, #headLangPointer").hide();});
		
	if($.browser.msie || $.browser.opera)  {
		$("#sidebar .tools li").append("<i></i>");
		$("#login-reg, .tabs .panel-head").append('<i class="tr"></i><i class="tl"></i>');		
		$("#sidebar fieldset, #acc-res #lpsearch, #sidebar ul.sidenav, #sidebar div.dates div.date").append('<i class="tr"></i><i class="tl"></i><i class="br"></i><i class="bl"></i>');	
		$("#content ul.results div.commerce").append('<b class="tr"></b><b class="tl"></b><b class="br"></b><b class="bl"></b>');
		$("#sidebar .xmas-side-cal div").append('<b class="br"></b><b class="bl"></b>');
	}
	if($.browser.msie)  {
		$('.button').addClass('wrapped').wrap('<span class="button"></span>');
		$('.button.right').removeClass('right').parent('span').addClass('right');
		$('.button.left').removeClass('left').parent('span').addClass('left');
		$('.button.bbook').removeClass('bbook').parent('span').addClass('bbook');
		$('span.button').append('<i class="tl"></i><i class="tr"></i><i class="bl"></i><i class="br"></i>');
		$('#sidebar fieldset span.button').append('<b class="tl"></b><b class="tr"></b><b class="bl"></b><b class="br"></b>');
		if ($.browser.msie && $.browser.version == "6.0") { $('input.button').siblings('i.tr, i.br').addClass('ie6RHS'); }	
	}

	$('#book-offer-tac').hide();
	$("#book-offer-tacLink").click(	function() {$("#book-offer-tac").show().addClass('dynamic');return false;});
	$("#book-offer-tac h3").prepend('<a href="#book-offer-tacLink" id="book-offer-tacClose">close <img src="http://static.visitlondon.com/images/accommodation/close.png" alt="" /></a>');
	$("#book-offer-tacClose").click(function() {$("#book-offer-tac").hide();return false;});

	$("#dynForm").hide().after('<div id="dynLink"><a>Do you want to see the prices and availability for different dates or rooms?</a></div>');
	$("#dynLink a").css('pointer','cursor').toggle(function(){ $("#dynForm").show(); $(this).text('Hide search form');},function() {$("#dynForm").hide(); $(this).text('Do you want to see the prices and availability for different dates or rooms?');});
	
});
