/* ################ Global variables ################  */
var  whichVid, tl, navTimer, WT = {}, DCS = {};
/* ################ End Global variables ################  */

/* ################  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, remove output of <embed> element
 * 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(); }
			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 k in params) {
				if (params[k] !== null) {
					html += '\n\t<param name="'+ k +'" value="'+ params[k] +'" />';
				}
			}
			if (flashvars) {
				html += '\n\t<param name="flashvars" value="' + concatVars(flashvars) + '" />';
			}
			html += "</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 videoMultiTrackWrapper(trackPath,trackTitle,trackEvent) {
	WT.ti=WT.cg_n=WT.cg_s=WT.mc_id=WT.si_n=WT.si_p=WT.z_vlSupplier=""; // null all values we don't use
	dcsMultiTrack("DCS.dcsuri",trackPath,"WT.z_ltvName","Video: "+trackTitle,trackEvent,"1");
	DCS.dcsuri=WT.z_ltvName=WT.z_ltvView=WT.z_ltvPlay=WT.z_ltvFinished=""; // null all values we do use
}
function drawTV() {
if(whichVid && whichVid !== "" && $("#video").size !== 0) {
var w, h, xml = whichVid + ".xml";
	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=green",
		width: 		w, 
		height: 	h,
		play: 		"true",
		wmode: 		"transparent",
		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="" />read the transcript</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=550, 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)');
		}
	}
}
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)');
		}
	}
}
/* ################ End Flash ################ */


/* ################  External 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").attr({title: 'Link will open in a new window', target: '_blank'});
	$("#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']").add(".slots a.ext, .slots a[href$='mp3'], .slots a[href$='pdf'], .slots a[href$='doc']").not(".button").not(".gallery").not(".noicon").append("<img src='http://static.visitlondon.com/partners2/images/external-links.gif' alt='' width='16' height='11' />");
}
/* ################  End External Links  ################ */

/* ################ Top Nav ################ */
function topmenuClear() {
	$("#topmenu *").removeClass("over");
	$("#topmenu .current").removeClass("fade");
}
/* ################ End Top Nav ################ */

/* ################ Date Picker  ################ */
// Prepare to show a date picker linked to three select controls 
function readLinkedFrom() { 
    $('#fromDate').val($('#fromMonth').val() + '/' + $('#fromDay').val() + '/' + $('#fromYear').val()); 
    return {}; 
} 
 function readLinkedTo() { 
    $('#toDate').val($('#toMonth').val() + '/' + $('#toDay').val() + '/' + $('#toYear').val()); 
    return {}; 
} 
// Update three select controls to match a date picker selection 
function updateLinkedFrom(date) { 
    $('#fromMonth').val(date.substring(0, 2)); 
    $('#fromDay').val(date.substring(3, 5)); 
    $('#fromYear').val(date.substring(6, 10)); 
} 
function updateLinkedTo(date) { 
    $('#toMonth').val(date.substring(0, 2)); 
    $('#toDay').val(date.substring(3, 5)); 
    $('#toYear').val(date.substring(6, 10)); 
}  
// Prevent selection of invalid dates through the select controls 
function checkLinkedDaysFrom() { 
    var daysInMonth = 32 - new Date($('#fromYear').val(), 
    $('#fromMonth').val() - 1, 32).getDate(); 
   	$('#fromDay option').attr('disabled', ''); 
    $('#fromDay option:gt(' + (daysInMonth - 1) +')').attr('disabled', 'disabled'); 
    if ($('#fromDay').val() > daysInMonth) { 
        $('#fromDay').val(daysInMonth); 
    } 
} 
function checkLinkedDaysTo() { 
    var daysInMonth = 32 - new Date($('#toYear').val(), 
    $('#toMonth').val() - 1, 32).getDate(); 
   	$('#toDay option').attr('disabled', ''); 
    $('#toDay option:gt(' + (daysInMonth - 1) +')').attr('disabled', 'disabled'); 
    if ($('#toDay').val() > daysInMonth) { 
        $('#toDay').val(daysInMonth); 
    } 
} 
/* ################ End Date Picker  ################ */

