var whichVid;
document.getElementsByClassName = function(cl) {
	var retnode = [], myclass = new RegExp('\\b'+cl+'\\b'), classes;
	var elem = this.getElementsByTagName('*');
	for (var i = 0; i < elem.length; i++) {
		classes = elem[i].className;
		if (myclass.test(classes)) {retnode.push(elem[i]);}
	}
	return retnode;
};

function isNumeric(p) { var pNum = new String(p); var regex = /[^0-9]/; return !regex.test(pNum); }

function so_clearInnerHTML(o) { while(o.firstChild) {o.removeChild(o.firstChild);} }

function removeChildren(node) {
	var child, next;
    for (child = node.firstChild; child !== null; ) {
    	next = child.nextSibling;
        node.removeChild(child);
        child = next;
	}
}

function getHeight(el) {
	var d = el, h = '0px', o;
	if(d) {
		if((o = document.defaultView) && o.getComputedStyle) {
			h = o.getComputedStyle(d, null).height;
		} else if('number' == typeof d.offsetHeight) {
			h = d.offsetHeight + 'px';
		}
	}
	return h;
}


allTubes = ['tubeparent','tubeCentral','tubeN','tubeNe','tubeNw','tubeEast','tubeWest','tubeS','tubeSe','tubeSw'];



function doFade(colorId, targetId) {
    if (colorId >= 1) {
		colorId--;
		for (i = 0; i < document.getElementById(targetId).childNodes.length; i++) {
			if (document.getElementById(targetId).childNodes[i].nodeType == 1) {
				if (location.pathname.indexOf('attractions') != -1) {
					document.getElementById(targetId).childNodes[i].style.backgroundColor = "#" + AttSteps[colorId];
				} else if (location.pathname.indexOf('accommodation') != -1) {
					document.getElementById(targetId).childNodes[i].style.backgroundColor = "#" + AccSteps[colorId];
				} else if (location.pathname.indexOf('events') != -1) {
					document.getElementById(targetId).childNodes[i].style.backgroundColor = "#" + EveSteps[colorId];
				} else if (location.pathname.indexOf('travel') != -1) {
					document.getElementById(targetId).childNodes[i].style.backgroundColor = "#" + TraSteps[colorId];
				} 
				
			}
		}
		if (colorId >= 1) {
			setTimeout("DoFade("+colorId+",'"+targetId+"')", FadeInterval);
		}
	}
}

/* Set Stuff Up */
function setupMultiPanel() {
	var multiPanelsRaw = document.getElementById('selector-window').childNodes;
	
	for (i=0;i<multiPanelsRaw.length;i++) {
		if (multiPanelsRaw[i].nodeName == 'DIV') {
				multiPanels[multiPanels.length] = multiPanelsRaw[i].id;
		}
	}
for (j=0;j<multiPanels.length;j++) {
		document.getElementById(multiPanels[j]).style.display = 'none';
		document.getElementById(multiPanels[j]).style.position = 'absolute';
		document.getElementById(multiPanels[j]).style.top =  "0px";
		document.getElementById(multiPanels[j]).style.left =  "0px";
		var nextList = document.createElement("li"); 
		var nextLink = document.createElement("a"); 
		nextList.appendChild(nextLink);
		nextLink.setAttribute("href", "javascript:multiPanel('"+j+"');");
		nextLink.setAttribute("id", "link"+j);
		
  		nextLink.appendChild(document.createTextNode(j+1));
    	document.getElementById('selector').appendChild(nextList);
		if (j+1 == multiPanels.length) {
			nextLink.className =  "lastLink";
		}
	}
	 multiPanel('0');
}

var hiddenDivs = [];
function setupHidden() {
var allHidden = document.getElementsByClassName("hidden"), i, k, whichHidden;
for (i = 0; i < allHidden.length; i++) {
	whichHidden = allHidden[i].id;
	k = 2 * i;
	hiddenDivs[k] = whichHidden;
	hiddenDivs[k+1] = getHeight(allHidden[i]);
	allHidden[i].style.height = "0px";
	allHidden[i].style.overflow = "hidden";
}
}


var showRev = false;

function setupTabs() {
var allTabs = document.getElementsByClassName("tabcnt"), i, whichTab;
if (allTabs.length > 0) {
if (!showRev) {
	for (i = 1; i < allTabs.length; i++) {
		allTabs[i].style.display = 'none';
	}
	whichTab = allTabs[0].id + "-tab";
	document.getElementById(whichTab).className = "current";
} else {
	for (i = 0; i < allTabs.length; i++) {
		allTabs[i].style.display = 'none';
	}
	document.getElementById('prod-rev').style.display = "block";
	document.getElementById('prod-rev-tab').className = "current";
}
}
}

function setupRollovers() {
var allRolls = document.getElementsByClassName("rollover");
for (var i = 0; i < allRolls.length; i++) {
	if(window.addEventListener)	{ 
		allRolls[i].addEventListener('mouseover', doRollover, false); allRolls[i].addEventListener('mouseout', doRollover, false);
	} else if(window.attachEvent) {
		allRolls[i].attachEvent('onmouseover', doRollover, false); allRolls[i].attachEvent('onmouseout', doRollover, false);
	} 
}
}

