/* ----------------------------------------------------------------------------
	Initialise
---------------------------------------------------------------------------- */
manageEvents("add", window, "load", initialise);

function initialise() {
	// create namespaces
	Deepend.namespace("Display");
	Deepend.namespace("AJAX");
	Deepend.namespace("Style");
	Deepend.namespace("ACO");
	
	// initiate objects
	DeepDisplay = new Deepend.Display();
	DeepAJAX = new Deepend.AJAX();
	DeepStyle = new Deepend.Style();
	ACO = new Deepend.ACO();
	
	DeepAJAX.sPath = "services/";
	
	// initiate load functions
	DeepDisplay.loadBrowserStyles();
	DeepDisplay.embedIEPNG();
	DeepDisplay.parseLocation();
	DeepDisplay.renderHeadings();
	
	DeepDisplay.renderFlash();
	DeepDisplay.fixHitArea();
	DeepDisplay.resizeElements();
	DeepDisplay.assignInputEvents();
	
	if (DeepDisplay.sLocation.indexOf("buy-concert-tickets") != -1) ACO.buildSelect(1);
	
	if (document.getElementById("image-source") && document.getElementById("image-viewer"))
		DeepDisplay.buildVenueGallery();
	
	manageEvents("add", window, "resize", DeepDisplay.resizeElements);
};


/* ----------------------------------------------------------------------------
	Display Elements
---------------------------------------------------------------------------- */
var DeepDisplay;

