﻿var ie = 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") {
            init(); // call the onload handler
        }
    };
		ie = true ;
/*@end @*/

if (!ie) {
	/* for Mozilla/Opera9 */
	if (document.addEventListener) {
			document.addEventListener("DOMContentLoaded", init, false);
	
	/* for Safari */
	} else if	 (/WebKit/i.test(navigator.userAgent)) { // sniff
			var _timer = setInterval(function() {
					if (/loaded|complete/.test(document.readyState)) {
							init(); // call the onload handler
					}
			}, 10)
	
	/* for other browsers */
	} else {
		window.onload = init;
	}
}

/* Golbal scoped vars */
var menu ;
var map ;

/* dom loaded call */
function init() {

/* object detection */
	if (!document.getElementsByTagName) return true ;
   
/* Clear inputs */
  inputs = document.getElementsByTagName('input') ;
  for (i = 0; i < inputs.length; i++) {
    if (inputs[i].getAttribute('value')) {
      inputs[i].onfocus = function() {
				if (! this.getAttribute) return true ;
				if ((this.value == this.getAttribute('value')) && (this.getAttribute('type') != 'submit')) {
					this.value = '' ;
				}
			}
    }
  }
	
/* External Links */
	var links = document.getElementsByTagName('a') ;
	for (var i=0; i<links.length; i++) {
		var link = links[i] ;
		var addy = link.href ;
		if (addy.indexOf(window.location.hostname) == -1) {
			if (link.className == "") {
				link.className = 'externalLink' ;
			} else {
				link.className = link.className + ' externalLink' ;
			}
			if (link.title == "") {
				link.title = '(External link - opens a new window)' ;
			} else {
				link.title = link.title + ' (External link - New window)' ;
			}
			link.onclick = function(e) {
				if (!e) e = window.event ;
				if (e.shiftKey || e.ctrlKey || e.altKey) return ;
				window.open(this.href) ;
				return false ;
			}
		}
	}
	
/* Init Open Studio detail functions */
	if (document.getElementById('showMap')) {
		var mapBtn = document.getElementById('showMap') ;
		mapBtn.style.display = 'inline' ;
		map = getElementsByClass('map', null, 'a')[0] ;
		if (map != '') map.style.display = 'none' ;
		mapBtn.onclick = function() {
			map.style.display = (map.style.display != 'block' ? 'block' : 'none')
			return false;
		}
	}
	
/* Open studio no script buttons */
	var noScriptBtn = getElementsByClass('noScriptBtn', null, 'input') ;
	if (noScriptBtn != '') {
		for (i=0; i < noScriptBtn.length; i++) {
			noScriptBtn[i].style.display = 'none' ;
		}
	}
	
/* Details venue pop up
	var venueLink = getElementsByClass('venueLink', null, 'a') ;
	if (venueLink != '') {
			venueLink[0].onclick = function() {
				window.open (this.href, 'mapwindow','width=440,height=480');
				return false;
			}
	} */
/* Other Events at venue link
	var otherLink = getElementsByClass('otherEvents', null, 'a') ;
	if (otherLink != '') {
		otherLink[0].onclick = function() {
			window.opener.document.location.href = this.href;window.close()	;
			return false;
		}
	} */
	
/* Initilise Menu for our special friend ie6 */
	if (typeof document.body.style.maxHeight == "undefined") { /* sniffs ie6 and below */
		if (!document.createElement) return true ;
		if (!document.insertBefore) return true ;
		if (!document.removeChild) return true ;	
		if (! window.attachEvent) return true ;		
		/* Find object */
		var menuWrap = getElementsByClass('ieMenu', null, 'li') ;
		if (menuWrap != '') {
			/* remove ieMenu class for noscript users */
			menuWrap[0].className = 'menu' ;
			/* add event handlers */
			menuWrap[0].onmouseover = toggleMenu ;
			menuWrap[0].onmouseout = toggleMenu ;
			 			
		}
	}
}


/* menu */
function toggleMenu() {
	menu = this.getElementsByTagName('ul')[0] ;
	menu.style.left = (parseInt(menu.style.left) != '0' ? '0' : '-8888px')
	appendIframe(menu)
}

function appendIframe(o) {
	var parent = o.parentNode ;
	
	if (!document.getElementById('ieMat')) {
		var ieMat=document.createElement('iframe') ;
		if(document.location.protocol == "https:") {
			ieMat.src="//0";
		} else if(window.opera != "undefined") {
			ieMat.src="";
		} else {
			ieMat.src="about:blank";
		}
		ieMat.scrolling="no";
		ieMat.frameBorder="0";
		ieMat.style.width=o.offsetWidth+"px";
		ieMat.style.height=o.offsetHeight+"px";
		ieMat.style.zIndex="-1";
		ieMat.style.position = 'absolute' ;
		ieMat.style.left = '0' ;
		ieMat.style.top = '0' ;
		ieMat.id = 'ieMat' ;
		parent.insertBefore(ieMat, o);
		o.style.zIndex="101";
	} else {
		parent.removeChild(document.getElementById('ieMat')) ;
	}
}	


/* common methods */
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}
function getChild(startParent) {
  EndChild = startParent.firstChild ;
  while(EndChild.nodeType != 1){
    EndChild = EndChild.nextSibling ;
  }
  return EndChild;
}