tdi_site = {
    vars:{
        isIE:(navigator.userAgent.toLowerCase().search("msie") > -1),
        isFox:(navigator.userAgent.toLowerCase().search("firefox") > -1),
        isMac:(navigator.userAgent.toLowerCase().search("macintosh;") > -1),
        spGif:"/assets/images/sp.gif",
        flash:{
            rel:{
                major:9,
                minor:-1,
                rel:45
            },
            getFlash:0,
            flashMessage:0
        },
        url:{
            path:0,
            search:0
        },
        events:{
        	load:{},
        	mouseup:{},
        	mousemove:{}
        },
        zMinder:{
        	start:100,
        	cur:100,
        	top:101,
        	groups:{},
        	cur:{}
        },
        vInfo:{
            namePlate:0
        },
        eventRem:[]
        
    },
    utils:function(oPar){
        this.par = oPar
        
        this.inish = function(oSelf){
            this.self = oSelf
        }
        
        this.getWinDims = function(){
        
        	if(this.par.vars.isIE){
			w = document.body.clientWidth
			h = document.body.clientHeight
		} else {
			w = window.innerWidth
			h = window.innerHeight
		}
	        //var b = document.getElementsByTagName("body")[0]
	        var sl = document.documentElement.scrollLeft
	        var st = document.documentElement.scrollTop
	        return {w:w,h:h,l:sl,t:st,r:sl+w,b:st+h}
	
	}
        this.addFun = function(addObj, oFuns, bReplace, bReset){
            for(var e in addObj){
                if(addObj[e] && !bReplace) alert("Function "+e+" already exists")
                addObj[e] = oFuns[e]
            }
            if(bReset) oFuns = {}
        }

        this.autoFuns = function(oObj, oPar, bReset){
            for(var e in oObj){
                if(typeof(oObj[e]) == "function"){
                    oPar[e] = new oObj[e](oPar, e)
                    oPar[e].inish(oPar[e])
                } else {
                    oPar[e] = oObj[e]
                    oPar[e].inish(oPar[e], e, oPar)
                    delete oObj[e]
                    
                }
            }
            if(bReset) oObj = {}
        }

        this.testFlash = function(oAry){
            
            var fd = this.par.vars.flash
            
            if(fd.ver){
                if(!oAry) oAry = fd.rel
                for(var e in oAry) if(fd.ver[e] < oAry[e]) return 1
                return 0
            } else {
                return -1
            }   
        }
        
        this.getFlash = function(oObj){
            var ary  = this.par.vars.flash.flashMessage
            if(ary) oObj.innerHTML = ary.join("")
        }
        
        this.findChildren = function(oObj, sTag, bDrill){
            var ary = []
            for(var i=0;i<oObj.childNodes.length;i++){
            	if(oObj.childNodes[i].tagName){
                	if(sTag && oObj.childNodes[i].tagName.toLowerCase() == sTag){
                		ary.push(oObj.childNodes[i])
                	} else {
                		if(!sTag) ary.push(oObj.childNodes[i])
                	}
                	if(bDrill && oObj.childNodes[i].childNodes.length){
				var r = this.findChildren(oObj.childNodes[i], sTag, bDrill)
				while(r.length) ary.push(r.shift())
                	}
                }
            }
            return ary
        }

        this.addListener = function(oObj, oAry, oFun){
        if(!oFun) return
            for(var i =0; i < oAry.length; i++){
                if(this.par.vars.isIE){
		            
                    oObj.attachEvent("on"+oAry[i], oFun)
                } else {
                    oObj.addEventListener(oAry[i], oFun, 0)
                }
            }
         }
        this.removeListener = function(oObj, oAry, oFun){
            for(var i =0; i < oAry.length; i++){
                if(this.par.vars.isIE){
                    oObj.detachEvent("on"+oAry[i], oFun)
                } else {
                    oObj.removeEventListener(oAry[i], oFun, 0)
                }
            }
        }
        
        
        
        this.getElm = function(sElm){
        	return document.getElementById(sElm)
        }
        
        
            
        
        this.noSelect = function(targ, bAllow){
            var ary = ["mousedown"]
            if (this.par.vars.isIE) ary = ["selectstart", "dragstart", "drag"]
            if(bAllow){
                this.removeListener(targ, ary, this.par.voidEvent.run)
            } else {
                this.addListener(targ, ary, this.par.voidEvent.run)
            }
        }
        
        this.arySum = function(sJoin, oAry){
        	return eval(oAry.join(sJoin))
        }
        
        this.getPos = function(oObj, bUseParent){
	        if(typeof(oObj) == "string") oObj = document.getElementById(oObj)
	        var b = document.getElementsByTagName("body")[0]
	        var sl = document.documentElement.scrollLeft
	        var st = document.documentElement.scrollTop
	        if(document.getBoxObjectFor){
		        var r = document.getBoxObjectFor(oObj)
		        var rect = {l:r.x,t:r.y,r:r.width+r.x,b:r.y+r.height}
	        } else{
		        if(oObj.getBoundingClientRect){
			        var r = oObj.getBoundingClientRect()
			        var rect = {l:r.left-2+sl,t:r.top-2+st,r:r.right-2+sl,b:r.bottom-2+st}
		        } else {
			        var l = oObj.offsetLeft
			        var t = oObj.offsetTop
			        var rect = {l:l,t:t,r:l+oObj.offsetWidth,b:t+oObj.offsetHeight}
			        var p = oObj.offsetParent
			        if(bUseParent) p = oObj.parentNode
			        while(p){
				        l = p.offsetLeft
				        t = p.offsetTop
				        if(l){
				        	rect.l += l
				        	rect.r += l
				        }
				        if(t){
				        	rect.t += t
				        	rect.b += t
				        }
				        if(bUseParent){
				        	p = p.parentNode
				        } else {
				        	p = p.offsetParent
				        } 
			        }
		        }
	        }
	        return rect
         }
    },
    autoFuns:{
	
	placeWidget:function(oPar, sName){
		this.par = oPar
		this.name = sName
		this.inish = function(oSelf){
			this.self = oSelf
		}
		this.run = function(sParent, sWidget, sHolder){			
				var p = document.getElementById(sParent)
				var w = document.getElementById(sWidget)
				var h = document.getElementById(sHolder)
				var wC = tdi_site.utils.findChildren(w, "div", 0)[0]
				if(wC){
					w.parentNode.style.overflow = "auto"
					vR = tdi_site.utils.getPos(h)
					pR = tdi_site.utils.getPos(p)
					wCr = tdi_site.utils.getPos(wC)
					wR = tdi_site.utils.getPos(w)
					w.style.position = "absolute"
					w.style.zIndex = "500"
					w.style.left = (pR.l-vR.l-(wCr.l-wR.l))+"px"
					w.style.top = (pR.t-vR.t)+"px"
				} else {
					var self = this.self
					var fun = function(){
						self.run(sParent, sWidget, sHolder)
					}
					setTimeout(fun, 50)
				}
			}
	},		
	
	load:function(oPar, sName){
		this.par = oPar
		this.name = sName
		this.inish = function(oSelf){
			this.self = oSelf
		}
		this.run = function(){
			var targ = this.par.vars.events.load
			for(var i =0; i<2;i++){
				for(var e in targ){
					targ[e].run(i)
				}
			}
		}
	},
	zMinder:function(oPar, sName){
		this.par = oPar
		this.name = sName
		this.z = {
        		start:100,
        		cur:100,
        		top:101,
        		bottom:100,
        		max:0,
        		groups:{},
        		stack:[],
        		lut:{}
        	}
		this.inish = function(oSelf){
			this.self = oSelf
		}
		this.add = function(sName, oGroup){
			iInt = 0
			for(var i=0;i<oGroup.length;i++){
				oGroup[i].style.zIndex = this.z.cur+i
			}	
			if(i > this.z.max) this.z.max = i
			
			var t = (new Date).getTime()
			while(this.z.groups[sName]){
				t++
				sName = sName+"_"+t
			}
			
			this.z.groups[sName] = {
				orig:this.z.cur,
				total:i,
				group:oGroup
			}
			this.z.cur += i
			this.z.top += i
			return sName
		}
		this.push = function(sName){
			var targ = this.z.groups[sName]
			for(var i=0;i<targ.group.length;i++) {
				targ.group[i].style.zIndex = this.z.top+i
			}
			this.z.top += i
			var l = this.z.stack.length
			this.z.stack.push(targ.group)
			this.z.lut[sName] = l
		}
		this.pull = function(sName){
			if(this.z.lut[sName]){
				var l = this.z.lut[sName]
				var targ = this.z.stack.splice(l,1)[0] 
				var z = this.z.groups[sName].orig
				for(var i=0;i<targ.length;i++){
					targ[i].style.zIndex = z+i
				}
				for(var l=l;l<this.z.stack.length;l++){
					for(var k =0;k<this.z.stack[l].length;k++) this.z.stack[l][k].style.zIndex -= i
				}
				this.z.top -= i
				
			}
			delete this.z.lut[sName]
		}
	},
	    
	    voidEvent:function(oPar, sName){
	        this.isIE = oPar.vars.isIE
	        this.inish = function(oSelf){}
	        this.run = function(event){
	            if(oPar.vars.isIE){
	                event.returnValue = false
	            } else {
	                event.preventDefault()
	            }
	        }
	       
	    
            
            
        }
    },
    funs:{
	genInish:function(oSelf, sName, oPar){
		this.self = oSelf
		this.name = sName
		this.par = oPar
		if(oSelf.utils){
                	oSelf.utils = new oSelf.utils(oSelf)
                	oSelf.utils.inish(oSelf.utils)
		}
		oPar.utils.autoFuns(oSelf.autoFuns, oSelf, 1)
		
	},
	setEvents:function(oPar, sEvent){
		this.par = oPar
		this.event = sEvent
		this.ary = oPar.vars.events[sEvent]
		this.lastEvent = {}
		this.inish = function(oSelf){
			var fun = function(event){
				oSelf.run(event)
			}
			this.par.utils.addListener(document, [this.event], fun)
			this.par = 0
		}
		this.run = function(event){
			for(var e in this.ary){
				this.ary[e](event, this.lastEvent)
			}
			
			this.lastEvent = {type:event.type, clientX:event.clientX, clientY:event.clientY}
		}
	}
    },
    inish:function(oSelf, sName, oVinfo){
        this.self = oSelf
        this.name = sName
        oSelf.vars.vInfo = oVinfo.vInfo
        var url = location.toString().split("?")
        oSelf.vars.url.path = url.shift().split(location.host+"/").pop().split("/")
        if(url.length)eval(" oSelf.vars.url.search = {"+url.shift().replace(/=/gi, ":\"").replace(/&/gi, "\",")+"\"}")
        
        oSelf.utils = new oSelf.utils(oSelf)
        oSelf.utils.inish(oSelf.utils)
        oSelf.utils.autoFuns(oSelf.autoFuns, oSelf, 1)
        
        try{
            oSelf.vars.flash.ver = swfobject.getFlashPlayerVersion()
        } catch(e){
            oSelf.vars.flash.ver = 0
        }
        
        oSelf.vars.flash.getFlash = oSelf.utils.testFlash()
        
        for(var e in this.vars.events){
        	if(!oSelf[e]){
        		var r = new this.self.funs.setEvents(oSelf, e)
        		r.inish(r)
        	}
        }
        oSelf.utils.addListener(window, ["load"], new Function(this.name+".load.run()") )
        oSelf.utils.addListener(window, ["unload"], new Function("delete "+this.name) )
    }
}

