// JavaScript Document

var ZoomImage = {
	$				: function (strID) {return document.getElementById(strID); }
	,RootPath		: ""
	,ImageRootPath	: ""
	,ResizeImage	: true
	,ResizeType		: 1
	,Resize			: {
		1 : {
		 Path			: "includes/getimage.asp"
		,FileVar		: "file"
		,PathVar		: "path"
		,WidthVar		: "width"
		,Width			: 640
		,HeightVar		: "height"
		,Height			: 480
		,CropVar		: "crop"
		,Crop			: 0
		,CacheVar		: "cache"
		,Cache			: 1
		,TempVar		: "tempfolder"
		,Temp			: "_temp"
		}
	}
	,ImageList 		: new Array("")
	,intIndex		: -1
	,Folder			: ""
	,ResizeToImage	: true
	,CentreImage	: true
	,blnZoomOpen	: false
	,intCurType		: false
	,OnScrollID		: -1
	,ScrollPos		: {
		 Left			: 0
		,Top			: 0
	}
	,Current		: {
		 Index			: -1
		,File			: ""
		,Title			: ""
		,ID				: ""
	}
	,Images		: {
		Count		: -1
		,Length		: 0
		,Add			: function (strFileName,objVars) {
			if (strFileName != undefined && (strFileName != "")) {
				this.Count += 1;
				this.Length += 1;
				this[this.Count] = {
					 File		: strFileName
					,ID			: ""
					,Path		: ""
					,Title		: ""
					,Alt		: ""
					,Details	: ""
				}
				if (objVars != undefined) {
					for (var objItem in objVars) {
						this[this.Count][objItem] = objVars[objItem];
					}
				}
				return this[this.Count]
			}
		}
		,FromArray	: function (arrImages) {
			for (var i=0;i<arrImages.length;i=i+3) {
				var strFullPath = arrImages[i];
				var strID		= (arrImages[i+1] == "") ? i : arrImages[i+1];
				var strTitle	= arrImages[i+2];
				var arrPath 	= strFullPath.split("/");
				
				var strFileName = arrPath[arrPath.length -1];
				var strPath		= strFullPath.replace(strFileName,"");
				
				this.Add(strFileName,{ID : strID, Path : strPath, Title : strTitle});
			}
		}
		,Search		: function (strSearch,strSearchType) {
			if (strSearchType == undefined || strSearchType == null || strSearchType == "") {
				strSearchType = "File";
			}
			for (var i=0;i<this.Length;i++) {
				if (this[i][strSearchType] == strSearch) {
					return i;
					break;
				}
			}
			return -1
		}
		
	}
	,onImageLoad	: null
	,GetResizePath	: function (strFileName,strFilePath) {
		var strPath 	= "";
		var objResize	= this.Resize[this.ResizeType];
		
		if (objResize) {
			strPath = this.RootPath + objResize.Path + "?" + objResize.FileVar + "=" + strFileName;
			
			if (strFilePath != undefined) {
				strPath += "&" + objResize.PathVar + "=" + "../" + strFilePath;
			}
			strPath += "&" + objResize.WidthVar + "=" + objResize.Width;
			strPath += "&" + objResize.HeightVar + "=" + objResize.Height;
			strPath += "&" + objResize.CropVar + "=" + objResize.Crop;
			strPath += "&" + objResize.CacheVar + "=" + objResize.Cache;
			strPath += "&" + objResize.TempVar + "=" + objResize.Temp;
		}
		return strPath;
	}
	,Show			: function (strSearch,strSearchType) {
		this.Window = this.$("imagezoom")
		if (this.Images.Count == -1 && (this.ImageList.length > 0)) {
			this.Images.FromArray(this.ImageList);
		}
		if (this.Images.Length > 0) {
			this.$("imagezoomimage").src = ""
			this.$("imagezoomimage").style.display = "none"
			ZoomImage.$("imagezoom").style.width = 210 + "px";
			ZoomImage.$("imagezoom").style.height = 210 + "px";
			ZoomImage.$("imagezoomcontents").style.width = 200 + "px";
			ZoomImage.$("imagezoomcontents").style.height = 200 + "px";
			this.Centre();
			
			if (this.BlackOut.Show) {
				this.BlackOut.Show();
			}
			
			this.Window.style.display = "block";
			this.$("imagezoomloader").style.display = "block";
			this.blnZoomOpen = true;
			
			
			//this.Centre()
			//this.$("imagezoomimage").src = "includes/getimage.aspx?file=../media/" + this.Folder + "/zooms/" + strImage + "&width=640&height=480&nocrop=1"
			this.intIndex = this.Images.Search(strSearch,strSearchType);
			/*if (this.Images.Length > 1) {
				this.$("imagezoomcontrol_prev").style.display = (this.intIndex == 0) ?  "none" : "block"
				this.$("imagezoomcontrol_next").style.display = (this.intIndex == this.Images.Length) ?  "none" : "block"
			}else{
				this.$("imagezoomcontrol_prev").style.display = "none"
				this.$("imagezoomcontrol_next").style.display = "none"
			}*/
			
			this.Change(0);
			return false;
		}else{
			return true;
		}
	}
	,Close			: function () {
		this.$("imagezoom").style.display = "none";
		if (this.BlackOut.Hide) {
			this.BlackOut.Hide();
		}
		this.blnZoomOpen = false;
		return false;
	}
	,SetOnLoad		: function () {
		if (this.$("imagezoomimage").readyState) {
		this.$("imagezoomimage").onreadystatechange = function () {
			if (this.readyState.toString() == "loaded" || this.readyState.toString() == "complete") {
				ZoomImage.Loaded();
			}
		}
		if (this.$("imagezoomimage").readyState.toString() == "loaded" || this.$("imagezoomimage").readyState.toString() == "complete") {
			ZoomImage.Loaded();
		}
		}else{
			this.$("imagezoomimage").onload = function () {
				ZoomImage.Loaded();
			}
			if (this.$("imagezoomimage").complete) {
				ZoomImage.Loaded();
			}
		}
	}
	,Loaded			: function () {
		this.$("imagezoomloader").style.display = "none";
		this.$("imagezoomimage").style.display = "block"
		this.Centre();
		if (this.onImageLoad) {
			this.onImageLoad();
		}
	}
	,Change			: function (intDir) {
		
		if (intDir != 0) {
			this.intIndex += intDir;
		}
		var objImage = this.Images[this.intIndex];

		this.$("imagezoomloader").style.display = "block";
		
		ZoomImage.$("imagezoomloader").style.width = ZoomImage.$("imagezoomcontents").style.width
		if (ZoomImage.$("imagezoom").style.height != "") {
			ZoomImage.$("imagezoomloader").style.height = ((parseInt(ZoomImage.$("imagezoomcontents").style.height,10))/2) + "px"
			ZoomImage.$("imagezoomloader").style.paddingTop = ((parseInt(ZoomImage.$("imagezoomcontents").style.height,10))/2) + "px"
		}
		
		if (this.ResizeImage) {
			this.$("imagezoomimage").src = this.GetResizePath(objImage.File , this.Folder + objImage.Path );
		}else{
			this.$("imagezoomimage").src = this.RootPath + this.Folder + objImage.Path + objImage.File;
		}

		
		this.SetOnLoad();
		this.$("imagezoomcontrol_prev").style.display = (this.intIndex == 0) ?  "none" : "block";
		this.$("imagezoomcontrol_next").style.display = (this.intIndex == this.Images.Count) ?  "none" : "block";
		if (objImage.Title != "") {
			this.$("imagezoomtitle").innerHTML = objImage.Title;
			this.$("imagezoomtitle").style.display = "block";
			this.$("imagezoomimage").alt = objImage.Alt;
		}else{
			this.$("imagezoomtitle").innerHTML = "";
			this.$("imagezoomtitle").style.display = "none";
			this.$("imagezoomimage").alt = "";
		}
		this.Current.Index = this.intIndex;
		this.Current.ID = objImage.ID;
		this.Current.Title = objImage.Title;
		this.Current.File = objImage.File;
		return false;
	}
	,Centre			: function () {
		
		
		var objImageSize 	= ZoomImage.getElementSize(ZoomImage.$("imagezoomimage"))
		var objFrameSize	= ZoomImage.getElementSize(ZoomImage.$("imagezoomcontents"))
		
		var intImageWidth = objImageSize.x;
		var intImageHeight = objImageSize.y;
		
		var intFrameWidth	= (objFrameSize) ? objFrameSize.x 	: 640;
		var intFrameHeight	= (objFrameSize) ? objFrameSize.y	: 480;
		
		if (intImageWidth != 0) {
			ZoomImage.$("imagezoomcontrol").style.display = "block"
			if (intImageWidth != intFrameWidth || intImageHeight != intFrameHeight) {
				intFrameWidth = intImageWidth;
				intFrameHeight = intImageHeight;
				
				
				
				if (this.ResizeToImage && (intImageWidth > 0)) {
					if (hex && (hex.FX)) {
						hex.FX.Resize.Start("imagezoom",{EndWidth: (intFrameWidth+20), EndHeight : (intFrameHeight+20), Centre : true})
						hex.FX.Resize.Start("imagezoomcontents",{EndWidth: (intFrameWidth+10), EndHeight : (intFrameHeight+10), AnchorX : "centre", AnchorY : "centre"})
					}else{
						ZoomImage.$("imagezoom").style.width = intFrameWidth+20 + "px";
						ZoomImage.$("imagezoom").style.height = intFrameHeight+10 + "px";
						ZoomImage.$("imagezoomcontents").style.width = intFrameWidth+10 + "px";
						ZoomImage.$("imagezoomcontents").style.height = intFrameHeight+10 + "px";
					}
				}
				if (this.CentreImage) {
					var intImageLeft = ((intFrameWidth - 10) - intImageWidth) / 2;
					var intImageTop	= ((intFrameHeight - 10) - intImageHeight) / 2;
					ZoomImage.$("imagezoomimage").style.marginLeft = intImageLeft + "px";
					ZoomImage.$("imagezoomimage").style.marginTop = intImageTop + "px";
					
					//ZoomImage.$("imagezoomloader").style.marginLeft = intImageLeft + "px";
					//ZoomImage.$("imagezoomloader").style.marginTop = intImageTop + "px";
				}
			}else{
					
			}
			ZoomImage.MoveToCentre()
		//hex.Effects.doResize($,startWidth,startHeight,endWidth,endHeight,steps,interval,blnCentre,onComplete,strAnchorX,strAnchorY,hideOnComplete)	
		}else{
			ZoomImage.MoveToCentre()
		}
		if (intFrameWidth > 0) {
			ZoomImage.$("imagezoomloader").style.width = (intFrameWidth-50) + "px";
			ZoomImage.$("imagezoomloader").style.height = ((intFrameHeight+20)/2) + "px"
			ZoomImage.$("imagezoomloader").style.paddingTop = ((intFrameHeight+20)/2) + "px"
		}
		
	}
	,MoveToCentre	: function () {
		var blnIE = (window.innerHeight > 0) ? false : true;
		var intWinHeight = (blnIE) ? document.documentElement.clientHeight : window.innerHeight;
		var intWinWidth	= (blnIE) ? document.documentElement.clientWidth : window.innerWidth;
		var objFrameSize	= ZoomImage.getElementSize(ZoomImage.$("imagezoomcontents"))
		var intFrameWidth	= (objFrameSize) ? objFrameSize.x 	: 640;
		var intFrameHeight	= (objFrameSize) ? objFrameSize.y	: 480;
		
		if (intWinHeight == 0) intWinHeight = document.body.offsetHeight
		if (intWinWidth == 0) intWinWidth = document.body.offsetWidth
		//alert(document.body.offsetHeight)
		
		intFrameWidth = (intFrameWidth == 0) ? 		50 : intFrameWidth
		intFrameHeight = (intFrameHeight == 0) ? 	50 : intFrameHeight
	
		var intLeft = (intWinWidth/2) - (intFrameWidth/2);
		var intTop = (intWinHeight/2) - (intFrameHeight/2);
		
		if (intLeft < 0) intLeft = 0
		if (intTop < 0) intTop = 0
				
		var objSrollPos = ZoomImage.GetScrollPos();
				
		ZoomImage.$("imagezoom").style.left	= ((intLeft) + objSrollPos.Left) + "px";
		ZoomImage.$("imagezoom").style.top	= ((intTop) + objSrollPos.Top) + "px";
	}
	,OnScroll		: function () {
		if (ZoomImage.blnZoomOpen) {
			if (ZoomImage.OnScrollID != -1) {
				window.clearTimeout(ZoomImage.OnScrollID);
			}
			ZoomImage.OnScrollID = window.setTimeout(ZoomImage.Centre,500);
		}
	}
	,GetScrollPos	: function () {
		if (typeof window.pageYOffset != 'undefined') {
			this.ScrollPos = { Left : window.pageXOffset, Top : window.pageYOffset};
		}else if (typeof document.documentElement.scrollTop != 'undefined' && document.documentElement.scrollTop > 0) {
			this.ScrollPos = { Left : document.documentElement.scrollLeft, Top : document.documentElement.scrollTop};
		}else if (typeof document.body.scrollTop != 'undefined'){
			this.ScrollPos = { Left : document.body.scrollLeft, Top : document.body.scrollTop};
		}
		return this.ScrollPos;
	}
	,BlackOut : {
		Version		: "1.2.0.2"
	,ID			: "blackout"
	,Depth		: 900
	,Colour		: "#000000"
	,Opacity	: 0.5
	,onClick	: null
	,Created	: false
	,Animate	: false
	,Width		: null
	,Height		: null
	,ActualWidth 	: null
	,ActualHeight 	: null
	,FullWidth		: null
	,FullHeight		: null
	,blnIE		: null
	,$			: function () {
		return	(this.Created) ? document.getElementById(this.ID) : null;
	}
	,Initialise	: function () {
		//hex.Log.Add("Blackout","Initialising: ID = '[$" + this.ID + "$]', Version: [$" + this.Version + "$]");
		//hex.Versions.Add(this.ID,this.Version)
	}
	,Fade		: {
		 StartOpacity 	: 0
		,Steps			: 20
		,Interval		: 25
	}
	,Show		: function () {
		this.Create()
		this.$().style.display = "block";
	}
	,Hide		: function () {
		this.$().style.display = "none";

	}
	,GetWidth		: function (blnIngnoreContents) {
		this.blnIE = (window.innerWidth > 0) ? false : true
		if (blnIngnoreContents == null) {blnIngnoreContents = false}
		var intWinWidth = (this.blnIE) ? document.documentElement.clientWidth : window.innerWidth;
		var intBodyWidth = (this.blnIE) ? document.body.scrollWidth : document.body.scrollWidth;
		this.Width = (!blnIngnoreContents && (intBodyWidth > intWinWidth)) ? intBodyWidth : intWinWidth;
		this.ActualWidth = intWinWidth;
		this.FullWidth	 = intBodyWidth;
		//hex.Log.Add("Window","Getting Window Width: [$" + this.Width + "$]");
		return this.Width;
	 }
	,GetHeight		: function (blnIngnoreContents) {
		this.blnIE = (window.innerWidth > 0) ? false : true
		if (blnIngnoreContents == null) {blnIngnoreContents = false}
		var intWinHeight = (this.blnIE) ? document.documentElement.clientHeight : window.innerHeight;
		var intBodyHeight = (this.blnIE) ? document.body.scrollHeight : document.body.scrollHeight;
		if (intWinHeight == 0) intWinHeight = document.body.offsetHeight
		this.Height = (!blnIngnoreContents && (intBodyHeight > intWinHeight)) ? intBodyHeight : intWinHeight;
		this.ActualHeight = intWinHeight;
		this.FullHeight	 = intBodyHeight;
		//hex.Log.Add("Window","Getting Window Height: [$" + this.Height + "$]");
		return this.Height;
		
	}
	,Create		: function () {
		if (!this.Created) {
			var objBlackout = document.createElement("div");
			objBlackout.id	= this.ID;
			objBlackout.style.backgroundColor = this.Colour;
			objBlackout.style.position = "absolute";
			objBlackout.style.zIndex = this.Depth;
			objBlackout.style.width = "100%";
			objBlackout.style.height = ((document.body.offsetHeight < this.GetHeight()) ? this.GetHeight() : document.body.offsetHeight) + "px";
			objBlackout.style.opacity = this.Opacity;
			objBlackout.style.filter = "Alpha(Opacity='" + (this.Opacity *100) + "')";
			objBlackout.style.display = "none";
			objBlackout.style.left = 0;
			objBlackout.style.top = 0;
			objBlackout.style.right = 0;
			objBlackout.style.bottom = 0;
			document.body.insertBefore(objBlackout,document.body.childNodes[0]);
			objBlackout.onclick = this.onClick;

			this.Created = true;
		}
	}
	,Refresh	: function () {
		if (this.Created) {
			this.$().style.backgroundColor = this.Colour;
			this.$().style.zIndex = this.Depth;
			this.$().style.width = "100%";
			this.$().style.height = ((document.body.offsetHeight < this.GetHeight()) ? this.GetHeight() : document.body.offsetHeight) + "px";
			this.$().style.opacity = this.Opacity;
			this.$().style.filter = "Alpha(Opacity='" + (this.Opacity *100) + "')";
		}
	}
	}
	,getElementWidth	: function (objElement) {
		var blnIE = (window.innerWidth > 0) ? false : true
		if (objElement == "window") {
			objElement = (blnIE) ? document.body : window
		}
		if (objElement != null) {
			return (blnIE) ? objElement.offsetWidth : objElement.clientWidth
		}else{
			return -1
		}
	}
	,getElementHeight	: function (objElement) {
		var intReturn = 0
		if (objElement != null) {
			var blnIE = (window.innerHeight > 0) ? false : true
			if (objElement == "window") {
				intReturn = (blnIE) ? document.body.offsetHeight : window.innerHeight
				intReturn = (blnIE) ? document.documentElement.clientHeight : window.innerHeight
				if (intReturn == 0) intReturn = document.body.offsetHeight
			}else{
				intReturn = (blnIE) ? objElement.offsetHeight : objElement.clientHeight
			}
			return intReturn
		}else{
			return -1
		}
	}
	,getElementSize : function (objElement) {
		var intWidth = this.getElementWidth(objElement)
		var intHeight =  this.getElementHeight(objElement)
		
		return {x:intWidth, y:intHeight};
	
	}
}
