
//#############################################################################
//##########          Lightbox stuff

var frmrtdef = 50 //  ##########  Frame rate default millisecs
var fdindef = 70 //  ##########  Background opacity fade in Default
var stpsdef = 5 //  ##########  Number of steps default Default
var grybx = new Object()
var timer = new Object()
function init_lightbox(){
	var dvs = document.getElementsByTagName("*")
	var lbxob = new Object()//main light box components
	var lbxcn = new Object()//light box controls
	for(var i=0;i<dvs.length;i++){
		//Pick out main light box components
		if(dvs[i].id && dvs[i].id.substr(0, 3) == "lb_"){
			var m = dvs[i].id.split("_")		
			if(!lbxob[m[1]])lbxob[m[1]] = new Object()
			lbxob[m[1]][m[2]] = dvs[i]
			lbxob[m[1]][m[2]].gbx = grybx						
		}
		//Pick out light box controls
		if(dvs[i].id && dvs[i].id.substr(0, 5) == "lbcn_"){
			var m = dvs[i].id.split("_")		
			if(!lbxcn[m[1]])lbxcn[m[1]] = new Object()
			lbxcn[m[1]][m[2]] = dvs[i]
			lbxcn[m[1]][m[2]].cnob = lbxcn						
		}
	}	
	grybx = lbxob.grey.bx
	for(el in lbxob){
		if(lbxob[el].lnk){
			lbxob[el].lnk.gbx = grybx
			lbxob[el].lnk.onclick = function (){
											this.gbx.show(this.id)
											self.location = "#top"
										}
		}
	}	
	for(el in lbxcn){
		if(lbxcn[el].btn)lbxcn[el].btn.onclick = function (){
										this.cnob.tbclk(this.id)
									}
		if(el == "tckbtns"){
			for(btn in lbxcn[el]){
				lbxcn[el][btn].onclick = function (){
										this.cnob.fmrtclk(this.innerHTML)
									}
			}
		}
		if(el == "fdinbtns"){
			for(btn in lbxcn[el]){
				lbxcn[el][btn].onclick = function (){
										this.cnob.fdinclk(this.innerHTML)
									}
			}
		}
		if(el == "dgsf"){
			for(btn in lbxcn[el]){
				lbxcn[el][btn].onclick = function (){
										this.cnob.dgcrnclk(this.id)
									}
			}			
		}
		if(el == "stps"){
			for(btn in lbxcn[el]){
				lbxcn[el][btn].onclick = function (){
										this.cnob.stpsclk(this.innerHTML)
									}
			}
		}
	}
	lbxcn.gbx = grybx
	lbxob.gbx = grybx
	lbxcn.tbclk = tabclick
	lbxcn.tbclk("lbcn_tbb_btn")
	lbxcn.fmrtclk = frmrate
	lbxcn.fmrtclk(frmrtdef)
	lbxcn.fdinclk = fdinclick
	lbxcn.fdinclk(fdindef)
	lbxcn.dgcrnclk = dgcrnclk
	lbxcn.dgcrnclk("lbcn_dgsf_cntr")
	lbxcn.stpsclk = stpsclk
	lbxcn.stpsclk(stpsdef)
	lbxcn.lbxcntl.sk.onmouseover = function (){
										this.cnob.fade(1)
									}
	lbxcn.lbxcntl.sk.onmouseout = function (){										
										this.cnob.fade(-1)
									}
	lbxcn.lbxcntl.sk.mnmx = Array(3, 10)
	lbxcn.lbxcntl.sk.opi = 3
	lbxcn.lbxcntl.sk.ontck = cnsktck
	timer.cnsk = lbxcn.lbxcntl.sk
	lbxcn.fade = cntlfade
	grybx.lbxob = lbxob
	grybx.cntlob = lbxcn
	grybx.show = gbxshw
	grybx.dspbx = grybx.lbxob.grey.dsp
	grybx.dspcnv = grybx.lbxob.grey.dspcnv
	var gw = grybx.offsetWidth
	var gh = grybx.offsetHeight
	
	// IE 6 only: doesnt get screen height therefore vertically not centred
	if(gh < 200){
		gh = 1400
		grybx.style.height = "1400px"
		
		// force schgcnt (screen height center); point at which centre lb appears
		var schgcnt = 500
	}
	else{
		var schgcnt = gh/4
	}
	grybx.scntr = Array( (gw/2),  schgcnt)
	grybx.odslt = Array((grybx.scntr[0] - (.5*parseInt(grybx.dspbx.style.width))), (grybx.scntr[1] - (.5*parseInt(grybx.dspbx.style.height))) )
	//alert("Lf X Tp\n" + grybx.odslt[0] + " X " + grybx.odslt[1])
	grybx.dspbx.style.left = grybx.odslt[0] + "px"
	grybx.dspbx.style.top = grybx.odslt[1] + "px"
	grybx.odswh = Array(parseInt(grybx.dspbx.style.width), parseInt(grybx.dspbx.style.height))
	grybx.style.display = "none"
	grybx.dspbx.style.display = "none"//
	grybx.onclick = nixlb
	timer.gbx = grybx
	timer.dspbx = grybx.dspbx
	//alert("grey w & h\n" + gw + "\n" + gh)grybx.
	
	//lbxcn.intv = self.setInterval("dotick()", 200)
}
function nixlb(){
	this.show("_", -1)
}
function stpsclk(n){
	for(el in this.stps){
		this.stps[el].style.borderStyle = ((n == this.stps[el].innerHTML) ? "inset" : "outset" )
	}	
	this.nstps = n
}
function dgcrnclk(id){
	for(el in this.dgsf){
		this.dgsf[el].style.borderStyle = ((id == this.dgsf[el].id) ? "inset" : "outset" )
	}
	this.xfrom = ((id.indexOf("tplf") > 0) ? "tl" : "cn")
}
function fdinclick(fdop){
	for(el in this.fdinbtns){
		this.fdinbtns[el].style.borderStyle = ((fdop == this.fdinbtns[el].innerHTML) ? "inset" : "outset" )
	}	
	this.fdop = fdop
}
function frmrate(intvl){
	if(!(this.intvlms && this.intvlms == intvl)){
		this.intvlms = intvl
		if(this.intv)self.clearInterval(this.intv)
		this.intv = self.setInterval("dotick()", this.intvlms)
		for(el in this.tckbtns){
			this.tckbtns[el].style.borderStyle = ((intvl == this.tckbtns[el].innerHTML) ? "inset" : "outset" )
		}
	}
}
function dotick(){
	for(el in timer){
		if(timer[el].actv && timer[el].ontck)timer[el].ontck()
	}
}
function cnsktck(){
	 var nwop = this.stp + this.opi
	 if((nwop - this.mnmx[0])*(this.mnmx[1] - nwop)>=0){
		 setopcint(this, nwop)//
		 //this.innerHTML += "<br/>" + this.id + " to op " + nwop
	 }
	 else{
		 this.actv = false
	 }
}
function cntlfade(n){
	var cnsk = this.lbxcntl.sk 
	cnsk.stp = 1*n
	cnsk.actv = true
}
function gbxshw(id, n){
	if(isNaN(n))n = 1
	var m = id.split("_")
	if(n > 0){
		for(el in this.lbxob){
			if(this.lbxob[el].outer){
				this.lbxob[el].outer.style.display = ((el == m[1]+"") ? "block" : "none")
				//this.lbxob[el].outer.style.width = this.odswh[0] + "px"
			}
		}
	}
	this.style.display = "block"
	this.dspbx.style.display = "block"
	var bgop = this.cntlob.fdop/10
	if(this.actab == "tba"){
		setopcint(this,(n>0?1:3))
		setopcint(this.dspbx,(n>0?1:9))
		this.dspbx.style.width = this.odswh[0] + "px"
		this.dspbx.style.height = this.odswh[1] + "px"
		this.dspbx.style.left = this.odslt[0] + "px"
		this.dspbx.style.top = this.odslt[1] + "px"
		//alert("bgop\n" + bgop)
		this.mnmx = Array(0, bgop)
		this.dspbx.mnmx = Array(0, 10)
		this.ontck = cnsktck
		this.dspbx.ontck = cnsktck
	}
	if(this.actab == "tbb"){// Diagonal set up 
		
		if(n > 0){
			this.dspbx.style.height = "0px"
			this.dspbx.style.width = "0px"
			//alert("xfrom\n" + this.cntlob.xfrom)
			if(this.cntlob.xfrom == "cn"){
				this.dspbx.style.left = this.scntr[0] + "px"
				this.dspbx.style.top = this.scntr[1] + "px"
				this.dspcnv.style.left = -1*this.odswh[0]/2 + "px"
				this.dspcnv.style.top = -1*this.odswh[1]/2 + "px"
			}
		}
		this.pc = (n>0 ? 0 : 10)
		setopcint(this,bgop)
		setopcint(this.dspbx,10)
		this.ontck = diagtck
		this.dspbx.style.overflow = "hidden"
	}
	this.stp = n
	this.dspbx.stp = n
	this.actv = true
	this.dspbx.actv = true/**/
	//alert("showing\n" + id)
}
function diagtck(){
	var stpinc = 10/this.cntlob.nstps
	var npc = (this.pc + stpinc * this.stp)
	if(npc*(10 - npc) >= 0){
		var dw = npc*this.odswh[0]/10
		var dh = npc*this.odswh[1]/10	
		this.dspbx.style.width = dw + "px"
		this.dspbx.style.height = dh + "px"	
		if(this.cntlob.xfrom == "cn"){
			this.dspbx.style.left = (this.scntr[0] - dw/2) + "px"
			this.dspbx.style.top = (this.scntr[1] - dh/2) + "px"
			this.dspcnv.style.left = (dw - this.odswh[0])/2 + "px"
			this.dspcnv.style.top = (dh - this.odswh[1])/2 + "px"
		}
		this.pc = npc
	}
	else{
		this.actv = false
		this.dspbx.style.overflow = "auto"
		if(npc < 0){
			this.style.display = "none"
			this.dspbx.style.display = "none"
			this.dspbx.style.width = this.odswh[0] + "px"
			this.dspbx.style.height = this.odswh[1] + "px"
			this.dspbx.style.left = this.odslt[0] + "px"
			this.dspbx.style.top = this.odslt[1] + "px"
			this.dspcnv.style.left = "0px"
			this.dspcnv.style.top = "0px"
		}
	}
}
function tabclick(id){
	var m = id.split("_")
		for(el in this){
	if(this[el].pgsk && this[el].btn){
			var bl = ("" + el == "" + m[1])
			this[el].sk.style.padding = (bl ? "10px 10px 0px 10px" : "5px 10px 5px 10px")
			this[el].btn.style.fontWeight = bl ? "800" : "300"
			this[el].pgsk.style.display = bl ? "block" : "none"
	}
		}
		this.gbx.actab = m[1]
}

function  setopcint(dv, op){//op 0 -> 10
	//if(dv.style.opacity){}else{}
	dv.op = Math.round(op/10)
	dv.opi = op
	if(op*(10 - op) > 0){
		dv.style.opacity = op/10	
		var ieop =  Math.round(op*10)
		dv.style.filter ='alpha(opacity=' + ieop + ')'	
		if(ieop > 99)dv.style.filter = ''
		if(dv.onopct)dv.onopct()	
	}
	else{
		dv.style.filter = ''
		dv.style.opacity = ''
		dv.style.display = (dv.opi > 5 ? "block" : "none")
	}
return true
}

function tbgrpsInit(){
	init_lightbox()// 
}




