// JavaScript Document
var objLastViewed = {
	 Images 	: {}
	,Add 		: function (intID,strImage) {
		this.Images[intID] = {
			 Original	: null
			,HoverImage	: strImage
		}
	}
	,SwapImage : function (intID,blnHover) {
		var objImage = hex.$("last_viewed_"+intID)
		if (this.Images[intID] && (objImage)) {
			if (this.Images[intID].Original == null) {
				this.Images[intID].Original = objImage.src
			}
			objImage.src = (blnHover) ? this.Images[intID].HoverImage : this.Images[intID].Original
		}
	}
}
var objWindow	= {
	Window		: {
		 Width 		: 0
		,Height		: 0
	}
	,Size		: {
		 Width 		: 0
		,Height		: 0
	}
	,Open		: function (strID,objSize) {
		this.Window.Width = hex.Window.ActualWidth
		this.Window.Height = hex.Window.ActualHeight
		this.Size = {
			 Width 	: (objSize.Width < -1) ? this.Window.Width + objSize.Width : objSize.Width
			,Height : (objSize.Height < -1) ? this.Window.Height + objSize.Height : objSize.Height
		}
		
		if (this.Size.Width < objSize.MinWidth) {
			this.Size.Width  = objSize.MinWidth
		}
		if (this.Size.Height < objSize.MinHeight) {
			this.Size.Height = objSize.MinHeight
		}
		if (objSize.FitToWindow) {
			this.Size.Width = this.Window.Width
			this.Size.Height = this.Window.Height
		}
		if (objSize.FitToWindowWidth) {
			this.Size.Width = this.Window.Width
		}
		if (objSize.FitToWindowHeight) {
			this.Size.Height = this.Window.Height
		}
		if (objSize.WindowOverFlow != true) {
			this.Size.Width = (this.Size.Width > hex.Window.ActualWidth) ? hex.Window.ActualWidth - 40 :  this.Size.Width 
			this.Size.Height = (this.Size.Height > hex.Window.ActualHeight) ? hex.Window.ActualHeight - 40 :  this.Size.Height 
		}
		
		
		
		hex.$(strID).style.display 	= "block"
		if (this.Size.Width != -1) {
			hex.$(strID).style.width 	= this.Size.Width  + "px"
		}
		if (this.Size.Height != -1) {
			hex.$(strID).style.height 	= this.Size.Height + "px"
		}
		for (var strToResize in objSize.Contents) {
			var objElement = hex.$(strID + "_" + strToResize)
			if (objElement != null) {
				var objToResize = objSize.Contents[strToResize]
				var strWidth = ""
				var strHeight = ""
				for (var objDim in this.Window) {
					if (objToResize[objDim] && (objToResize[objDim] != "")) {
						var strSize = ""
						var intSize = objToResize[objDim]
						if (!isNaN(intSize)) {
							if (intSize < -1 || intSize > 1) {
								strSize = (this.Size[objDim] + intSize)
								if (strSize < -1) {
									strSize = 0
								}
							}else{
								if (intSize < 0) {
									strSize = ((1+intSize)* this.Size[objDim])
								}else{
									strSize = (intSize* this.Size[objDim])
								}
							}
							objToResize["Actual" + objDim] = strSize
							objSize["Actual" + objDim] = strSize
							objElement.style[objDim.toLowerCase()] = strSize + "px"
						}
					}
					if (objToResize["Fixed"+ objDim] && (objToResize["Fixed"+ objDim] != "")) {
						objElement.style[objDim.toLowerCase()] = objToResize["Fixed"+ objDim] + "px"
					}
					//FixedHeight
					
				}
			}
		}
		if (objSize.Position) {
			if (!isNaN(objSize.Position.X)) {
				hex.$(strID).style.left = (((this.Window.Width/2) +  objSize.Position.X)-(this.Size.Width/2)) + "px"
			}
			if (!isNaN(objSize.Position.Y)) {
				hex.$(strID).style.top = (((this.Window.Height/2) +  objSize.Position.Y)-(this.Size.Height/2)) + "px"
			}
			if (!isNaN(objSize.Position.Left)) {
				hex.$(strID).style.left = objSize.Position.Left +"px"
			}
			if (!isNaN(objSize.Position.Top)) {
				hex.$(strID).style.top = objSize.Position.Top +"px"
			}
		}
	}
}
var objMsgBox = {
	ID				: "msg_box"
	,Default		: {
		 Width : 350
		,Height : 125
	}
	,WindowSize 	: {
		 Width 			: 350
		,Height			: 125
		,MinWidth		: -1
		,MinHeight		: -1
		,Contents			: {
			"contents" 			: {Width : 0	, Height 		: 10}
			,"body"				: {Height 		: -76}
			,"main"				: {FixedHeight 	: 55}
		}
		,Position		: {
			 X	: 0
			,Y	: 0
		}
	}
	,Current	: {
		Type 		: 0
		,Open 		: false
		,BlackOut 	: true
		
	}
	,Events		: {
		OnOk		: null
		,OnYes		: null
		,OnNo		: null
	}
	,Initialised : false
	,Initialise : function () { 
		if (!this.Initialised) {
			var strHTML = '<div id="msg_box" style="display: none; z-index: 999;"><div id="msg_box_contents" style="padding: 0 10px;"><div id="msg_box_body">';
			strHTML += '<div id="msg_box_main"><div id="msg_box_message"></div></div>';
			strHTML += '<div id="msg_box_control">';
			strHTML += '<div id="msg_box_ctrl_0"><div  class="btn" onClick="objMsgBox.Close(true)" >OK</div></div>';
			strHTML += '<div id="msg_box_ctrl_1"><a href="#"  class="btn" onClick="objMsgBox.Close(true)" >Yes</a><a href="#"  class="btn" onClick="objMsgBox.Close(false)" >No</a></div>';
			strHTML += '</div></div></div></div>';
			document.body.innerHTML += strHTML
			this.Initialised = true
		}
	}
	,Open		: function (strMsg,objVars){
		this.Initialise()
	
		hex.$Hide("msg_box_ctrl_0")
		hex.$Hide("msg_box_ctrl_1")
		
		
		this.Current.Type = (objVars != undefined && (!isNaN(objVars.Type))) ? objVars.Type : 0
		hex.$Show("msg_box_ctrl_" + this.Current.Type)
		
		this.Events.OnOk = (objVars != undefined && (objVars.OnOk)) 	? objVars.OnOk : null
		this.Events.OnYes = (objVars != undefined && (objVars.OnYes)) 	? objVars.OnYes : null
		this.Events.OnNo = (objVars != undefined && (objVars.OnNo)) 	? objVars.OnNo : null
		
		this.Current.BlackOut = (objVars && (objVars.BlackOut != undefined)) ? objVars.BlackOut : true
		
		//msg_box_ctrl_0
		
		this.WindowSize.Width = (objVars != undefined && (!isNaN(objVars.Width))) ? objVars.Width : this.Default.Width
		this.WindowSize.Height = (objVars != undefined && (!isNaN(objVars.Height))) ? objVars.Height : this.Default.Height
		if (this.Current.BlackOut) {
			hex.BlackOut.Depth = 100
			hex.BlackOut.Show()
		}
		
		objWindow.Open(this.ID,this.WindowSize)
		this.Current.Open = true
		hex.$Text("msg_box_message",strMsg)
	}
	,Close		: function (blnValue){
		if (this.Current.Open) {
			hex.$(this.ID).style.display = "none"
			if (this.Current.BlackOut) {
				hex.BlackOut.Hide()	
			}
		}
		if (this.Current.Type == 0) {
			if (this.Events.OnOk) {
				this.Events.OnOk()
			}
			this.Events.OnOk = null
		}
		if (this.Current.Type == 1) {
			if (blnValue) {
				if (this.Events.OnYes) {
					this.Events.OnYes(blnValue)
				}
			}else{
				if (this.Events.OnNo) {
					this.Events.OnNo(blnValue)
				}
			}
			this.Events.OnOk = null
			this.Events.OnNo = null
		}
	}
}
