//events details collapse

function initCollapse() {
	if (document.getElementById && document.getElementsByTagName) {
		if ($('festivals')) {
			var h4arr = $A(document.getElementsByTagName('h4'));
			for (var i=0; i<h4arr.length; i++) {
				var h4 = h4arr[i];
				var partner = h4.nextSibling;
				while (partner.nodeType != 1) {
					partner = partner.nextSibling;	
				}
				h4.partner = partner;
				h4.style.cursor = "pointer";
				h4.refArr = h4arr;
				h4.isCollapsed = false;
				h4.onclick = function() {
					if (this.isCollapsed) {
						for (var i=0; i<this.refArr.length; i++) {
							var ref = this.refArr[i];
							if (!ref.isCollapsed) {
								Effect.BlindUp(ref.partner);
								ref.isCollapsed = !ref.isCollapsed;
							}
						}
						Effect.BlindDown(this.partner);
					} else {
						Effect.BlindUp(this.partner);
					}
					this.isCollapsed = !this.isCollapsed;
				};
				if (i > 0) {
					Effect.BlindUp(h4.partner);
					h4.isCollapsed = true;
				}
			}
		} else {
			return; //do nothing	
		}
	} else {
		return; //do nothing
	}
}

//still click change

function stillThumbs() {
	if (document.getElementById && document.getElementsByTagName) {
		if (still = $('still')) {
			var stillImg;
			var stillCaption;
			
			for (var i=0; i<still.childNodes.length; i++) {
				var cn = still.childNodes[i];
				if (cn.nodeType == 1 && cn.nodeName == "IMG") stillImg = cn;
				if (cn.nodeType == 1 && cn.nodeName == "P") stillCaption = cn;
			}
			
			var allAnchors = $A(document.getElementsByTagName('a'));
			var anchors = new Array();
			for (var i=0; i<allAnchors.length; i++) {
				var anc = allAnchors[i];
				if (anc.rel == "thumbnail") {
					anc.imgsrc = anc.firstChild.src.replace(/(.)(thumbs)(.)/gi, "$1large$3");
					anc.imgcap = anc.firstChild.alt;
					anc.stillImg = stillImg;
					anc.stillCaption = stillCaption;
					anc.onclick = function() {
						this.stillImg.src = this.imgsrc;
						this.stillCaption.innerHTML = this.imgcap;
						return false;
					};
				}
			}
		} else {
			return; //do nothing
		}
	} else {
		return; //do nothing
	}
}

//external links
function externalLinks() {
	if (document.getElementsByTagName) {
		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";
		}
	} else {
		return //do nothing
	}
}

//ufo

function buildFO() {
	var fo = {movie: rootPath + "flash/video2.swf", width: "750", height: "390", majorversion: "8", build: "0", id: "trailerswf", quality: "high", wmode: "transparent"};
	UFO.create(fo, "trailer");
}

window.onload = function() {
	//activate the trailer link
	var tlink = $('trailerlink');
	tlink.onclick = function() {
		buildFO();
		return false;
	};
	
	externalLinks();
	initCollapse();
	stillThumbs();
}