// JavaScript Document

var ZoomImage = {
	$				: function (strID) {return document.getElementById(strID) }
	,RootPath		: ""
	,ImageRootPath	: ""
	,ResizeImage	: false
	,ResizeType		: 1
	,Resize			: {
		1 : {
		 Path			: "includes/getimage.aspx"
		,FileVar		: "file"
		,WidthVar		: "width"
		,Width			: 640
		,HeightVar		: "height"
		,Height			: 480
		,CropVar		: "noCrop"
		,Crop			: 0
		,CacheVar		: "cache"
		,Cache			: 1
		}
	}
	,ImageList 		: new Array("")
	,intIndex		: -1
	,Folder			: ""
	,ResizeToImage	: false
	,CentreImage	: true
	,blnZoomOpen	: false
	,intCurType		: false
	,OnScrollID		: -1
	,ScrollPos		: {
		 Left			: 0
		,Top			: 0
	}
	,Current		: {
		 Index			: -1
		,File			: ""
		,Title			: ""
	}
	,onImageLoad	: null
	,GetResizePath	: function (strFilePath) {
		var strPath 	= ""
		var objResize	= this.Resize[this.ResizeType]
		if (objResize) {
			strPath = this.RootPath + objResize.Path + "?" + objResize.FileVar + "=" + strFilePath
			strPath += "&" + objResize.WidthVar + "=" + objResize.Width
			strPath += "&" + objResize.HeightVar + "=" + objResize.Height
			strPath += "&" + objResize.CropVar + "=" + objResize.Crop
			strPath += "&" + objResize.CacheVar + "=" + objResize.Cache
		}
		return strPath
	}
	,Show			: function (strImage,strDesc) {
		if (strDesc == undefined || strDesc == null) { strDesc = ""}
		this.Window = this.$("imagezoom")
		if (hex.BlackOut.Show) {
			hex.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 = 0
		if (this.ImageList.length > 2) {
			for (var i=0;i<this.ImageList.length;i=i+2) {
				if (strImage == this.ImageList[i]) {
					this.intIndex = i
					break;
				}
			}
			
			this.$("imagezoomcontrol_prev").style.display = (this.intIndex == 0) ?  "none" : "block"
			this.$("imagezoomcontrol_next").style.display = (this.intIndex == this.ImageList.length-2) ?  "none" : "block"
		}else{
			if (this.ImageList.length == 0) {
				this.ImageList = new Array(strImage,strDesc)
			}
			this.$("imagezoomcontrol_prev").style.display = "none"
			this.$("imagezoomcontrol_next").style.display = "none"
		}

		this.Change(0)
		
		/*if ( this.ImageList[this.intIndex+1] != "") {
			this.$("imagezoomtitle").innerHTML = this.ImageList[this.intIndex+1]
			this.$("imagezoomtitle").style.display = "block"
		}else{
			this.$("imagezoomtitle").innerHTML = ""
			this.$("imagezoomtitle").style.display = "none"
		}*/
		
		//this.$("imagezoomcontrol_prev").style.display = (this.ImageList.length > 1) ? "block" : "none"
		//this.$("imagezoomcontrol_next").style.display = (this.ImageList.length > 1) ? "block" : "none"
		return false
	}
	,Close			: function () {
		this.$("imagezoom").style.display = "none"
		if (hex.BlackOut.Hide) {
			hex.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.Centre()
		if (this.onImageLoad) {
			this.onImageLoad()
		}
	}
	,Change			: function (intDir) {
		if (intDir != 0) {
			this.intIndex += intDir*2
		}
		
		this.$("imagezoomloader").style.display = "block"
		if (this.ResizeImage) {
			this.$("imagezoomimage").src = this.GetResizePath(this.Folder + this.ImageList[this.intIndex] )
			//this.$("imagezoomimage").src = this.RootPath + "includes/getimage.aspx?file=" + this.Folder + this.ImageList[this.intIndex] + "&width=640&height=480&nocrop=1"
		}else{
			this.$("imagezoomimage").src = this.RootPath + this.Folder + this.ImageList[this.intIndex]
		}
		this.SetOnLoad()
		this.$("imagezoomcontrol_prev").style.display = (this.intIndex == 0) ?  "none" : "block"
		this.$("imagezoomcontrol_next").style.display = (this.intIndex == this.ImageList.length-2) ?  "none" : "block"
		if ( this.ImageList[this.intIndex+1] != "") {
			this.$("imagezoomtitle").innerHTML = this.ImageList[this.intIndex+1]
			this.$("imagezoomtitle").style.display = "block"
			this.$("imagezoomimage").alt = this.ImageList[this.intIndex+1]
		}else{
			this.$("imagezoomtitle").innerHTML = ""
			this.$("imagezoomtitle").style.display = "none"
			this.$("imagezoomimage").alt = ""
		}
		this.Current.Index = this.intIndex
		this.Current.Title = this.ImageList[this.intIndex+1]
		this.Current.File = this.ImageList[this.intIndex]
		return false
	}
	,Centre			: 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 intImageWidth = hex.$("imagezoomimage").width
		var intImageHeight = hex.$("imagezoomimage").height
		
		var intFrameWidth	= 640
		var intFrameHeight	= 480
		
		if (this.ResizeToImage) {
			//this.$("imagezoomtitle").style.display = "block"
			//this.$("imagezoomtitle").innerHTML = this.$("imagezoomimage").width
		}else if(this.CentreImage){
			var intImageLeft = (intFrameWidth - intImageWidth) / 2
			var intImageTop	= ((intFrameHeight+20) - intImageHeight) / 2
			hex.$("imagezoomimage").style.marginLeft = intImageLeft + "px"
			hex.$("imagezoomimage").style.marginTop = intImageTop + "px"
		}
	
		var intType = (hex.$("imagezoomimage").width == 480) ? 1 : 0
		intType = 0
	
		/*hex.$("imagezoom").style.width = (intType == 1) ? "490px" : "660px"
		hex.$("imagezoom").style.height = (intType == 1) ? "660px" : "490px"
		hex.$("imagezoomcontents").style.width = (intType == 1) ? "500px" : "660px"
		hex.$("imagezoomcontents").style.height = (intType == 1) ? "660px" : "500px"
		hex.$("imagezoomtitle").style.marginLeft = (intType == 1) ? "140px" : "220px"
		*/	
		var intLeft = (intWinWidth/2) - (intFrameWidth/2)
		var intTop = (intWinHeight/2) - (intFrameHeight/2)
		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;
	}
	
}