function LAEvents() {
	$('ul.LAevents').hide();
	$('p.LAevents').hide();
	$('h4.LAevents').css('cursor', 'pointer');
	$('h4.LAevents').css('text-decoration', 'underline');
	$('h4.LAevents').css('background-image', 'url(/images/nav/downIndicator.jpg)');
	$('h4.LAevents').css('background-repeat', 'no-repeat');
	$('h4.LAevents').css('background-position', '5px');
	$('h4.LAevents').click(function () {
		if($(this).next().is(':visible')) {
			$('ul.LAevents:visible').hide('slow');
			$('p.LAevents:visible').hide('slow');
			$('ul.LAevents').css('margin-top', '18px');
		} else {
			$('ul.LAevents:visible').hide('slow');
			$('p.LAevents:visible').hide('slow');
			$(this).next().show('slow');
			$(this).next().next().show('slow');
		}
	});
}
if(window.addEventListener) window.addEventListener ("load",LAEvents,false);
else if(window.attachEvent) window.attachEvent ("onload",LAEvents);
else window.onload = runFirst;


function laSections() {
    if(document.getElementById('subSectionLinks')) {
		var subSectionLinks = document.getElementById('subSectionLinks');
		var anchors = subSectionLinks.getElementsByTagName('a');
		var anchorsLength = anchors.length;
		for(var i=0; i<anchorsLength; i++) {
			var aLink = anchors[i].href;
			anchorText = anchors[i].innerText;
			if(aLink.indexOf('schoolsandteachers.aspx') != -1) {
				var newImg = document.createElement('img');
				newImg.src = 'images/2009/la/sectionLinkSchools-1.jpg';
			} else if(aLink.indexOf('talksandevents.aspx') != -1) {
				var newImg = document.createElement('img');
				newImg.src = 'images/2009/la/sectionLinkTalks-1.jpg';
			} else if(aLink.indexOf('classesandcourses.aspx') != -1) {
				var newImg = document.createElement('img');
				newImg.src = 'images/2009/la/sectionLinkClasses-1.jpg';
			} else if(aLink.indexOf('communityoutreach.aspx') != -1) {
				var newImg = document.createElement('img');
				newImg.src = 'images/2009/la/sectionLinkCommunity-1.jpg';
			} else if(aLink.indexOf('learningandaccesscontacts.aspx') != -1) {
				var newImg2 = document.createElement('img');
				newImg2.src = 'images/2009/la/sectionLinkStaff-1.jpg';
				newImg2.className = 'flip';
				newImg2.width = '200';
				newImg2.height = '84';
				newImg2.alt = anchorText;
				anchors[i].innerText = '';
				anchors[i].appendChild(newImg2);
				newImg = false;
			} else {
				newImg = false;
			}
			
			if(newImg) {
				anchors[i].innerText = '';
				newImg.className = 'flip';
				newImg.width = '200';
				newImg.height = '125';
				newImg.alt = anchorText;
				anchors[i].appendChild(newImg);
			}
		}
	}
}
if(window.addEventListener) window.addEventListener ("load",laSections,false);
else if(window.attachEvent) window.attachEvent ("onload",laSections);
else window.onload = runFirst;