Deepend.Display = function() {
	// setup constants and variables
	var HTML_ELEMENT_BACKGROUND = "flash-bkg";
	var HTML_ELEMENT_NAV = "nav-site";
	var HTML_ELEMENT_SUBNAV = "sub-nav-site";
	var HTML_ELEMENT_FOOTER = "footer";
	var HTML_ELEMENT_PERFORMANCE = "performance-nav";
	var HTML_ELEMENT_HEADINGNOLINE = "noline";
	var HTML_ELEMENT_IMAGEVIEWER = "image-viewer";
	var HTML_ELEMENT_IMAGESOURCE = "image-source";
	var HTML_ELEMENT_GALLERYVIEWER = "gallery-viewer";
	var HTML_ELEMENT_GALLERYPAGES = "pages";
	var HTML_ELEMENT_GALLERYPAGE = "page";
	var HTML_ELEMENT_GALLERYLINKS = "links";
	var HTML_ELEMENT_GALLERYIMAGE = "gallery-image";
	var CSS_LINK_TEXT = "link-text";
	var CSS_LINK_IMAGE = "link-image";
	var CSS_LINK_HOME = "link-home";
	var CSS_LINK_PERFORMANCE = "link-performance";
	var CSS_LINK_PLAYER = "link-player";
	var CSS_LINK_TEXTCONTENT = "link-text-content";
	var FLASH_ID_BACKGROUND = "aco-backround-image";
	var FLASH_ID_NAV = "aco-topmenu";
	var FLASH_ID_SUBNAV = "aco-sidemenu";
	var FLASH_ID_PERFORMANCE = "aco-performance";
	var FLASH_SRC_NAV = "flash/aco-topmenu.swf";
	var FLASH_SRC_SUBNAV = "flash/aco-sidemenu.swf";
	var FLASH_SRC_PERFORMANCE = "flash/aco-contentmenu.swf";
	var FLASH_CLASSID = "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000";
	var FLASH_CODEBASE = "https://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0";
	var FLASH_PLUGINSPAGE = "https://www.macromedia.com/go/getflashplayer";
	var FLASH_PARAMS = [
		{ "name": "allowScriptAccess", "value": "sameDomain" },
		{ "name": "quality", "value": "high" }, 
		{ "name": "wmode", "value": "transparent" },
		{ "name": "type", "value": "application/x-shockwave-flash" }
	];
	
	var sLocation; this.sLocation = sLocation;
	var eCurrentSource; this.eCurrentSource = eCurrentSource;
	var bGalleryVisible; this.bGalleryVisible = false;
	
	// gallery config
	var oGalleryConfig;
	this.oGalleryConfig = {
		"width": "530",
		"height": "552",
		"pagesize": "9",
		"imgwidth": "475",
		"imgheight": "330",
		"thumbwidth": "155",
		"thumbheight": "90",
		"imgpath": "images/performance/gallery/",
		"thumbpath": "images/performance/gallery/thumb/"
	};
	
	// gallery images collection
	var oGalleryImages; this.oGalleryImages;
	
	/*
	renderFlash
	*/
	this.renderFlashBaK = function() {
		var eFlash; this.eFlash = eFlash;
		var eDiv; this.eDiv = eDiv;
		
		// json object used for looping through any items that need to utilise flash replacement
		var oFlashElements;
		this.oFlashElements = [
			{ "id": HTML_ELEMENT_BACKGROUND, "objectid": FLASH_ID_BACKGROUND, "src": "images/backgrounds/" + getFlashData(HTML_ELEMENT_BACKGROUND), "width": "100%", "height": "100%", "align": "middle" },
			//{ "id": HTML_ELEMENT_NAV, "objectid": FLASH_ID_NAV, "src": FLASH_SRC_NAV, "width": "766", "height": "45", "salign": "lt", "vars": getFlashData(HTML_ELEMENT_NAV) },
			//{ "id": HTML_ELEMENT_SUBNAV, "objectid": FLASH_ID_SUBNAV, "src": FLASH_SRC_SUBNAV, "width": "182", "height": "1", "salign": "lt", "vars": getFlashData(HTML_ELEMENT_SUBNAV) },
			{ "id": HTML_ELEMENT_PERFORMANCE, "objectid": FLASH_ID_PERFORMANCE, "src": FLASH_SRC_PERFORMANCE, "width": "530", "height": "30", "vars": getFlashData(HTML_ELEMENT_PERFORMANCE) }
		];
		
		for (e in this.oFlashElements) {
			this.eFlash = document.getElementById(this.oFlashElements[e].id);
			
			if (this.eFlash) {
				// fix flash background for IE6
				if (this.oFlashElements[e].id == HTML_ELEMENT_BACKGROUND)
					if (oBrowser.IE && oBrowser.IEVersion <= 6) {
						this.eFlash.id = "flash-bkg-ie6";
					}
				
				// create flash output code
				var so = new SWFObject(this.oFlashElements[e].src, this.oFlashElements[e].objectid, this.oFlashElements[e].width, this.oFlashElements[e].height, "8", "#ffffff");
				
				for (a in FLASH_PARAMS) {
					so.addParam(FLASH_PARAMS[a].name, FLASH_PARAMS[a].value);
				}
				if (this.oFlashElements[e].align) so.addParam("align", this.oFlashElements[e].align);
				if (this.oFlashElements[e].vars) so.addParam("FlashVars", this.oFlashElements[e].vars);
				if (this.oFlashElements[e].salign) so.addParam("salign", this.oFlashElements[e].salign);
				
				so.useExpressInstall('flash/expressinstall.swf');
				
				if (this.oFlashElements[e].id == HTML_ELEMENT_BACKGROUND) {
					this.eFlash.innerHTML = this.sFlashOutput;
					so.write(this.eFlash.id);
				} else {
					// create div to hold output
					this.eDiv = document.createElement("div");
					this.eFlash.insertAdjacentElement("beforeBegin", this.eDiv);
					this.eDiv.id = this.oFlashElements[e].id + "-flash";
					so.write(this.eDiv.id);
				}
			}
		}
		
		function getFlashData(eElement) {
			this.eElement = document.getElementById(eElement);
			if (this.eElement) {
				var sTitle = this.eElement.getAttribute("title");
				this.eElement.setAttribute("title", "");
				return sTitle;
			} else
				return null;
		};

	}
	
	this.renderFlash = function() {
		var sFlashOutput; this.sFlashOutput = sFlashOutput;
		var eFlash; this.eFlash = eFlash;
		var eDiv; this.eDiv = eDiv;

		// json object used for looping through any items that need to utilise flash replacement
		var oFlashElements;
		this.oFlashElements = [
			{ "id": HTML_ELEMENT_BACKGROUND, "objectid": FLASH_ID_BACKGROUND, "src": "images/backgrounds/" + getFlashData(HTML_ELEMENT_BACKGROUND), "width": "100%", "height": "100%", "align": "middle" },
			//{ "id": HTML_ELEMENT_NAV, "objectid": FLASH_ID_NAV, "src": FLASH_SRC_NAV, "width": "766", "height": "45", "salign": "lt", "vars": getFlashData(HTML_ELEMENT_NAV) },
			//{ "id": HTML_ELEMENT_SUBNAV, "objectid": FLASH_ID_SUBNAV, "src": FLASH_SRC_SUBNAV, "width": "182", "height": "1", "salign": "lt", "vars": getFlashData(HTML_ELEMENT_SUBNAV) },
			{ "id": HTML_ELEMENT_PERFORMANCE, "objectid": FLASH_ID_PERFORMANCE, "src": FLASH_SRC_PERFORMANCE, "width": "530", "height": "30", "vars": getFlashData(HTML_ELEMENT_PERFORMANCE) }
		];
		
		for (e in this.oFlashElements) {
			this.eFlash = document.getElementById(this.oFlashElements[e].id);
			
			if (this.eFlash) {
				// fix flash background for IE6
				if (this.oFlashElements[e].id == HTML_ELEMENT_BACKGROUND)
					if (oBrowser.IE && oBrowser.IEVersion <= 6)
						this.eFlash.id = "flash-bkg-ie6";
				
				// create flash output code
				this.sFlashOutput = "<object classid=\"" + FLASH_CLASSID + "\" "
						+ "codebase=\"" + FLASH_CODEBASE + "\" "
						+ "id=\"" + this.oFlashElements[e].objectid + "\" "
						+ "width=\"" + this.oFlashElements[e].width + "\" "
						+ "height=\"" + this.oFlashElements[e].height + "\" "
						+ "style=\"margin:0 0 1px 0;\" "
						+ "VIEWASTEXT";
				if (this.oFlashElements[e].align) this.sFlashOutput += " align=\"" + this.oFlashElements[e].align + "\" "
				this.sFlashOutput += ">"
					+ "<param name=\"movie\" value=\"" + this.oFlashElements[e].src + "\" />";
				
				if (this.oFlashElements[e].vars) this.sFlashOutput += "<param name=\"FlashVars\" value=\"" + this.oFlashElements[e].vars + "\" />";
				if (this.oFlashElements[e].salign) this.sFlashOutput += "<param name=\"salign\" value=\"" + this.oFlashElements[e].salign + "\" />";
				
				for (a in FLASH_PARAMS)
					this.sFlashOutput += "<param name=\"" + FLASH_PARAMS[a].name + "\" value=\"" + FLASH_PARAMS[a].value + "\" />"
				
				this.sFlashOutput += "<embed src=\"" + this.oFlashElements[e].src + "\" "
						+ "FlashVars=\"" + this.oFlashElements[e].vars + "\" "
						+ "name=\"" + this.oFlashElements[e].objectid + "\" "
						+ "width=\"" + this.oFlashElements[e].width + "\" "
						+ "height=\"" + this.oFlashElements[e].height + "\" "
						+ "pluginspage=\"" + FLASH_PLUGINSPAGE + "\" "
						+ "style=\"margin:0 0 1px 0;\" ";
				
				if (this.oFlashElements[e].salign) this.sFlashOutput += "salign=\"" + this.oFlashElements[e].salign + "\" ";
				
				for (a in FLASH_PARAMS) {
					this.sFlashOutput += FLASH_PARAMS[a].name + "=\"" + FLASH_PARAMS[a].value + "\"";
						+ (a == FLASH_PARAMS.length - 1) ? "></embed>" : " ";
				}
				
				this.sFlashOutput += "</object>";
				
				if (this.oFlashElements[e].id == HTML_ELEMENT_BACKGROUND)
					this.eFlash.innerHTML = this.sFlashOutput;
				else {
					// create div to hold output
					this.eDiv = document.createElement("div");
					this.eFlash.insertAdjacentElement("beforeBegin", this.eDiv);
					this.eDiv.id = this.oFlashElements[e].id + "-flash";
					this.eDiv.innerHTML = this.sFlashOutput;
					
					// remove html node that is being replaced
					if (BrowserDetect.browser == "Safari") {
						var oParent = this.eFlash.parentNode;
						if (this.eFlash) oParent.removeChild(this.eFlash);
					} else {
						if (this.eFlash.removeNode) {
							this.eFlash.removeNode(true);
						}
					}					
				}
			}
		}
		
		function getFlashData(eElement) {
			this.eElement = document.getElementById(eElement);
			if (this.eElement) {
				var sTitle = this.eElement.getAttribute("title");
				this.eElement.setAttribute("title", "");
				return sTitle;
			} else
				return null;
		};
	};
	
	/*
	fixHitArea
	*/
	this.fixHitArea = function() {
		var eLinks; this.eLinks = document.getElementsByTagName("a");
		var iLinksLength; this.iLinksLength = this.eLinks.length;
		var sLinkID; this.sLinkID = sLinkID;
		var eLink; this.eLink = eLink;
		var eImg; this.eImg = eImg;
		var eDiv; this.eDiv = eDiv;
		var eTitle; this.eTitle = eTitle;
		var eParent; this.eParent = eParent;
		var eRegExp; this.eRegExp = eRegExp;
		var sPattern; this.sPattern = sPattern;
		var ePerformance; this.ePerformance = ePerformance;
		var oPerformanceNav; this.oPerformanceNav = oPerformanceNav;
		
		this.sPattern = CSS_LINK_TEXT + "|" + CSS_LINK_IMAGE + "|" + CSS_LINK_HOME + "|" + CSS_LINK_PLAYER + "|" + CSS_LINK_TEXTCONTENT;
		this.eRegExp = new RegExp(this.sPattern, "i");
		
		this.oPerformanceNav = [
			{ "title": "overview", "left": "0", "width": "86", "height": "30", "titlewidth": "57", "titleheight": "9" },
			{ "title": "behind-the-scenes", "left": "87", "width": "133", "height": "30", "titlewidth": "105", "titleheight": "9" },
			{ "title": "galleries", "left": "221", "width": "81", "height": "30", "titlewidth": "54", "titleheight": "9" },
			{ "title": "concert-reviews", "left": "303", "width": "126", "height": "30", "titlewidth": "99", "titleheight": "9" },
			{ "title": "your-say", "left": "430", "width": "100", "height": "30", "titlewidth": "55", "titleheight": "9" }
		];
		
		for (i = 0; i < this.iLinksLength; i++) {
			// find all text and image link elements and fix hit area
			if (this.eRegExp.test(this.eLinks[i].className)) {
				switch (this.eLinks[i].className) {
					case CSS_LINK_TEXT: // text link
						this.eImg = createClear(this.eLinks[i]);
						with (this.eImg) {
							style.width = this.eLinks[i].clientWidth + "px";
							style.height = this.eLinks[i].clientHeight + "px";
						}
						
						// create arrow
						this.eImg = document.createElement("img");
						this.sLinkID = (this.eLinks[i].getAttribute("id")) ? this.eLinks[i].getAttribute("id") : "";
						if (this.sLinkID.indexOf("previous") == -1) {
							this.eImg.src = "images/icons/arrow-right.gif";
							this.eImg.className = "arrow-right";
							this.eLinks[i].insertAdjacentElement("afterBegin", this.eImg);
						} else {
							this.eImg.src = "images/icons/arrow-left.gif";
							this.eImg.className = "arrow-left";
							this.eLinks[i].insertAdjacentElement("beforeEnd", this.eImg);
						}
						break;
					
					case CSS_LINK_IMAGE: //image link
						this.eImg = createClear(this.eLinks[i]);
						
						//this.eLinks[i].style.width = (this.eLinks[i].parentNode.parentNode.clientWidth - 20)+ "px";
						with (this.eImg) {
							style.width = this.eLinks[i].clientWidth + "px";
							style.height = this.eLinks[i].clientHeight + "px";
						}
						
						createWhiteBox(this.eLinks[i]);
						break;
					
					case CSS_LINK_HOME: // image link for homepage only
						this.eImg = createClear(this.eLinks[i]);
						
						this.eLinks[i].style.width = this.eLinks[i].firstChild.clientWidth + "px";
						with (this.eImg) {
							style.width = this.eLinks[i].clientWidth + "px";
							style.height = this.eLinks[i].clientHeight + "px";
						}
						break;
					
					case CSS_LINK_PLAYER: // link for players
						this.eDiv = this.eLinks[i].parentNode;
						this.eDiv.onmouseover = function() { this.style.backgroundColor = "#FFF"; };
						this.eDiv.onmouseout = function() { this.style.backgroundColor = ""; };
						this.eDiv.onclick = new Function("location.href = \"" + this.eLinks[i] + "\"");
						
						this.eImg = createClear(this.eDiv);
						with (this.eImg) {
							style.width = this.eDiv.clientWidth + "px";
							style.height = this.eDiv.clientHeight + "px";
						}
						break;
					
					case CSS_LINK_TEXTCONTENT: // text link in content
						this.eImg = createClear(this.eLinks[i]);
						with (this.eImg) {
							style.width = this.eLinks[i].clientWidth + "px";
							style.height = this.eLinks[i].clientHeight + "px";
						}
						
						// create arrow
						this.eImg = document.createElement("img");
						with (this.eImg) {
							src = "images/icons/arrow-right.gif";
							className = "arrow-right";
						}
						this.eLinks[i].insertAdjacentElement("afterBegin", this.eImg);
				};
			}
		}
		
		function createClear(eLink) {
			// create clear gif
			this.eImg = document.createElement("img");
			eLink.appendChild(this.eImg);
			this.eImg.src = "images/clear.gif";
			this.eImg.className = "clear";
			return this.eImg;
		};
		
		function createWhiteBox(eLink) {
			// create white box
			this.eImg = document.createElement("img");
			eLink.appendChild(this.eImg);
			with (this.eImg) {
				src = "images/nav/link-box.gif";
				style.width = "15px";
				style.height = "8px";
				className = "box";
			}
		};
	};
	
	/*
	renderHeadings
	*/
	this.renderHeadings = function() {
		var eHeading; this.eHeading = document.getElementById("h1");
		var iHeadingWidth; this.iHeadingWidth;
		var iMaxWidth; this.iMaxWidth = 717;
		var iGap; this.iGap = 12;
		var eDiv; this.eDiv = eDiv;
		
		if (this.eHeading) {
			this.iHeadingWidth = this.eHeading.clientWidth;
			
			if (this.iHeadingWidth == 717) {
				trace("** ALERT: HEADING NEEDS TO BE RESIZED **");
				return;
			}
			
			// if flag set to noline then don't show line.
			if (document.getElementById(HTML_ELEMENT_HEADINGNOLINE)) return;
			
			this.eDiv = document.createElement("div");
			with (this.eDiv) {
				style.position = "absolute";
				style.top = "1px";
				style.right = "0";
				style.zIndex = "100";
				style.width = (this.iMaxWidth - this.iHeadingWidth - this.iGap) + "px";
				style.height = "1px";
				style.borderTop = "0px solid #FFF";
			}
			this.eDiv.className = "header-line";
			//DeepStyle.setOpacity(this.eDiv, .75);
			this.eHeading.insertAdjacentElement("afterEnd", this.eDiv);
		}
	};
	
	/*
	embedIEPNG
	*/
	this.embedIEPNG = function() {
		// embed pngs only for IE versions 6 & 5.5
		if (oBrowser.IE)
			if (oBrowser.IEVersion <= 6 && oBrowser.IEVersion >= 5.5) {
				// find all images with .png
				var eImgs = this.eImgs = document.getElementsByTagName("img");
				var iImgsLength = this.iImgsLength = this.eImgs.length;
				var eDiv = this.eDiv;
				var eHTML = this.eHTML;
				var sImgSrc = this.sImgSrc;
				
				for (i = 0; i < this.eImgs.length; i++) {
					this.sImgSrc = this.eImgs[i].src.toLowerCase();
					if (this.sImgSrc.indexOf(".png") != -1) {
						this.eDiv = document.createElement("div");
						this.eImgs[i].insertAdjacentElement("afterEnd", this.eDiv);
						with (this.eDiv) {
							style.width = this.eImgs[i].width;
							style.height = this.eImgs[i].height;
							title = this.eImgs[i].title;
							className = this.eImgs[i].className;
						}
						if (this.eImgs[i].id) this.eDiv.id = this.eImgs[i].id;
						
						DeepStyle.setPNG(this.eDiv, this.eImgs[i].src, "no-repeat");
						this.eImgs[i].removeNode();
						i -= 1;
					}
				}
			}
	};
	
	/*
	resizeElements
	*/
	this.resizeElements = function() {
		// resize footer to 100% so it doesn't muck around with widths
		var eFooter; this.eFooter = document.getElementById(HTML_ELEMENT_FOOTER);
		
		if (this.eFooter) {
			this.eFooter.style.width = "100%";
			
			var oWinSize;
			this.oWinSize = {
				"width": document.documentElement.clientWidth,
				"height": document.documentElement.clientHeight,
				"scrollwidth": document.documentElement.scrollWidth,
				"scrollheight": document.documentElement.scrollHeight
			};
			
			// resize footer width with the proper size
			this.eFooter.style.width = parseInt(this.oWinSize.width) < 950 ? this.oWinSize.scrollwidth + "px" : "100%";
		}
	};
	
	/*
	buildVenueImages
	*/
	this.buildVenueGallery = function() {
		var eImageSource; this.eImageSource = document.getElementById(HTML_ELEMENT_IMAGESOURCE);
		var eImages; this.eImages = this.eImageSource.getElementsByTagName("img");
		var eImagesLength; this.eImagesLength = this.eImages.length;
		var iCount; this.iCount = 1;
		
		for (i = 0; i < this.eImages.length; i++)
			if (this.eImages[i].src.indexOf(".jpg") != -1 || this.eImages[i].src.indexOf(".gif") != -1) {
				switch (this.iCount) {
					case 1: // select first image
						DeepDisplay.toggleVenueImage(this.eImages[i]); break;
					
					case 2: case 4: // add breaks
						this.eImages[i].insertAdjacentElement("beforeBegin", document.createElement("br"));
					
					default: // add events images
						this.eImages[i].onclick = function() { DeepDisplay.toggleVenueImage(this); };
						this.eImages[i].style.cursor = "pointer";
				}
				this.iCount += 1;
			}
	};
	
	/*
	toggleVenueImage
	@eImage: Source of onclick
	*/
	this.toggleVenueImage = function(eSource) {
		this.eSource = eSource;
		var eImage; this.eImage = eImage;
		var eImageViewer; this.eImageViewer = document.getElementById(HTML_ELEMENT_IMAGEVIEWER);
		var eCurrentImage; this.eCurrentImage = this.eImageViewer.childNodes[0];
		
		// reset opacity and viewer
		if (this.eCurrentImage) {
			//DeepStyle.setOpacity(DeepDisplay.eCurrentSource, 1);
			DeepDisplay.eCurrentSource.onclick = function() { DeepDisplay.toggleVenueImage(this); };
			DeepDisplay.eCurrentSource.style.cursor = "pointer";
			DeepDisplay.eCurrentSource.style.border = "1px solid #fff";
			
			if (this.eCurrentImage.removeNode)
			this.eCurrentImage.removeNode(true);
		}
		
		// set source in global var
		DeepDisplay.eCurrentSource = this.eSource;
		
		// set opacity of selected item and remove cursor
		//DeepStyle.setOpacity(this.eSource, 0.5);
		this.eSource.style.cursor = "default";
		this.eSource.style.border = "1px solid #000";
		
		// insert big image into viewer
		this.eImage = document.createElement("img");
		this.eImageViewer.appendChild(this.eImage);
		this.eImage.src = this.eSource.src.replace(/-thumb/ig, "");
	};
	
	/*
	buildGalleryViewer
	@iPerformance: Performance ID
	@iGallery: Gallery ID
	*/
	this.buildGalleryViewer = function(iGallery) {
		this.iGallery = iGallery;
		
		// if gallery is already built, return the funtion
		if (DeepDisplay.bGalleryVisible) return;
		DeepDisplay.bGalleryVisible = true;
		
		// container
		var eGalleryViewer; this.eGalleryViewer = document.createElement("div");
		document.getElementsByTagName("h1")[0].insertAdjacentElement("afterEnd", this.eGalleryViewer);
		this.eGalleryViewer.setAttribute("id", HTML_ELEMENT_GALLERYVIEWER);
		DeepStyle.setOpacity(this.eGalleryViewer, 0.1);
		
		// yahoo animation attributes
		var oAttributes;
		this.oAttributes = {
			width: { to: DeepDisplay.oGalleryConfig.width },
			height: { to: DeepDisplay.oGalleryConfig.height },
			//top: {  },
			//left: {  },
			opacity: { to: 1 }
		};
		var oGalleryAnim; this.oGalleryAnim = new YAHOO.util.Anim("gallery-viewer", this.oAttributes, 0.7, YAHOO.util.Easing.backOut);
		this.oGalleryAnim.onComplete.subscribe(function() { DeepDisplay.callGalleryData(iGallery) });
		this.oGalleryAnim.animate();
	};
	
	/*
	callGalleryData
	@iGallery: Gallery ID
	*/
	this.callGalleryData = function(iGallery) {
		this.iGallery = iGallery;
		var eGalleryViewer; this.eGalleryViewer = document.getElementById(HTML_ELEMENT_GALLERYVIEWER);
		
		// ajax images and load
		var sPostVars; this.sPostVars = "gallery=" + this.iGallery;
		DeepAJAX.Load("gallery.aspx", "POST", DeepDisplay.buildGallery, 1, this.sPostVars);
	};
	
	/*
	buildGallery
	@iStep: 2 Steps in the process. (Mandatory)
		1 = building elements
		2 = building images
	@iPage: Identifies what page of images to display. (Optional)
	*/
	this.buildGallery = function(iStep, iPage) {
		this.iStep = iStep;
		this.iPage = (iPage) ? iPage : 1;
		var eGalleryViewer; this.eGalleryViewer = document.getElementById(HTML_ELEMENT_GALLERYVIEWER);
		var eDiv; this.eDiv = eDiv;
		var eHeading; this.eHeading = eHeading;
		var eLink; this.eLink = eLink;
		var eParagraph; this.eParagraph = eParagraph;
		var eSpan; this.eSpan = eSpan;
		var ePage; this.ePage = ePage;
		
		switch (this.iStep) {
			case 1: // build elements
				// close link
				this.eParagraph = document.createElement("p");
				this.eParagraph.className = "close-link";
				this.eLink = document.createElement("a");
				this.eParagraph.appendChild(this.eLink);
				this.eLink.appendChild(document.createTextNode("x close gallery"));
				this.eLink.setAttribute("href", "javascript:DeepDisplay.closeGallery()");
				this.eGalleryViewer.appendChild(this.eParagraph);
				
				// ajax data
				// note: storage of data in global variable
				DeepDisplay.oGalleryImages = eval("(" + this.oLoader.responseText + ")");
				DeepDisplay.oGalleryImages = DeepDisplay.oGalleryImages.gallery[0];
				var sGalleryTitle; this.sGalleryTitle = DeepDisplay.oGalleryImages.name;
				
				// gallery heading
				this.eHeading = document.createElement("h3");
				this.eHeading.appendChild(document.createTextNode(this.sGalleryTitle));
				this.eGalleryViewer.appendChild(this.eHeading);
				
				// image page container
				this.eDiv = document.createElement("div");
				this.eDiv.setAttribute("id", "pages");
				this.eGalleryViewer.appendChild(this.eDiv);
				
				// footer
				this.eDiv = document.createElement("div");
				this.eDiv.className = "footer";
				this.eParagraph = document.createElement("p");
				this.eDiv.appendChild(this.eParagraph);
				this.eParagraph.appendChild(document.createTextNode("Click on a thumbnail to view larger image"));
				this.eGalleryViewer.appendChild(this.eDiv);
				
				DeepDisplay.buildGallery(2, this.iPage);
				break;
			
			case 2: // build images
				var oGalleryImages; this.oGalleryImages = DeepDisplay.oGalleryImages;
				var oPaging; this.oPaging = new calcPaging(this.iPage);
				
				// eGalleryPages is the container for eGalleryPage
				// this is for height, paging and animation purposes
				var eGalleryPages; this.eGalleryPages = document.getElementById(HTML_ELEMENT_GALLERYPAGES);
				var eGalleryPage; this.eGalleryPage = document.getElementById(HTML_ELEMENT_GALLERYPAGE);
				
				// if page is not present, create it
				if (!this.eGalleryPage) {
					var eGalleryPage; this.eGalleryPage = document.createElement("div");
					this.eGalleryPages.appendChild(this.eGalleryPage);
					this.eGalleryPage.setAttribute("id", HTML_ELEMENT_GALLERYPAGE);
				}
				
				// clear nodes if paging
				DeepDisplay.removeAllNodes(this.eGalleryPage);
				
				for (e = (this.oPaging.iStart - 1); e <= (this.oPaging.iFinish - 1); e++) {
					// image container
					this.eDiv = document.createElement("div");
					this.eDiv.setAttribute("id", this.oGalleryImages.images[e].imagesrc);
					this.eDiv.onmouseover = function() { this.style.backgroundColor = "#FFF"; };
					this.eDiv.onmouseout = function() { this.style.backgroundColor = "#BFBFBF"; };
					this.eDiv.onclick = function() { displayImage(this); };
					
					// image
					this.eImg = document.createElement("img");
					this.eDiv.appendChild(this.eImg);
					with (this.eImg) {
						setAttribute("src", DeepDisplay.oGalleryConfig.thumbpath + this.oGalleryImages.images[e].thumb);
						style.width = DeepDisplay.oGalleryConfig.thumbwidth + "px";
						style.height = DeepDisplay.oGalleryConfig.thumbheight + "px";
					}
					this.eDiv.appendChild(document.createElement("br"));
					
					// title & description
					this.eParagraph = document.createElement("p");
					this.eParagraph.appendChild(document.createTextNode(this.oGalleryImages.images[e].title));
					this.eDiv.appendChild(this.eParagraph);
					this.eSpan = document.createElement("span");
					this.eSpan.appendChild(document.createTextNode(this.oGalleryImages.images[e].description));
					this.eDiv.appendChild(this.eSpan);
					
					this.eGalleryPage.appendChild(this.eDiv);
				}
				
				// create and edit paging links
				// check to see if element has been created, if so, then just rewrite the href
				var ePagingLinks; this.ePagingLinks = document.getElementById(HTML_ELEMENT_GALLERYLINKS);
				if (!this.ePagingLinks) {
					// create links
					this.eParagraph = document.createElement("p");
					this.eParagraph.setAttribute("id", "links");
					
					// previous
					this.eLink = document.createElement("a");
					this.eParagraph.appendChild(this.eLink);
					this.eImg = document.createElement("img");
					this.eLink.appendChild(this.eImg);
					this.eImg.setAttribute("src", "images/icons/white-arrow-left.gif");
					this.eLink.appendChild(document.createTextNode("Previous"));
					if (this.iPage > 1) {
						this.eLink.className = "previous";
						this.eLink.setAttribute("href", "javascript:DeepDisplay.buildGallery(2," + (this.iPage - 1) + ")");
					} else
						this.eLink.className = "previous-inactive";
					
					// next
					this.eLink = document.createElement("a");
					this.eLink.appendChild(document.createTextNode("Next"));
					this.eImg = document.createElement("img");
					this.eLink.appendChild(this.eImg);
					this.eImg.setAttribute("src", "images/icons/white-arrow-right.gif");
					if (this.iPage < this.oPaging.iPageTotal) {
						this.eLink.className = "next";
						this.eLink.setAttribute("href", "javascript:DeepDisplay.buildGallery(2," + (this.iPage + 1) + ")");
					} else
						this.eLink.className = "next-inactive";
					
					this.eParagraph.appendChild(this.eLink);
					this.eGalleryViewer.appendChild(this.eParagraph);
				} else {
					// edit links
					var eLinks; this.eLinks = this.ePagingLinks.getElementsByTagName("a");
					
					// previous
					if (this.iPage > 1) {
						this.eLinks[0].className = "previous";
						this.eLinks[0].setAttribute("href", "javascript:DeepDisplay.buildGallery(2," + (this.iPage - 1) + ")");
					} else {
						this.eLinks[0].className = "previous-inactive";
						this.eLinks[0].removeAttribute("href");
					}
					
					// next
					if (this.iPage < this.oPaging.iPageTotal) {
						this.eLinks[1].className = "next";
						this.eLinks[1].setAttribute("href", "javascript:DeepDisplay.buildGallery(2," + (this.iPage + 1) + ")");
					} else {
						this.eLinks[1].className = "next-inactive";
						this.eLinks[1].removeAttribute("href");
					}
				}
		}
		
		function calcPaging(iPage) {
			var oGalleryImages; this.oGalleryImages = DeepDisplay.oGalleryImages.images;
			
			// total number of images
			var iImageTotal; this.iImageTotal = this.oGalleryImages.length;
			
			// total number of pages
			var iPageTotal; this.iPageTotal = this.iImageTotal / parseInt(DeepDisplay.oGalleryConfig.pagesize) + "";
			this.iPageTotal = (this.iPageTotal.indexOf(".") > -1) ? (parseInt(this.iPageTotal.substring(0, this.iPageTotal.indexOf("."))) + 1) : parseInt(this.iPageTotal);
			
			// start and finish ints
			var iStart; this.iStart = (iPage == 1) ? 1 : ((iPage - 1) * parseInt(DeepDisplay.oGalleryConfig.pagesize)) + 1;
			var iFinish; this.iFinish = (iPage == 1) ? parseInt(DeepDisplay.oGalleryConfig.pagesize) : (iPage * parseInt(DeepDisplay.oGalleryConfig.pagesize));
			if (this.iFinish > this.iImageTotal) this.iFinish = this.iImageTotal;
		};
		
		function displayImage(eElement) {
			this.eElement = eElement;
			var eGalleryViewer; this.eGalleryViewer = document.getElementById(HTML_ELEMENT_GALLERYVIEWER);
			var eGalleryPage; this.eGalleryPage = document.getElementById(HTML_ELEMENT_GALLERYPAGE);
			var ePagingLinks; this.ePagingLinks = document.getElementById(HTML_ELEMENT_GALLERYLINKS);
			var sImageSource; this.sImageSource = eElement.getAttribute("id");
			
			var eDiv; this.eDiv = eDiv;
			var eImg; this.eImg = eImg;
			var eLInk; this.eLink = eLink;
			
			// image container
			this.eDiv = document.createElement("div");
			this.eDiv.setAttribute("id", HTML_ELEMENT_GALLERYIMAGE);
			
			// image
			this.eImg = document.createElement("img");
			with (this.eImg) {
				setAttribute("src", DeepDisplay.oGalleryConfig.imgpath + this.eElement.getAttribute("id"));
				style.width = DeepDisplay.oGalleryConfig.imgwidth + "px";
				style.height = DeepDisplay.oGalleryConfig.imgheight + "px";
			}
			this.eDiv.appendChild(this.eImg);
			
			// title
			this.eParagraph = document.createElement("p");
			this.eParagraph.appendChild(document.createTextNode(this.eElement.getElementsByTagName("span")[0].innerHTML));
			this.eDiv.appendChild(this.eParagraph);
			
			this.eGalleryPage.style.display = "none";
			DeepStyle.setOpacity(this.eDiv, 0);
			this.eGalleryViewer.appendChild(this.eDiv);
			
			// thumbnail link
			this.eLink = document.createElement("a");
			this.eLink.setAttribute("id", "thumbnails");
			this.eLink.setAttribute("href", "javascript:void(0)");
			this.eLink.appendChild(document.createTextNode("Thumbnails"));
			this.eLink.onclick = function() {
				document.getElementById("thumbnails").removeNode(true);
				
				var oAttributes = { opacity: { to: 0 } };
				var oGalleryImageAnim = new YAHOO.util.Anim("gallery-image", oAttributes, 0.7);
				oGalleryImageAnim.onComplete.subscribe(function() {
					document.getElementById(HTML_ELEMENT_GALLERYIMAGE).removeNode(true);
					document.getElementById(HTML_ELEMENT_GALLERYPAGE).style.display = "block";
				});
				oGalleryImageAnim.animate();
			};
			this.ePagingLinks.appendChild(this.eLink);
			
			var oAttributes; this.oAttributes = { opacity: { to: 1 } };
			var oGalleryImageAnim; this.oGalleryImageAnim = new YAHOO.util.Anim("gallery-image", this.oAttributes, 0.7);
			this.oGalleryImageAnim.animate();
		};
	};
	
	/*
	closeGallery
	*/
	this.closeGallery = function() {
		var eGalleryViewer; this.eGalleryViewer = document.getElementById(HTML_ELEMENT_GALLERYVIEWER);
		DeepDisplay.bGalleryVisible = false;
		
		// remove all content before animating
		DeepDisplay.removeAllNodes(this.eGalleryViewer);
		
		// yahoo animation attributes
		var oAttributes;
		this.oAttributes = {
			width: { to: 0 },
			height: { to: 0 },
			//top: { to: },
			//left: { to: },
			opacity: { to: 0 }
		};
		var oGalleryAnim; this.oGalleryAnim = new YAHOO.util.Anim("gallery-viewer", this.oAttributes, 0.7, YAHOO.util.Easing.backOut);
		this.oGalleryAnim.onComplete.subscribe(function() { document.getElementById(HTML_ELEMENT_GALLERYVIEWER).removeNode(true) });
		this.oGalleryAnim.animate();
	};
	
	/*
	loadBrowserStyles
	*/
	this.loadBrowserStyles = function() {
		// load stylesheets dependant on browser
		
		if (BrowserDetect.browser == "Safari") {
			var oStyle = document.createElement("style");
			var oImport = document.createTextNode("@import url(\"css/screen_ff.css\");");
			oStyle.appendChild(oImport);
			document.body.appendChild(oStyle);
			
			return;
		}
		
		if (oBrowser.IE)
			document.styleSheets[0].addImport("css/screen_ie.css");
		else {
			var oStyle = document.createElement("style");
			var oImport = document.createTextNode("@import url(\"css/screen_ff.css\");");
			oStyle.appendChild(oImport);
			document.body.appendChild(oStyle);
		}
	};
	
	/*
	assignInputEvents
	*/
	this.assignInputEvents = function() {
		
	};
	
	/*
	parseLocation
	*/
	this.parseLocation = function(sPage) {
		DeepDisplay.sLocation = location.href;
	};
	
	/*
	removeAllNodes
	*/
	this.removeAllNodes = function(eElement) {
		this.eElement = eElement;
		do { if (this.eElement.childNodes.length > 0) this.eElement.removeChild(this.eElement.childNodes[0]) }
		while (this.eElement.childNodes.length > 0);
	};
};


