
		
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;
}

/*
* Get a reference to a flash movie object. Adobe recomends using this
* for cross-browser reliability.
*/
function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName]
    }
    else {
        return document[movieName]
    }
}

function externalLinks() { 
	if (!document.getElementsByTagName) return; 
	var anchors = document.getElementsByTagName("a"); 
	for (var i=0; i<anchors.length; i++) { 
		var anchor = anchors[i]; 
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") anchor.target = "_blank"; 
	} 
}

function addClass(theClass) {
	if (this.className != '') {
		this.className += ' ' + theClass;
	} else {
		this.className = theClass;
	}
}

function inArray(needle) {
	for (var i=0; i < this.length; i++) {
		if (this[i] === needle) {
			return i;
		}
	}
	return false;
}

function footnoteLinks(containerID,targetID) {
	if (!document.getElementById || !document.getElementsByTagName || !document.createElement) return false;
	if (!document.getElementById(containerID) || !document.getElementById(targetID)) return false;
	var container = document.getElementById(containerID);
	var target = document.getElementById(targetID);
	var div = document.createElement('div');
	div.setAttribute("id",'footnotes'); 
	var h2 = document.createElement('h2');
	var h2_txt = document.createTextNode('Links');
	h2.appendChild(h2_txt);
	var coll = container.getElementsByTagName('*');
	var ol = document.createElement('ol');
	var myArr = [];
	var thisLink;
	var num = 1;
	for (var i=0; i<coll.length; i++) {
		var thisClass = coll[i].className;
		if ( (coll[i].getAttribute('href') || coll[i].getAttribute('cite')) && (thisClass == '' || thisClass.indexOf('ignore') == -1)) {
			thisLink = coll[i].getAttribute('href') ? coll[i].href : coll[i].cite;
			var note = document.createElement('sup');
			addClass.apply(note,['screen_hide']);
			var note_txt;
			var j = inArray.apply(myArr,[thisLink]);
			if ( j || j===0 ) {
				note_txt = document.createTextNode(j+1);
			} else {
				var li = document.createElement('li');
				var li_txt = document.createTextNode(thisLink);
				li.appendChild(li_txt);
				ol.appendChild(li);
				myArr.push(thisLink);
				note_txt = document.createTextNode(num);
				num++;
			}
			note.appendChild(note_txt);
			if (coll[i].tagName.toLowerCase() == 'blockquote') {
				var lastChild = lastChildContainingText.apply(coll[i]);
				lastChild.appendChild(note);
			} else {
				coll[i].parentNode.insertBefore(note, coll[i].nextSibling);
			}
		}
	}
	
	div.appendChild(h2);
	div.appendChild(ol);
	target.appendChild(div);
	
	addClass.apply(document.getElementsByTagName('html')[0],['noted']);
	return true;
}

function insertExhibitionsVideo () {
	/*
	if ($("#exhibitions_video_swf").length == 1) {
		var flashString = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="356" height="270" id="FLVPlayer">
		<param name="movie" value="swf/FLVPlayer_Progressive.swf" />
		<param name="salign" value="lt" />
		<param name="quality" value="high" />
		<param name="scale" value="noscale" />
		<param name="FlashVars" value="&MM_ComponentVersion=1&skinName=swf/Clear_Skin_1&streamName=../video/Patterson&autoPlay=true&autoRewind=true" />
		<embed src="swf/FLVPlayer_Progressive.swf" flashvars="&MM_ComponentVersion=1&skinName=swf/Clear_Skin_1&streamName=../video/Patterson&autoPlay=true&autoRewind=true" quality="high" scale="noscale" width="356" height="270" name="FLVPlayer" salign="LT" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />      
		</object>';
		
	}
	*/
	
	if ($("#exhibitions_video_swf").length == 1) {
		var s = new SWFObject("swf/FLVPlayer_Progressive.swf", "FLVPlayer",356, 270, "7");
		s.addVariable("salign","lt");
		s.addVariable("quality","high");
		s.addVariable("scale","noscale");
		s.addVariable("FlashVars","&MM_ComponentVersion=1&skinName=swf/Clear_Skin_1&streamName=../video/Patterson&autoPlay=true&autoRewind=true");
		s.write("exhibitions_video_swf");
	}
	
}

$(document).ready(function(){
	externalLinks();
	footnoteLinks('content','container');	
	// if the viewport id exists then set it up
	insertExhibitionsVideo();
	// If it's a gallery page insert slideshow
	if ($("body.bronzes.gallery").length == 1) {
		var s = new SWFObject("swf/imageSlideshow.swf", "slideshowFlashObject",775, 460, "7");
		s.addParam("wmode", "transparent");
		s.addVariable("xmlfile", "http://www.stellashawzin.co.uk/ssp_director/images.php?album=4");
		s.write("slideshow");
	}
	if ($("body.marbles.gallery").length == 1) {
		var s = new SWFObject("swf/imageSlideshow.swf", "slideshowFlashObject",775, 460, "7");
		s.addParam("wmode", "transparent");
		s.addVariable("xmlfile", "http://www.stellashawzin.co.uk/ssp_director/images.php?album=6");
		s.write("slideshow");
	}
	if ($("body.animals.gallery").length == 1) {
		var s = new SWFObject("swf/imageSlideshow.swf", "slideshowFlashObject",775, 460, "7");
		s.addParam("wmode", "transparent");
		s.addVariable("xmlfile", "http://www.stellashawzin.co.uk/ssp_director/images.php?album=7");
		s.write("slideshow");
	}
	if ($("body.videos.gallery").length == 1) {
		var s = new SWFObject("swf/videoSlideshow.swf", "slideshowFlashObject",775, 460, "7");
		s.addParam("wmode", "transparent");
		s.addVariable("xmlfile", "http://www.stellashawzin.co.uk/ssp_director/images.php?album=8");
		s.write("slideshow");
	}
});

function loadContent (contentId) {
	thisMovie("slideshowFlashObject").loadContent(contentId);
}