function clickUrl() {
	// NB: gi modifier for 'G'lobal & case-'I'nsensitive
	// Get the Embedded URLs
	var regexpUrl = /((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi;
	// Get the @Users
	var regexpUser = /([@]+[A-Za-z0-9-_]+)/gi;
	// Get the Hash_Tags
	var regexpHash = /([#]+[A-Za-z0-9-_]+)/gi;
	$('#twitterContent li.headline').each(function() {
		$(this).html(
			// Make all embedded URIs clickable
			$(this).html().replace(regexpUrl, "<a href='$1' rel='external'>$1</a>")
		);
		$(this).html(
			// Link all @Users
			$(this).html().replace(regexpUser, "<a href='http://twitter.com/@@$1' rel='external' target='_blank'>@$1</a>")
		);
		$(this).html(
			// Link all #Hash_Tags
			$(this).html().replace(regexpHash, "<a href='http://search.twitter.com/search?q=#$1' rel='external' target='_blank'>$1</a>")
		);
		$(this).html(
			// Make all #Hash_Tags links websafe (replace # with %23)
			$(this).html().replace(/##/gi, '%23')
		);
		$(this).html(
			// Remove @ from href on linkable @Users
			$(this).html().replace(/@@@/gi, '')
		);
		$(this).html(
			// Make sure all @Users have @ sign before their name
			$(this).html().replace(/@@/gi, '@')
		);
	});
	return $('#twitterContent');
}

function get_twitter_feed() {
	if(document.getElementById('twitterContent')) {
	 
		//use the JQuery get to grab the URL from the selected item, put the results in to an argument for parsing in the inline function called when the feed retrieval is complete
	    $.get('/blogXML.php?id=twitter', function(d) {
	        var thisCounter = 0;
	        //find each 'item' in the file and parse it
	        $("#twitterContent").empty();
	        $(d).find('item').each(function() {

	            //name the current found item this for this particular loop run
	            var $item = $(this);
	            // grab the post title
	            var title = $item.find('title').text();
	            title = title.replace('NBTlive: ', '');
	            //don't forget the pubdate
	            var pubDate = $item.find('pubDate').text();

	            var guid = $item.find('guid').text();
	            guid = guid.split('/', guid);
	            guid = guid[guid.length - 1];

	            // now create a var 'html' to store the markup we're using to output the feed to the browser window
	            var html = "<li style='clear: both;'><ul><li class='twitterIcon'><img src='images/2009/icons/twitter50.jpg' width='50' height='50' alt='' /></li><li class='headline'>" + title + "</li>";
	            html += "<li class='date'>" + pubDate.substr(0, 22) + "</li>";

	            if (thisCounter == 0) {
	                //clear the content in the div for the next feed.
	            }
	            thisCounter++;
	            //put that feed content on the screen!
	            $('#twitterContent').append($(html));
	            $('#twitterContent').css('background-image', 'none');
	        });
	        clickUrl();
	    });
	}
};
if(window.addEventListener) window.addEventListener ("load",get_twitter_feed,false);
else if(window.attachEvent) window.attachEvent ("onload",get_twitter_feed);
else window.onload = runFirst;

function get_rss_feed() {
	if(document.getElementById('feedContent')) {
		var whichBlog = 'blog';
		
		if($('#feedContent').hasClass('academy')) {
			whichBlog = 'academy';
		} else if($('#feedContent').hasClass('la')) {
			whichBlog = 'la';
		} else if($('#feedContent').hasClass('easter')) {
			whichBlog = 'easter';
		} else {
		    // Use Default
		}
		
		if($('#feedContent').hasClass('shorten')) var shorten = true;
		else var shorten = false;
		
		var blogUri = '/blogXML.php?id='+whichBlog;
	 
		//use the JQuery get to grab the URL from the selected item, put the results in to an argument for parsing in the inline function called when the feed retrieval is complete
		$.get(blogUri, function(d) {
		    //var thisCounter = 0;
		    var thisCounter = 0;
		    $('#feedContent').empty();
		    //find each 'item' in the file and parse it
		    $(d).find('item').each(function() {

		        //name the current found item this for this particular loop run
		        var $item = $(this);
		        // grab the post title
		        var title = $item.find('title').text();
		        // grab the post's URL
		        var link = $item.find('link').text();
		        // next, the description
		        //var description = $item.find('description').text();
		        if (whichBlog == 'blog') {
		            var description = $item.find('content\\:encoded').text();
		            if (description == '') description = $item.find('description').text();
		        } else {
		            var description = $item.find('description').text();
		        }
		        //don't forget the pubdate
		        var pubDate = $item.find('pubDate').text();

		        if (title.indexOf('northernballet') != -1) {
		            title = title.split('northernballet');
		            title = title[0];
		        }
		        if (thisCounter == 0) {
		            //clear the content in the div for the next feed.
		        }
		        thisCounter++;

		        if (shorten) {
		            var html = "<li><a href='" + link + "' rel='external' target='_blank'>" + title + "</a> <span class='date'>[" + pubDate.substr(0, 16) + "]</span></li>";
		        } else {
		            // now create a var 'html' to store the markup we're using to output the feed to the browser window
		            var html = "<li><ul><li class='headline'><a href='" + link + "' rel='external' target='_blank'>" + title + "</a></li>";
		            html += "<li class='date'>" + pubDate.substr(0, 16).replace(' ', '&nbsp;') + "</li>";
		            html += "<li class='firstParagraph'>" + description + "</li>";
		            html += "<li class='newsLink'><a href='" + link + "' rel='external' target='_blank'>Read Full Article...</a></li></ul></li>";
		        }
		        //put that feed content on the screen!
		        $('#feedContent').append($(html));

		    });
		    $('#feedContent').css('background-image', 'none');
		    var html = "<a href='http://northernballettheatre.wordpress.com/category/northern-ballet-theatre-academy/' title='Northern Ballet Theatre Academy Blog' class='blogFooter' target='_blank'><img src='images/2009/blog/blogFooter.jpg' width='204' height='36' alt='blog' /></a>";
		    $('.sideBlogFeed').append(html);
		});
	}
};
if(window.addEventListener) window.addEventListener ("load",get_rss_feed,false);
else if(window.attachEvent) window.attachEvent ("onload",get_rss_feed);
else window.onload = runFirst;

function ajax() {
	var goAhead = true;
	var xmlHttp;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	} catch (e) {
		// Internet Explorer
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				goAhead = false;
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	return xmlHttp;
}
function sortNumber(a,b) {
	return a - b;
}
function addBooking() {
	var months = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
	if(document.getElementById('bookingInfo')) {
		var bookingInfo = document.getElementById('bookingInfo');
		var xmlHttp = ajax();
		
		xmlHttp.onreadystatechange = function() {
			if(xmlHttp.readyState == 4) {
				var currDate = new Date();
				var thisMonth = currDate.getMonth();
				thisMonth++;
				if(thisMonth < 10) thisMonth = '0'+thisMonth;
				var thisDay = currDate.getDate();
				if(thisDay < 10) thisDay = '0'+thisDay;
				var parseDate = currDate.getFullYear() + thisMonth + thisDay;
				
				var newUL = document.createElement('ul');
				
				if(xmlHttp.responseXML.documentElement) {
					var returnedText = xmlHttp.responseXML.documentElement;
					alert("!");
				} else {
					var returnedText = xmlHttp.responseXML;
				}
				
				var events = returnedText.getElementsByTagName('event');
				var eventsLen = events.length;
				var venue = returnedText.getElementsByTagName('venue')[0];
				
				var Names = returnedText.getElementsByTagName('name')[1].firstChild.data;
				alert(Names);
				
				bookingInfo.appendChild(newUL);
				/*var eventsLength = events.length;
				alert(eventsLength);
				for(var i=0; i<eventsLength; i++) {
					var productions = events[i].getElementsByTagName('production');
					var prodLen = productions.length;
					for(var j=0; j<prodLen; j++) {
						var names = productions[j].getElementsByTagName('name');
						var prodName = document.createTextNode(names[0].firstChild.data);
						var url = productions[j].getElementsByTagName('url');
						var urlAddress = url[0].firstChild.data;
					}
					var newA = document.createElement('a');
					newA.href = urlAddress;
					newA.appendChild(prodName);
					var newP = document.createElement('p');
					newP.appendChild(newA);
					bookingInfo.appendChild(newP);
				}*/
			}
		}
		xmlHttp.open("GET","shows.xml",true);
		xmlHttp.send(null);
	}
}
if(window.addEventListener) window.addEventListener ("load",addBooking,false);
else if(window.attachEvent) window.attachEvent ("onload",addBooking);
else window.onload = runFirst;

function h1Replace() {
	var h1Ele = document.getElementsByTagName('h1');
	var h1EleLen = h1Ele.length;
	for(var i=0; i<h1EleLen; i++) {
		if(h1Ele[i].className.indexOf('replace') != -1) {
			eleInText = h1Ele[i].innerHTML;
			if(eleInText == 'Swan Lake') {
				h1Ele[i].innerHTML = '';
				var newH1 = new Image();
				newH1.src = 'images/swanlake/swanlake.jpg';
				newH1.width = '323';
				newH1.height = '55';
				newH1.alt = eleInText;
				var newImgOnPage = document.createElement('img');
				newImgOnPage.src = newH1.src;
				h1Ele[i].appendChild(newImgOnPage);
			} else if(eleInText == 'Wuthering Heights') {
				h1Ele[i].innerHTML = '';
				var newH1 = new Image();
				newH1.src = 'images/whlogo.jpg';
				newH1.width = '200';
				newH1.height = '66';
				newH1.alt = eleInText;
				var newImgOnPage = document.createElement('img');
				newImgOnPage.src = newH1.src;
				h1Ele[i].appendChild(newImgOnPage);
			} else if(eleInText == 'Romeo &amp; Juliet') {
				h1Ele[i].innerHTML = '';
				var newH1 = new Image();
				newH1.src = 'images/rjwidelogo.jpg';
				newH1.width = '350';
				newH1.height = '38';
				newH1.alt = eleInText;
				var newImgOnPage = document.createElement('img');
				newImgOnPage.src = newH1.src;
				h1Ele[i].appendChild(newImgOnPage);
			} else if(eleInText == 'Dracula') {
				h1Ele[i].innerHTML = '';
				var newH1 = new Image();
				newH1.src = 'images/2009/drac/draculah1.jpg';
				newH1.width = '375';
				newH1.height = '164';
				newH1.alt = eleInText;
				var newImgOnPage = document.createElement('img');
				newImgOnPage.src = newH1.src;
				h1Ele[i].appendChild(newImgOnPage);
			} else if(eleInText == 'A Christmas Carol') {
				h1Ele[i].innerHTML = '';
				h1Ele[i].style.textAlign = 'center';
				var newH1 = new Image();
				newH1.src = 'images/2009/christcarol/h1.jpg';
				newH1.width = '350';
				newH1.height = '199';
				newH1.alt = eleInText;
				var newImgOnPage = document.createElement('img');
				newImgOnPage.src = newH1.src;
				h1Ele[i].appendChild(newImgOnPage);
            } else if (eleInText == 'Peter Pan') {
                h1Ele[i].innerHTML = '';
                h1Ele[i].style.textAlign = 'center';
                var newH1 = new Image();
                newH1.src = 'images/2009/pan/h1.jpg';
                newH1.width = '425';
                newH1.height = '141';
                newH1.alt = eleInText;
                var newImgOnPage = document.createElement('img');
                newImgOnPage.src = newH1.src;
                h1Ele[i].appendChild(newImgOnPage);
            } else if (eleInText == 'I Got Rhythm') {
                h1Ele[i].innerHTML = '';
                h1Ele[i].style.textAlign = 'center';
                var newH1 = new Image();
                newH1.src = 'images/2009/igrLogo.jpg';
                newH1.width = '420';
                newH1.height = '220';
                newH1.alt = eleInText;
                var newImgOnPage = document.createElement('img');
                newImgOnPage.src = newH1.src;
                h1Ele[i].appendChild(newImgOnPage);
            } else if (eleInText == 'A Midsummer Night\'s Dream') {
                h1Ele[i].innerHTML = '';
                h1Ele[i].style.textAlign = 'center';
                var newH1 = new Image();
                newH1.src = 'images/2009/amndLogo.jpg';
                newH1.width = '420';
                newH1.height = '189';
                newH1.alt = eleInText;
                var newImgOnPage = document.createElement('img');
                newImgOnPage.src = newH1.src;
                h1Ele[i].appendChild(newImgOnPage);
            } else if (eleInText == 'The Three Musketeers') {
                h1Ele[i].innerHTML = '';
                h1Ele[i].style.textAlign = 'center';
                var newH1 = new Image();
                newH1.src = 'images/2009/3mLogo.jpg';
                newH1.width = '420';
                newH1.height = '184';
                newH1.alt = eleInText;
                var newImgOnPage = document.createElement('img');
                newImgOnPage.src = newH1.src;
                h1Ele[i].appendChild(newImgOnPage);
            } else if (eleInText == 'Requiem') {
                h1Ele[i].innerHTML = '';
                h1Ele[i].style.textAlign = 'center';
                var newH1 = new Image();
                newH1.src = 'images/2009/requiem/requiemLogo.jpg';
                newH1.width = '420';
                newH1.height = '143';
                newH1.alt = eleInText;
                var newImgOnPage = document.createElement('img');
                newImgOnPage.src = newH1.src;
                h1Ele[i].appendChild(newImgOnPage);
            } else if (eleInText == 'Carmen') {
                h1Ele[i].innerHTML = '';
                h1Ele[i].style.textAlign = 'left';
                var newH1 = new Image();
                newH1.src = 'images/2009/carmen/carmenLogo.jpg';
                newH1.width = '200';
                newH1.height = '105';
                newH1.alt = eleInText;
                var newImgOnPage = document.createElement('img');
                newImgOnPage.src = newH1.src;
                h1Ele[i].appendChild(newImgOnPage);
            } else if (eleInText == 'Hamlet') {
                h1Ele[i].innerHTML = '';
                h1Ele[i].style.textAlign = 'center';
                var newH1 = new Image();
                newH1.src = 'images/2009/hamlet/hamletLogo.jpg';
                newH1.width = '420';
                newH1.height = '152';
                newH1.alt = eleInText;
                var newImgOnPage = document.createElement('img');
                newImgOnPage.src = newH1.src;
                h1Ele[i].appendChild(newImgOnPage);
            } else if (eleInText == 'Dangerous Liasons') {
                h1Ele[i].innerHTML = '';
                h1Ele[i].style.textAlign = 'center';
                var newH1 = new Image();
                newH1.src = 'images/2009/dl/liasonsLogo.jpg';
                newH1.width = '420';
                newH1.height = '101';
                newH1.alt = eleInText;
                var newImgOnPage = document.createElement('img');
                newImgOnPage.src = newH1.src;
                h1Ele[i].appendChild(newImgOnPage);
            } else if (eleInText == 'A Sleeping Beauty Tale') {
                h1Ele[i].innerHTML = '';
                h1Ele[i].style.textAlign = 'center';
                var newH1 = new Image();
                newH1.src = 'images/2009/asbt/asbtLogo.jpg';
                newH1.width = '420';
                newH1.height = '155';
                newH1.alt = eleInText;
                var newImgOnPage = document.createElement('img');
                newImgOnPage.src = newH1.src;
                h1Ele[i].appendChild(newImgOnPage);
            } else if (eleInText == 'The Nutcracker') {
                h1Ele[i].innerHTML = '';
                h1Ele[i].style.textAlign = 'center';
                var newH1 = new Image();
                newH1.src = 'images/2009/nut/nutLogo.jpg';
                newH1.width = '420';
                newH1.height = '85';
                newH1.alt = eleInText;
                var newImgOnPage = document.createElement('img');
                newImgOnPage.src = newH1.src;
                h1Ele[i].appendChild(newImgOnPage);
            } else if (eleInText == 'La Traviata') {
                h1Ele[i].innerHTML = '';
                h1Ele[i].style.textAlign = 'center';
                var newH1 = new Image();
                newH1.src = 'images/2009/latrav/homeLogo.jpg';
                newH1.width = '420';
                newH1.height = '192';
                newH1.alt = eleInText;
                var newImgOnPage = document.createElement('img');
                newImgOnPage.src = newH1.src;
                h1Ele[i].appendChild(newImgOnPage);
            } else if (eleInText == 'A Tale Of Two Cities') {
                h1Ele[i].innerHTML = '';
                h1Ele[i].style.textAlign = 'center';
                var newH1 = new Image();
                newH1.src = 'images/2009/atotc/homeLogo.jpg';
                newH1.width = '420';
                newH1.height = '106';
                newH1.alt = eleInText;
                var newImgOnPage = document.createElement('img');
                newImgOnPage.src = newH1.src;
                h1Ele[i].appendChild(newImgOnPage);
            } else if (eleInText == 'Learning and Access') {
                h1Ele[i].innerHTML = '';
                h1Ele[i].style.textAlign = 'center';
                var newH1 = new Image();
                newH1.src = 'images/2009/la/laBanner.jpg';
                newH1.width = '724';
                newH1.height = '200';
                newH1.alt = eleInText;
                var newImgOnPage = document.createElement('img');
                newImgOnPage.src = newH1.src;
                h1Ele[i].appendChild(newImgOnPage);
            }
			
		}
	}
}
if(window.addEventListener) window.addEventListener ("load",h1Replace,false);
else if(window.attachEvent) window.attachEvent ("onload",h1Replace);
else window.onload = runFirst;


function removeSection() {
    if (document.getElementById('removeOnDate')) {
        var removable = document.getElementById('removeOnDate');
        var liToRemovable = document.getElementById('liRemovable');
        var thisDate = new Date();

        var thisDay = thisDate.getDate();
        var thisMonth = thisDate.getMonth();
        var thisYear = thisDate.getYear();
        if (thisYear < 1000) thisYear = thisYear - 100 + 2000;

        if (thisYear > 2009 || (thisYear == 2009 && thisMonth > 5) || (thisYear == 2009 && thisMonth == 5 && thisDay > 27)) {
            removable.style.display = 'none';
            liToRemovable.style.display = 'none';
        }
    }
}
if (window.addEventListener) window.addEventListener("load", removeSection, false);
else if (window.attachEvent) window.attachEvent("onload", removeSection);
else window.onload = runFirst;


function imageFlipper() {
	var flipClass = 'flip';
	var allImgs = document.getElementsByTagName('img');
	var allImgTotal = allImgs.length;
	for(var i=0;i<allImgTotal;i++) {
		if(allImgs[i].className.indexOf(flipClass) != -1) {
			var newPic = new Image();
			var firstPicSrc = allImgs[i].src;
			var newPicSrc = firstPicSrc.replace('-1', '-2');
			newPic.src = newPicSrc;
			allImgs[i]['onmouseover'] = new Function('this.src="'+newPicSrc+'";');
			allImgs[i]['onmouseout'] = new Function('this.src="'+firstPicSrc+'";');
		}
	}
	imagePreloader(flipClass);
}
function imagePreloader(classes) {
	if(classes == undefined) classes = 'flipper';
	
	var replaceWhat = '-1.jpg';
	var withWhat = '-2.jpg';
	
	var newDiv = document.createElement('div');
	newDiv.style.display = 'none';
	var theBody = document.getElementsByTagName('body');
	theBody[0].appendChild(newDiv);
	newDiv.id = 'preLoaderBay';
	preDiv = document.getElementById('preLoaderBay');
	
	var allImages = document.getElementsByTagName('img');
	var imgLength = allImages.length;
	for(var i = 0; i<imgLength; i++) {
		if(allImages[i].className.indexOf(classes) != -1) {
			var imgSrc = allImages[i].src.replace(replaceWhat, withWhat);
			var newImg = document.createElement('img');
			newImg.src = imgSrc;
			preDiv.appendChild(newImg);
		}
	}
	theBody[0].removeChild(preDiv);
}
if(window.addEventListener) window.addEventListener ("load",imageFlipper,false);
else if(window.attachEvent) window.attachEvent ("onload",imageFlipper);
else window.onload = runFirst;

function pdfNewWindow() {
	var allLinks = document.getElementsByTagName('a');
	var allLinksLength = allLinks.length;
	for(var i=0; i<allLinksLength; i++) {
		if(allLinks[i].href.indexOf('.pdf') != -1 || allLinks[i].href.indexOf('.doc') != -1) {
			var thisTarget = allLinks[i].href;
			allLinks[i]['onclick'] = new Function('window.open("'+thisTarget+'");return false;');
		}
	}
}
if(window.addEventListener) window.addEventListener("load",pdfNewWindow,false);
else if(window.attachEvent) window.attachEvent("onload",pdfNewWindow);
else window.onload = runFirst;

function externalLinks() {
	var allLinks = document.getElementsByTagName('a');
	var allLinksLength = allLinks.length;
	for(var i=0; i<allLinksLength; i++) {
		if(allLinks[i].rel == 'external' || allLinks[i].rel == 'wallpaper') {
			var thisTarget = allLinks[i].href;
			allLinks[i]['onclick'] = new Function('window.open("'+thisTarget+'");return false;');
		}
	}
}
if(window.addEventListener) window.addEventListener("load",externalLinks,false);
else if(window.attachEvent) window.attachEvent("onload",externalLinks);
else window.onload = runFirst;

function diaryCitation() {
	$(
		function() {
			$('p.diaryCitation').css('font-weight', 'normal');
			$('p.diaryCitation').css('font-family', 'Georgia, serif');
			$('p.diaryCitation').css('font-style', 'italic');
			$('p.diaryCitation:first-line').css('font-weight', 'bolder');
			$('p.diaryCitation:first-line').css('font-family', 'arial, verdana, helvetica, serif');
			$('p.diaryCitation:first-line').css('font-style', 'normal');
		}
	);
}
if(window.addEventListener) window.addEventListener("load",diaryCitation,false);
else if(window.attachEvent) window.attachEvent("onload",diaryCitation);
else window.onload = runFirst;

function faqScript() {
    $(
		function() {
		    $('dl.faq>dd').hide();
		    $('dl.faq>dt').css('cursor', 'pointer');
		    $('dl.faq>dt').addClass('showPlus');
		    $('dl.faq>dt').click(function() {
		    $('dl.faq>dd:visible').hide("blind", {}, 500);
		        $(this).removeClass('showMinus');
		        $(this).addClass('showPlus');
		        $(this).siblings().removeClass('showMinus');
		        $(this).siblings().addClass('showPlus');
		        if ($(this).next().css('display') == 'none') {
		            $(this).next().show("blind", {}, 750);
		            $(this).removeClass('showPlus');
		            $(this).addClass('showMinus');
		        }
		        return false;
		    });
		}
	)
}
if(window.addEventListener) window.addEventListener("load",faqScript,false);
else if(window.attachEvent) window.attachEvent("onload",faqScript);
else window.onload = runFirst;
function faqScriptHide() {
	$('dl.faq>dd')(function() {
		if($(this).css('display') != 'none') {
			$(this).hide("blind", {}, 250);
		}
	});
}

function secondaryMenu() {
	$(
		function() {
			$('#secondaryMenu ul').hide();
			$('#subMenu a.JQsm').click(function() {
					var thisId = '.'+$(this).attr("id");
					if($(thisId).css('display') == 'none') {
						$('#secondaryMenu>ul:visible').hide('blind', {}, 250);
						$(thisId).show("blind", {}, 250);
					} else {
						$(thisId).hide("blind", {}, 250);
					}
					return false;
				}
			)
		}
	)
}
if(window.addEventListener) window.addEventListener("load",secondaryMenu,false);
else if(window.attachEvent) window.attachEvent("onload",secondaryMenu);
else window.onload = runFirst;


function ppCalculator() {
	if(document.getElementById('ppCost') && document.getElementById('field0')) {
		numberPP = document.getElementById('field0');
		numberPP['onblur'] = new Function('ppCalculator();');
	} else {
		return false;
	}
	costPara = document.getElementById('ppCost');
	ppValue = numberPP.value;
	if(isNaN(ppValue)) {
		costPara.innerHTML = "You can pre-order up to 99 copies of the Anniversary Book";
		numberPP.value = 1;
	} else if(ppValue < 1 || ppValue > 99) {
		costPara.innerHTML = "You can pre-order up to 99 copies of the Anniversary Book";
		if(ppValue < 1) numberPP.value = 1;
		else numberPP.value = 99;
	} else {
		brCost = 10 * ppValue;
		if(ppValue < 2) {
			brPP = 3;
		} else if(ppValue < 3) {
			brPP = 4;
		} else {
			brPP = 5;
		}
		costPara.innerHTML = "<b>" + ppValue + "</b> copies of the book @ <b>&pound;10</b> each + <b>&pound;"+brPP+".50</b> Postage &amp; Packing"+
		"<br/><b><i>Total: &pound;"+(brCost+brPP)+".50</i></b>";
	}
}
if(window.addEventListener) window.addEventListener("load",ppCalculator,false);
else if(window.attachEvent) window.attachEvent("onload",ppCalculator);
else window.onload = runFirst;


function addBookLink() {
	if(document.getElementById('infoRow')) {
		var linkStrip = document.getElementById('infoRow');
		
		var newText = document.createTextNode("40th Anniversary Book - Buy Now");
		var newA = document.createElement('a');
		var newImg = document.createElement('img');
		newImg.src = '/images/2009/bookOnSale.gif';
		newImg.alt = '40th Anniversary Book - Buy Now';
		newA.title = "The Northern Ballet Theatre 40th Anniversary Book, On Sale Now!";
		newA.href = "http://www.northernballettheatre.co.uk/brochure.aspx";
		newA.className = 'bookLink';
		newA.appendChild(newImg);
		linkStrip.appendChild(newA);
	}
}
if(window.addEventListener) window.addEventListener("load",addBookLink,false);
else if(window.attachEvent) window.attachEvent("onload",addBookLink);
else window.onload = runFirst;


function bookmarking() {
	var thisURL = encodeURIComponent(document.location.href);
	var pageTitle = encodeURIComponent(document.title);
	var bms = new Array();
	bms[0] = Array("http://del.icio.us/post?url=" + thisURL + "&title=" + pageTitle, "Del.icio.us"); //Delicious
	bms[1] = Array("http://digg.com/submit?url=" + thisURL + "&title=" + pageTitle, "Digg"); // Digg
	bms[2] = Array("http://reddit.com/submit?url=" + thisURL + "&title=" + pageTitle, "Reddit"); // Reddit
	bms[3] = Array("http://www.facebook.com/sharer.php?u=" + thisURL + "&t=" + pageTitle, "Facebook"); // Facebook
	bms[4] = Array("http://www.stumbleupon.com/submit?url=" + thisURL + "&title=" + pageTitle, "StumbleUpon"); // StumbleUpon
	bms[5] = Array("http://twitter.com/home?status=" + pageTitle + ": " + thisURL, "Twitter"); // Twitter
	bms[6] = Array("http://www.google.com/bookmarks/mark?op=edit&bkmk=" + thisURL + "&title=" + pageTitle, "Google Bookmarks"); // Google Bookmarks
	//bms[7] = Array("http://sphinn.com/submit.php?url=" + thisURL + "&title=" + pageTitle, "Sphinn"); // Sphinn
	
	var newUL = document.createElement("ul");
	var bmLen = bms.length;
	for(var i=0; i<bmLen; i++) {
		var newLi = document.createElement('li');
		var newA = document.createElement('a');
		newA.href = bms[i][0];
		newA.rel = 'external';
		var newText = document.createTextNode(bms[i][1]);
		newA.appendChild(newText);
		newLi.appendChild(newA);
		newUL.appendChild(newLi);
	}
	
	var newH2 = document.createElement('h2');
	var newText = document.createTextNode('Share this page:');
	newH2.appendChild(newText);
	
	var newDiv = document.createElement('div');
	newDiv.id = 'bookmarking';
	
	newDiv.appendChild(newH2);
	newDiv.appendChild(newUL);
    var divFoot = document.getElementById('footer');
	var thisContent = document.getElementById("content");
	thisContent.insertBefore(newDiv, divFoot);
}
if(window.addEventListener) window.addEventListener("load",bookmarking,false);
else if(window.attachEvent) window.attachEvent("onload",bookmarking);
else window.onload = runFirst;

function showHide(tra, quick) {
	if(quick == 1) {
		$('.tabSection:visible').hide();
		$('#thisSection' + tra).show();
		$('#doTabsList li').removeClass('selected');
		$('#doTabsList li').eq(tra).addClass('selected');
	} else {
		if($('#thisSection' + tra).is(':visible')) {
			//* if this tab is visible then do nowt
		} else {
			$('.tabSection:visible').slideUp('slow');
			$('#thisSection' + tra).slideDown('slow');
			$('#doTabsList li').removeClass('selected');
			$('#doTabsList li').eq(tra).addClass('selected');
		}
	}
}
function doTabs() {
    var noSections = $('.tabSection');
    var noSecLen = noSections.length;
    if (noSections.length > 0) {
        var newUl = document.createElement('ul');
        newUl.id = 'doTabsList';
        var theBody = document.getElementsByTagName('h1');
        var nextEle = theBody[0].nextSibling;
        var nextUp = nextEle.parentNode;
        nextUp.insertBefore(newUl, nextEle);
        $('.tabSection').hide();
        for (var i = 0; i < noSecLen; i++) {
            var thisH2 = noSections[i].getElementsByTagName('h2')[0];
            var h2Text = thisH2.innerHTML;
            var sectionId = 'thisSection' + i;
            $('.tabSection').eq(i).attr('id', sectionId);

            var newText = document.createTextNode(h2Text);
            var newAnchor = document.createElement('a');
            newAnchor.appendChild(newText);
            newAnchor.href = '#';
            var newLi = document.createElement('li');
            newLi.appendChild(newAnchor);
            newUl.appendChild(newLi);

            newAnchor['onclick'] = new Function('showHide('+i+', 0); return false;');
        }

        var instructions = document.createTextNode("Select a heading for further information...");
        var newInst = document.createElement('p');
        newInst.id = 'inPara';
        newInst.appendChild(instructions);
        newInst.className = "pInstructions";
        nextEle = document.getElementById('doTabsList');
        nextUp.insertBefore(newInst, nextEle);
        $('#thisSection0').show();
        $('#doTabsList li').eq(0).addClass('selected');
    }
}
if (window.addEventListener) window.addEventListener("load", doTabs, false);
else if (window.attachEvent) window.attachEvent("onload", doTabs);
else window.onload = runFirst;

function concertina() {
	if(document.getElementById('concertina')) {
		//* Content for Object Close
		var closeInnards = "<p class='closeSection'>Close project information&hellip;</p>";
		//* Hide all Concertina section content
		$('.cSubSection').hide();
		$('.cSubSection').append(closeInnards);
		$('.closeSection').click(function() {
			$(this).parent('.cSubSection').hide('slow', function() {
				$('body').scrollTo('h1', 400);
			});
		});
		//alert(location.href);
		//* Insert instructional paragraph
		$('#concertina').before('<p>Click on a project name for more information&hellip;</p>');
		//* Add clicking event
		$('#concertina .cSection>h2').click(function () {
			if($(this).siblings('.cSubSection').is(":hidden")) {
				//* In the event that the information associated
				//*	with the clicked h2 is invisible
				var parentId = '#' + $(this).parent().attr('id');
				$('.cSubSection:visible').hide();
				$(this).siblings('.cSubSection').show('slow', function() {
					$('body').scrollTo(parentId, 400);
				});
			} else {
				//* In the event that the information associated
				//* with the clicked h2 is already visible
				$(this).siblings('.cSubSection').hide('slow');
			}
		});
		if(location.href.indexOf('#')  != -1) {
			var thisAnchor = location.href.split('#');
			if(document.getElementById(thisAnchor[1])) {
				var theParent = $('#'+thisAnchor[1]).parent().attr('id');
				theParentNumber = theParent.split('Section');
				theParentNumber = theParentNumber[1];
				showHide(theParentNumber, 1);
				$('#'+thisAnchor[1]+' h2').siblings('.cSubSection').show('slow', function() {
					$('body').scrollTo('#'+thisAnchor[1], 400);
				});
			}
		}
		//* Add hover cursor
		$('#concertina h2').css('cursor', 'pointer');
	} else {
		return false;
		/* Do Nothing */
	}
}
if(window.addEventListener) window.addEventListener ("load",concertina,false);
else if(window.attachEvent) window.attachEvent ("onload",concertina);
else window.onload = runFirst;

var newInterval;
function homeSpreads() {
	if(document.getElementById('spread')) {
		var spreadElement = document.getElementById('spread');
		var spreadLink = spreadElement.getElementsByTagName('a')[0];
		var spreadImage = spreadLink.getElementsByTagName('img')[0];
		
		$('#spreadList .buttonList li a').click(function () {
			var buttonLink = $(this).attr('href');
			var buttonImage = $(this).children('img');
			var newSpread = buttonImage[0].src.replace('/button', '/spread');
			
			if(spreadImage.src == newSpread) {
				window.location = buttonLink;
			}
			spreadImage.src = newSpread;
			spreadLink.href = buttonLink;
			return false;
		});
		var numberOfItems = $('#spreadList .buttonList').children('li').length;
		var ulWidth = numberOfItems * 200;
		$('#spreadList .buttonList').css('width',''+ulWidth+'px');
		
		$('#bclose').css('cursor','pointer');
		$('#blate').css('cursor','pointer');
		
		$('#blate img').mouseover(function () {
			newInterval = setInterval('shiftLeft()', 25);
		});
		$('#blate img').mouseout(function () {
			clearInterval(newInterval);
		});
		$('#bclose img').mouseover(function () {
			newInterval = setInterval('shiftRight()', 25);
		});
		$('#bclose img').mouseout(function () {
			clearInterval(newInterval);
		});
		
	} else {
		// Do Nothing
	}
}
if(window.addEventListener) window.addEventListener ("load",homeSpreads,false);
else if(window.attachEvent) window.attachEvent ("onload",homeSpreads);
else window.onload = runFirst;
		function shiftLeft() {
			var mLeft = $('#spreadList .buttonList').css('margin-left');
			if(mLeft.indexOf('px') != -1) {
				mLeft = mLeft.replace('px', '');
			}
			mLeft -= 5;
			
			var maxLeft = 0 - (($('#spreadList .buttonList').children('li').length * 200) + 45 - 750);
			
			if(mLeft <= maxLeft) {
				clearInterval(newInterval);
			} else {
				$('#spreadList .buttonList').css('margin-left',''+mLeft+'px');
			}
		}
		function shiftRight() {
			var mLeft = $('#spreadList .buttonList').css('margin-left');
			if(mLeft.indexOf('px') != -1) {
				mLeft = mLeft.replace('px', '');
			}
			mLeft = mLeft * 1;
			mLeft += 5;
			
			var maxRight = 0;
			
			if(mLeft >= maxRight) {
				clearInterval(newInterval);
			} else {
				$('#spreadList .buttonList').css('margin-left',''+mLeft+'px');
			}
		}

function runFirst() {
	if(window.imageFlipper) imageFlipper();
	if(window.externalLinks) externalLinks();
	if(window.homeSpreads) homeSpreads();
	if(window.rowHighlight) rowHighlight();
	if(window.faqScript) faqScript();
	if(window.pdfNewWindow) pdfNewWindow();
	if(window.wmvLoader) wmvLoader();
	if(window.h1Replace) h1Replace();
	if(window.makeGallery) makeGallery();
	if(window.setAjaxForm) setAjaxForm();
	if(window.addBooking) addBooking();
	if(window.secondaryMenu) secondaryMenu();
	if(window.diaryCitation) diaryCitation();
	if(window.ppCalculator) ppCalculator();
	if(window.bookmarking) bookmarking();
	if (window.addBookLink) addBookLink();
	if (window.changeMainPic) changeMainPic();
	if (window.doTabs) doTabs();
	if (window.removeSection) removeSection();
	if (window.get_rss_feed) get_rss_feed();
	if (window.get_twitter_feed) get_twitter_feed();
	if (window.laSections) laSections();
	if (window.concertina) concertina();
	if (window.LAEvents) LAEvents();
	if (window.gMaps) gMaps();
}