function randomHpTile() {
	if ($("#hp-tile img").size !== 0) {
		var randomTile = Math.floor(Math.random() * 4);
		switch (randomTile) {
			case 0: 
				$("#hp-tile img").attr('src','http://static.visitlondon.com/partners2/assets/promos/hp-london-quest.jpg').attr('alt','&quot;Visit London are focused on drawing business to the capital, and have a team with the skills to do it&quot; - Andrew Pawlby, Managing Director, London Quest').wrap('<a href="/partner_benefits/case_studies/london-quest-case-study"></a>');
				break;
			case 1: 
				$("#hp-tile img").attr('src','http://static.visitlondon.com/partners2/assets/promos/hp-vinopolis.jpg').attr('alt','&quot;Partnership with Visit London has increased our leads and helped us access new markets&quot; - Rupert Edwards, Managing Director, Vinopolis').wrap('<a href="/partner_benefits/case_studies/vinopolis-case-study"></a>');
				break;
			case 2: 
				$("#hp-tile img").attr('src','http://static.visitlondon.com/partners2/assets/promos/hp-aka.jpg').attr('alt','&quot;Partnership has given us new marketing and promotional channels into our target market&quot; - Charlotte French, Head of Marketing, AKA').wrap('<a href="/partner_benefits/case_studies/aka-case-study"></a>');
				break;
			case 3:
				$("#hp-tile img").attr('src','http://static.visitlondon.com/partners2/assets/promos/hp-lords.jpg').attr('alt','&quot;Partnership has provided us with new opportunities to increase our non-match day business&quot; - Simon Swift, Assistant Secretary, MCC').wrap('<a href="/partner_benefits/case_studies/lord-case-study "></a>');
				break;
		}
	}
}

/* ################ Loader ################ */
 $(document).ready(function(){
 	if($.browser.msie)  {$("body").addClass('isIE');}
	if($.browser.opera)  {$("body").addClass('isOp');}
	if($.browser.safari)  {$("body").addClass('isWk');}
	externalLinks();
	randomHpTile();
	drawTV();
	$("#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.')); }	
	);
	if($.browser.msie || $.browser.opera)  {
		$('.button-rounded').addClass('wrapped').wrap('<span class="button-rounded"></span>');
		$('.button-rounded.right').removeClass('right').parent('span').addClass('right');
		$('.button-rounded.left').removeClass('left').parent('span').addClass('left');
		$('span.button-rounded').append('<i class="tl"></i><i class="tr"></i><i class="bl"></i><i class="br"></i>');
		if ($.browser.msie && $.browser.version == "6.0") {
			$('input.button-rounded').siblings('i.tr, i.br').addClass('ie6RHS');
		}
		if ($.browser.opera) {
			$('input.button-rounded').addClass('opPad');
			$('span.button-rounded').each( function() {
				if($(this).css('float') == 'none') {
					$(this).children('i.tr, i.br').addClass('opNoFlo');
				};
			});
		};
	};
	$("#otabl").click(function() { $(".bus-only").hide(); $(".bus-only label").hide(); $(".bus-only input").attr('disabled', 'disabled'); $("#otabl").addClass('tabOn'); $("#otabb").removeClass('tabOn'); });
	$("#otabb").click(function() { $(".bus-only").show(); $(".bus-only label").show(); $(".bus-only input").removeAttr('disabled'); $("#otabb").addClass('tabOn'); $("#otabl").removeClass('tabOn'); });
	$(".bus-only").hide(); $(".bus-only label").hide(); $(".bus-only input").attr('disabled', 'disabled'); $("#type-b, #type-l").css('display','none'); $("#otabl").addClass('tabOn');
	$("form.dcform input, form.dcform textarea, form.dcform select").focus(function() { $(this).parents("fieldset").addClass('focus');});
	$("form.dcform input, form.dcform textarea, form.dcform select").blur(function() { $(this).parents("fieldset").removeClass('focus');});
	
	
	$("#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();});
	$("#foot ul#lang-list").remove();	
		
	if($.browser.msie || $.browser.opera)  {
		$("#login-reg, .tabs .panel-head").append('<i class="tr"></i><i class="tl"></i>');				
	}	
	
	$(".homepage .secondary .AutoIndexSlot:first").addClass('first');
	
	
});