function setupLangs() {
	if (document.getElementById('lang-list')) {
		document.getElementById('lang-list').style.display = "none"; /* doing this is less work then querying computed styles */
	}
}

function externalLinks() { 
	var extLink = /^http/;
	var intLink = /^https?\:\/\/[a-z0-9\-]*.?visitlondon\.com/;
	var intLink2 = /^https?\:\/\/[a-z0-9\-]*.?visitlondon\.co\.uk/;
	var wnLink = /^https?\:\/\/[a-z0-9\-]*.?worldnomads\.com/;
	var server = /web[1234]/;
	var fileLink = /\.(pdf|doc)$/;
	if (!document.getElementsByTagName || !document.getElementById("content") || window.location.protocol == 'https:') {return; }
	var anchors = document.getElementById("content").getElementsByTagName("a"), i, anchor; 
	for (i=0; i<anchors.length; i++) { 
		anchor = anchors[i]; 
		if (
			anchor.getAttribute("href") && (
				anchor.className.indexOf('ext') != -1 ||
				fileLink.test(anchor.getAttribute("href")) || (
					extLink.test(anchor.getAttribute("href")) && !intLink.test(anchor.getAttribute("href")) && !intLink2.test(anchor.getAttribute("href")) && !server.test(anchor.getAttribute("href"))  
				)
			)
		) {
	 		if (anchor.className.indexOf('button') == -1 && anchor.className.indexOf('noicon') == -1 && !wnLink.test(anchor.getAttribute("href"))) {  
				var extIcon = document.createElement("img");
				extIcon.setAttribute("alt","");
				extIcon.setAttribute("src","http://static.visitlondon.com/images/icons/external-links.gif");
				anchor.appendChild(extIcon); 
	 		}
			anchor.target = "_blank";
			anchor.title += "\nLink will open in a new window" ;
		}
	} 
	if (!document.getElementsByTagName || !document.getElementById("sidebar")) { return; } 
	var anchors2 = document.getElementById("sidebar").getElementsByTagName("a"); 
	for (i=0; i<anchors2.length; i++) { 
		anchor = anchors2[i]; 
		if (
			anchor.getAttribute("href") && (
				anchor.className.indexOf('ext') != -1 ||
				fileLink.test(anchor.getAttribute("href")) || (
					extLink.test(anchor.getAttribute("href")) && !intLink.test(anchor.getAttribute("href")) && !intLink2.test(anchor.getAttribute("href")) && !server.test(anchor.getAttribute("href"))  
				)
			)
		) {
			anchor.target = "_blank";
			anchor.title += "\nLink will open in a new window" ;
		}
	} 
}

var navTimer;
function topmenuHover() {
	if(document.getElementById("topmenu")) {
		navRoot = document.getElementById("topmenu");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					clearTimeout(navTimer); topmenuClear();
					this.className+=" over";
					this.childNodes[0].className="over"; 
				};
				node.onmouseout=function() {
					navTimer = setTimeout(topmenuClear,2000);
				};
			}
		}
	}
}

function topmenuClear() {
	navRoot = document.getElementById("topmenu");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.className=node.className.replace("over", "");
				node.childNodes[0].className="";
			}
		}
}

/* Search */
function getMaxDay(selectedMonth) {
	if (selectedMonth == 'Feb') { if (leapYear(selectedYear) ) {maxDay = 29;} else {maxDay = 28;} }  
  	else { if  (selectedMonth == 'Apr' || selectedMonth == 'Jun' || selectedMonth == 'Sep' || selectedMonth == 'Nov') { maxDay = 30;} else { maxDay = 31; } }
  return maxDay;
}
function getMinDay(selectedMonth) {
	if (selectedMonth == currentMonth && selectedYear == currentYear) { minDay = currentDay; }
	else { minDay = 1; }
	return minDay;
}


/* Load Stuff */
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    };
  }
}

function inita() {
	if (arguments.callee.done) {return;}
	arguments.callee.done = true;
	if (_timer) {clearInterval(_timer);}
setupLangs();
setupTabs();
setupHidden();
externalLinks();
setupRollovers();
//	if (BrowserDetect.browser == "Explorer" && BrowserDetect.version < 7) {
		topmenuHover(); /* AJ - IE6 hover fix */
//	}
	if (whichVid && whichVid !== ""){
	detectFlash();
	vidUrl = "#" + whichVid + ".xml";
	drawTV("video", vidUrl);	
	}
}

/* for Mozilla/Opera9 */
if (document.addEventListener) {
	document.addEventListener("DOMContentLoaded", inita, false);
}

/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
	document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
	var script = document.getElementById("__ie_onload");
	script.onreadystatechange = function() {
		if (this.readyState == "complete") {
			inita(); // call the onload handler
		}
	};
@else @*/
/*@end @*/

/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
	var _timer = setInterval(function() {
		if (/loaded|complete/.test(document.readyState)) {
			inita(); // call the onload handler
		}
	}, 10);
}

/* for other browsers */
window.onload = inita;