/*##panels*/
function LynxPanels(hostDiv){
	this.hostDiv = hostDiv;
	this.panels = new Array();
	this.actual = -1;
	this.over = -1;
}

LynxPanels.prototype._overTrans = function(e,index){
	var coord = eventCoords(e);
	if(this.over!=-1){
		if(this.panels[this.over]._isOver(coord))return;
		else{
			var pane = this.panels[this.over];
			setOpacity(pane.content,pane.inactiveOp);
		}
	}
	for(var i=0; i<this.panels.length; i++){
		if(i==index || i==this.over || i==this.actual)continue;
		var pane = this.panels[i];
		if(pane._isOver(coord)){
			this.over = i;
			setOpacity(pane.content,pane.hoverOp);
			return;
		}
	}
	this.over=-1;
}

LynxPanels.prototype._clickTrans = function(){
	if(this.over==-1)return;
	var temp = this.over;
	this.over = -1;
	this.focus(temp);
}

LynxPanels.prototype._outTrans = function(){
	if(this.over==-1)return;
	var pane = this.panels[this.over];
	setOpacity(pane.content,pane.inactiveOp);
	this.over=-1;
}

LynxPanels.prototype.focus = function(index){
	if(this.actual!=-1)this.panels[this.actual]._defocus();
	this.actual = index;
	this.panels[this.actual]._focus();
}

LynxPanels.prototype.addPane = function(content){
	content.parentNode.removeChild(content);
	this.hostDiv.appendChild(content);
	var pane = new LynxPane(content);
	pane.parent = this;
	pane.index = this.panels.length;
	this.panels.push(pane);
	pane._setCBTrans();
	if(this.actual==-1){
		this.actual = 0;
		pane._focus();
	}else{
		pane._defocus();
	}
}

LynxPanels.prototype.adjustHeight = function(index){
	if(index==undefined){
		var max_height = 0;
		for(var i in this.panels){
			if(this.panels[i].content.offsetHeight>max_height){
				max_height = this.panels[i].content.offsetHeight;
			}
		}
		this.hostDiv.style.height = max_height;
	}else{
		var xdiv = this.panels[index].content;
		if(this.hostDiv.style.height<xdiv.offsetHeight)this.hostDiv.style.height = xdiv.offsetHeight;
	}
}

function LynxPane(content){
	this.content = content;
	this.parent = null;
	this.index = -1;
	this.activeOp = 100;
	this.inactiveOp = 70;
	this.hoverOp = 90;
	this.trans = new Array();
	
	this.onfocus = null;
	this.ondefocus = null;
}

LynxPane.prototype._setCBBlur = function(){
	var xc = this.content.childNodes;
	var _me = this;
	var pattern = new RegExp("transparent");
	for(var i in xc){
		var ele = xc[i];
		if(!pattern.test(ele.className)){
			ele.onmouseover = function(){setOpacity(_me.content,_me.hoverOp);};
			ele.onmouseout = function(){setOpacity(_me.content,_me.inactiveOp);};
			ele.onclick = function(){_me.parent.focus(_me.index);};
		}
	}
}

LynxPane.prototype._setCBTrans = function(){
	var xc = $C2("transparent",null,this.content);
	var _me = this;
	for(var i in xc){
		var ele = xc[i];
		ele.onmousemove = function(e){_me.parent._overTrans(e,_me.index);};
		ele.onmouseout = function(){ _me.parent._outTrans();};
		ele.onclick = function(){ _me.parent._clickTrans();};
		this.trans.push(ele);
	}
}

LynxPane.prototype._setCBFocus = function(){
	var xc = this.content.childNodes;
	var pattern = new RegExp("transparent");
	for(var i in xc){
		var ele = xc[i];
		if(!pattern.test(ele.className)){
			ele.onmouseover = null;
			ele.onmouseout = null;
			ele.onclick = null;
		}
	}
}

LynxPane.prototype._focus = function(){
	if(this.onfocus!=null)this.onfocus();
	this.content.style.zIndex = 3;
	this._setCBFocus();
	setOpacity(this.content,this.activeOp);
}

LynxPane.prototype._defocus = function(){
	if(this.ondefocus!=null)this.ondefocus();
	this.content.style.zIndex = 1;
	this._setCBBlur();
	setOpacity(this.content,this.inactiveOp);
}

LynxPane.prototype._isOver = function(coord){
	if(isAt(coord[0],coord[1],this.content)){
		for(var i in this.trans){
			if(isAt(coord[0],coord[1],this.trans[i]))return false;
		}
		return true;
	}else return false;
}
