

tdi_callouts = {
	vars:{
		curOn:0,
		TO:0,
		buttons:{}
	},
	utils:0,
	autoFuns:{
		main:function(oPar, sName){
			this.par = oPar
			this.name = sName
			this.site = oPar.par
			this.inish = function(oSelf){
				this.self = oSelf
			}
			this.run = function(){
				var targ = document.getElementById("tdi_callOutDIV")
				
				while(targ){
					if(targ.length){
						var cur= targ[0]
					} else {
						var cur = targ
					}
					
					var config = cur.getAttribute("tdi_config")
					
					
					
					if(config){
						eval("config = {"+config+"}")
					} else {
						config = {l:0,t:0,r:0,b:0}
					}
					
					var cn = this.site.utils.findChildren(cur, 0, 0)
					var pn = cur.parentNode
					for(var i=0;i<cn.length;i++){
					
						var c = document.body.appendChild(cn[i].cloneNode(1))
						var b = c.id.split("_")
						b.pop()
						var b = document.getElementById(b.join("_"))
						if(b){
						    this.par.vars.buttons[b.id] = new this.par.funs.callOut(this.par, this.par.name, this.site, c, b, pn, {l:config.l, t:config.t, r:config.r, b:config.b})
						    this.par.vars.buttons[b.id].inish(this.par.vars.buttons[b.id])
						}
						
						
					}
					pn.removeChild(cur)
					targ = document.getElementById("tdi_callOutDIV")
				}
			}
		},
		load:function(oPar, sName){
			this.par = oPar
			this.name = sName
			this.inish = function(oSelf){
				this.self = oSelf
				this.par.par.vars.events.load[this.par.name] = oSelf
			}
			this.run = function(bAllLoad){
				//if(bAllLoad){
					this.par.main.run()
					delete this.par.par.vars.events.load[this.par.name]
				//}
			}
		}
		
	},
	funs:{
		callOut:function(oPar, sName, oSite, oObj, oButton, oParent, config){
			
			this.par = oPar
			this.name = sName+"_"+(new Date).getTime()
			this.site = oSite
			this.obj = oObj
			this.dims = 0
			
			this.button = oButton
			this.parent = oParent
			
			this.config = config
			
			this.bIsCenter = 0
			if(this.config.l == "c"){
			   this.bIsCenter = 1
			   this.config.l = this.config.r = 0
		    } 
			
			this.subCon = this.site.utils.findChildren(oObj, 0, 0)[0]
			var cn = this.site.utils.findChildren(this.subCon, 0, 0)
			this.tArrow = cn[0]
			this.textCon = cn[1]
			this.bArrow = cn[2]
			
			
			
			//this.tArrowD = this.site.utils.getPos(cn[0])
			//this.bArrowD = this.site.utils.getPos(cn[2])
			
			this.hideTO = 0
			
			this.name = this.site.zMinder.add(this.name, [oObj])
			
			
			
			
			
			this.inish = function(oSelf){
				this.self = oSelf
				this.fun = {
					mouseEvents:function(event){
						oSelf.run(event)
					},
					timeOut:function(){
						oSelf.show()
					},
					hide:function(){
						oSelf.hide()
					},
					cancelMouse:function(event){
						event.cancelBubble = true
						event.returnValue = false
						if(!oSelf.site.vars.isIE){
							event.stopPropagation();
							event.preventDefault();
						}
						return false
					}	
				}
				this.site.utils.addListener(this.button, ["mouseover", "mouseout", "mousedown"], this.fun.mouseEvents)
				
			}
			this.run = function(event){
				if(!this.dims) this.getDims()
				if(event.type == "mouseover"){
					if(this.par.vars.curOn != this.self){
						if(this.par.vars.curOn) this.par.vars.curOn.hide()
						clearTimeout(this.par.vars.TO)
						this.par.vars.TO = setTimeout(this.fun.timeOut, 500)
					}
				} else {
					this.hide()
				}
			}
			
			this.getDims = function(){
				var tBody = this.site.utils.findChildren(this.textCon, "tbody", 1)[0]
				this.margins = this.site.utils.getPos(tBody.rows[1].cells[1])
				this.conDims = this.site.utils.getPos(this.textCon)
				this.tArrowDims = this.site.utils.getPos(this.tArrow)
				this.bArrowDims = this.site.utils.getPos(this.bArrow)
				this.dims = {
				    w:this.textCon.offsetWidth,
				    h:this.textCon.offsetHeight,
				    tAh:Math.abs(this.tArrowDims.t), 
				    tAw:this.tArrow.offsetWidth, 
				    bAh:this.bArrowDims.b - this.conDims.b,
				    bAw:this.bArrow.offsetWidth,
				    tAl:this.margins.l+this.tArrow.offsetWidth/2,
				    tAr:this.margins.r-this.tArrow.offsetWidth/2,
				    bAl:this.margins.l+this.bArrow.offsetWidth/2,
				    bAr:this.margins.r-this.bArrow.offsetWidth/2
				}
				this.subCon.style.height = this.obj.style.height = this.textCon.offsetHeight+"px"
				this.subCon.style.width = this.obj.style.width = this.textCon.offsetWidth+"px"
			}
			
			this.hide = function(){
				clearTimeout(this.par.vars.TO)
				clearTimeout(this.hideTO)
				this.site.zMinder.pull(this.name)
				this.tArrow.style.visibility = this.bArrow.style.visibility = this.obj.style.visibility = "hidden"
				this.par.vars.curOn = 0
			}
			
			this.show = function(){
				var bDims = this.site.utils.getPos(this.button)
				var pDims = this.site.utils.getPos(this.parent)
				var wDims = this.site.utils.getWinDims()
				
				
				this.tArrow.style.visibility = this.bArrow.style.visibility = "hidden"
				
				var bb = bDims.b + this.dims.tAh + this.config.b //(this.dims.h+this.dims.tAh)
				var tt = bDims.t - (this.dims.h+this.dims.bAh) + this.config.t
				var t = bb
				
				
				
				
				if(t > pDims.b && tt >= pDims.b) t = tt
			    if(t < wDims.t && bb < wDims.b) t = bb
			    if(((t + this.dims.h + this.dims.tAh) > wDims.b) && (tt > wDims.t)) t  = tt
				if(t < 0) t = bb
				
				var l = -1
				var lC = 0
				var lL = bDims.l+this.config.l 
				var lR = bDims.r+this.config.r
				
				if(t == tt){
				    lL-= this.dims.tAl
				    lC= (this.dims.tAw/2)
				    lR-= this.dims.tAr
				} else {
				    lL-= this.dims.bAl
				    lC= (this.dims.bAw/2)
				    lR-= this.dims.bAr
				}
				
				if(this.bIsCenter){
				    var l = (bDims.l+(this.button.offsetWidth/2))-(this.dims.w/2)
				    
				    var m = (this.dims.w/2)-lC
				    
				} else {
				    l = lL
				    if(l + this.dims.w > pDims.r) l = lR //|| (l+this.dims.w > wDims.r)) l = lR
				    var rem = wDims.r-(l+this.dims.w)
				    if(rem < 0){
				        if(-rem > this.button.offsetWidth) rem = -this.button.offsetWidth
				        l += rem
				        lR = l
				    }
				    rem = l-wDims.l
				    if(rem < 0){
				        if(-rem > this.button.offsetWidth) rem = -this.button.offsetWidth
				        l += rem
				        lL = l
				    }
				    var m = this.margins.l
				    if(l == lR){
				        m = this.margins.r-this.tArrow.offsetWidth
				        if(t == bb) m = this.margins.r-this.bArrow.offsetWidth
				    }
				}
				this.tArrow.style.left = this.bArrow.style.left = m +"px"
				
				this.obj.style.top = t+"px"
				this.obj.style.left = l+"px"
				if(t == tt){
				    this.bArrow.style.visibility  = ""
				} else {
				    this.tArrow.style.visibility = ""
				}
				this.obj.style.visibility = "visible"
				
				/*
				var w = this.conDims.r-this.conDims.l
				var h = this.conDims.b-this.conDims.t
				
				var tAh = Math.abs(this.tArrowDims.t)
				var tAw = this.tArrowDims.r - this.tArrowDims.l
				var bAh = this.bArrowDims.b - this.conDims.b
				var bAw = this.bArrowDims.r - this.bArrowDims.l
				
				
				var dl = bDims.l+w+this.config.l
				var dt = bDims.t - (h+bAh)+this.config.t
				var dr = bDims.r-w+this.config.r
				var db = bDims.b +h+tAh+this.config.b
				
				this.tArrow.style.visibility = this.bArrow.style.visibility = "hidden"
				
				
				
				if(db < pDims.b){
					var t = db-h
					var aw = tAw
					this.tArrow.style.visibility = ""
				} else {
					var t = dt
					var aw = bAw
					this.bArrow.style.visibility = ""
				}
				
				if(dr > pDims.l){
					var l = dr
					var m = this.margins.r-this.margins.l-(aw/2)
				}
				if(dl < pDims.r){
					var l = bDims.l
					var m = this.margins.l
				}
				
				
				
				this.tArrow.style.left = this.bArrow.style.left = m+"px"
				this.obj.style.top = t+"px"
				this.obj.style.left = l+"px"
				
				
				
				this.obj.style.visibility = "visible"
				this.par.vars.curOn = this.self	
				*/
				this.site.zMinder.push(this.name)
				
			}
		}
	},
	inish:tdi_site.funs.genInish
}

tdi_site.autoFuns["callOuts"] = tdi_callouts