/* ----------------------------------------------------------------------------
	Floating functions that need to be placed into namespaces
---------------------------------------------------------------------------- */
function GoHome() {
	window.location = "?url=/home";
}

function setFlashSize(sID, iNewWidth, iNewHeight) {
	if (BrowserDetect.browser == "Safari") {
		var o = document.getElementById(sID);
		
		/* EP: fixed problem with resizing in Safari on Mac */
		o.style.width = iNewWidth + "px";
		o.style.height = iNewHeight + "px";
		
/*		var oObjects = document.getElementsByTagName("object");
		for (var i=0; i<oObjects.length; i++) {
			//alert("Resizing Flash: " + e + ":" + sID + ":" + e.id + ":" + oObjects[i].id + ":" + oObjects[i].name);
			if (oObjects[e].id == sID) {
				oObjects[e].width = iNewWidth + "px";
				oObjects[e].height = iNewHeight + "px";
				return;
			}
		}*/
		return;
	}
	
	if (oBrowser.IE) {
		var oObjects = document.getElementsByTagName("object");
		for (e in oObjects)
			if (oObjects[e].id == sID) {
				oObjects[e].width = iNewWidth + "px";
				oObjects[e].height = iNewHeight + "px";
				break;
			}
	} else
		if (document.embeds && document.embeds[sID]) {
			document.embeds[sID].style.width = iNewWidth + "px";
			document.embeds[sID].style.height = iNewHeight + "px";
		}
}

function setSideMenuHeight(numItems) {
	var ItemHeight = 22;
	var Height = numItems * ItemHeight + 10;
	setFlashSize("aco-sidemenu", 182, Height);
}

function openForm(strUrl) {
	// open window
	var objWin = window.open(strUrl, "EcardForm", "top=200,left=200,height=550,width=550,location=no,menubar=no,resizable=yes,scrollbars=yes,toolbar=no");
	// and bring the window forward just in case the window already had been opened and in the background.
	objWin.window.focus();
}

function NewWindow(mypage,myname,w,h,scroll){
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	var settings ='height='+h+',';
	settings +='width='+w+',';
	settings +='top='+wint+',';
	settings +='left='+winl+',';
	settings +='scrollbars='+scroll+',';
	settings +='resizable=no';
	win=window.open(mypage,myname,settings);
	if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}

