function getAttributes(dataObject,element) {
	for (var acount=0;acount<element.attributes.length;acount++) {
		dataObject[element.attributes[acount].name]=element.attributes[acount].value;
	}
}

function popupControlBox(div) {
	this.canvas=div;
	this.canvas.style.display="none";
	this.canvas.className="pb_box";
	this.canvas.style.backgroundImage="url("+div.attributes['theme'].value+"/box_middle.gif)";
	this.note=document.createElement("div");
	this.note.className="pb_note";
	this.note.style.backgroundImage="url("+div.attributes['theme'].value+"/box_top.gif)";
	this.exit=document.createElement("div");
	this.exit.style.display="none";
	this.exit.className="pb_button";
	this.exit.style.backgroundImage="url("+div.attributes['theme'].value+"/box_top.gif)";
	this.exit.innerHTML="<a href='javascript:"+this.id+".hide()'>Close X</a>";
	this.label=document.createElement("div");
	this.label.className="pb_label";
	this.content=document.createElement("div");
	this.content.className="pb_content";
	this.content.style.backgroundImage="url("+div.attributes['theme'].value+"/box_bottom.gif)";
	this.canvas.innerHTML="";
	this.canvas.appendChild(this.note);
	this.canvas.appendChild(this.exit);
	this.canvas.appendChild(this.label);
	this.canvas.appendChild(this.content);
}

function popupControlList(list) {
	list.className="pb_list";
	list.style.listStyleImage="";
	var items=list.getElementsByTagName("li");
	for (var icount=0;icount<items.length;icount++) {
		this.items[this.items.length]=new PopupItem(items[icount],this,"list");
	}
	if (!list.attributes['label'].value) return;
	newLi=document.createElement("li");
	newLi.className="pl_label";
	newLi.style.fontWeight=900;
	newLi.innerHTML=list.attributes['label'].value;
	list.insertBefore(newLi,list.firstChild);
}

function popupControlBar(div) {
	div.className="pb_bar";
	var spans=div.getElementsByTagName("span");
	for (var scount=0;scount<spans.length;scount++) {
		if (spans[scount].parentNode!=div) continue;
		this.items[this.items.length]=new PopupItem(spans[scount],this,"bar");
	}
	if (!div.label) return;
	div.insertBefore(document.createElement("br"),div.firstChild);
	newSpan=document.createElement("span");
	newSpan.className="pl_label";
	newSpan.style.fontWeight=900;
	newSpan.innerHTML=div.label;
	div.insertBefore(newSpan,div.firstChild);
}

function PopupItem(span,parent,type) {
	this.type=type;
	this.label="";
	this.note="Click at current location to lock this panel.";
	this.link="";
	this.target="";
	this.image=""
	this.hover="";
	this.active="";
	this.content=span.innerHTML;
	getAttributes(this,span);
	if (!this.hover) this.hover=this.image;
	if (!this.active) this.active=this.hover;
	overFx=parent.id+".show("+parent.items.length+")";
	outFx=parent.id+".hide()";
	span.innerHTML="<img /><a onMouseOver='"+overFx+"' onMouseOut='"+outFx+"'><span>"+this.label+"</span><img /></a>";
	this.hotspot=span;
	this.bullet=this.hotspot.getElementsByTagName("img")[0];
	this.anchor=this.hotspot.getElementsByTagName("a")[0];
	this.button=this.anchor.getElementsByTagName("img")[0];
	this.anchorText=this.anchor.getElementsByTagName("span")[0];
	this.hotspot.className="pb_item";
	this.bullet.className="pb_bullet";
	this.bullet.src=parent.bullets["blank"];
	this.bullet.width=7;
	this.bullet.height=10;
	this.anchor.style.cursor="default";
	this.anchor.className="pb_link";
	this.anchor.href="javascript:"+parent.id+".toggleLock()";
	if (this.link) {
		this.anchor.href=this.link;
		this.note="Click at current location to follow link.";
	}
	if (this.target) this.anchor.target=this.target;
	this.button.className="pb_button";
	this.button.src=this.image;
	this.anchor.appendChild(this.button);
	if (this.image) {
		this.anchorText.style.display="none";
		this.hotspot.style.verticalAlign="middle";
	} else {
		this.button.style.display="none";
	}
	if (type=="list") {
		var tempSpace=document.createElement("span");
		tempSpace.innerHTML="&nbsp;";
		this.hotspot.insertBefore(tempSpace,this.hotspot.firstChild);
		this.hotspot.insertBefore(this.bullet,this.hotspot.firstChild);
		this.anchor.style.textDecoration="none";
	} else {
		this.bullet.style.display="none";
		this.anchor.style.cursor="hand";
	}
	if (!this.link && !this.content) {
		this.hotspot.insertBefore(this.anchorText,this.anchor);
		this.hotspot.removeChild(this.anchor);
	}
}

function popupControlData(label,content,note) {
	this.label.innerHTML=label;
	if (this.label.innerHTML=="undefined") {
		this.label.innerHTML="";
	}
	this.content.innerHTML=content;
	this.note.innerHTML=note;
	if (this.note.innerHTML=="undefined") {
		this.note.innerHTML="Click at current location to lock this panel.";
	}
}

function popupControlShow(index) {
	this.hover=index;
	this.items[this.hover].bullet.src=this.bullets["hover"];
	this.items[this.hover].button.src=this.items[this.hover].hover;
	if (this.active!=-1) return;
	this.data(this.items[this.hover].label,this.items[this.hover].content,this.items[this.hover].note);
	if (this.items[this.hover].type=="link") return;
	if (!this.items[this.hover].content) return;
	this.tempColor=this.canvas.parentNode.style.color;
	this.canvas.parentNode.style.color="bfbfbf";
	this.canvas.style.display="block";
}

function popupControlHide() {
	if (this.hover==-1) {
		this.toggleLock();
	} else if (this.hover==this.active) {
		this.items[this.hover].bullet.src=this.bullets["active"];
		this.items[this.hover].button.src=this.items[this.hover].active;
	} else {
		this.items[this.hover].bullet.src=this.bullets["blank"];
		this.items[this.hover].button.src=this.items[this.hover].image;
	}
	this.hover=-1;
	if (this.active!=-1) return;
	this.canvas.style.display="none";
	this.canvas.parentNode.style.color=this.tempColor;
}

function popupControlToggleLock() {
	if (this.hover==-1) {
		this.exit.style.display="none";
		this.note.style.display="block";
		this.items[this.active].bullet.src=this.bullets["blank"];
		this.items[this.active].button.src=this.items[this.active].image;
		this.active=-1;
	} else if (!this.items[this.hover].content) {
		return;
	} else if (this.active==-1) {
		this.note.style.display="none";
		this.exit.style.display="block";
		this.active=this.hover;
		this.items[this.active].bullet.src=this.bullets["active"];
		this.items[this.active].button.src=this.items[this.active].active;
		this.canvas.style.display="block";
	} else if (this.hover==this.active) {
		this.exit.style.display="none";
		this.note.style.display="block";
		if (this.items[this.active].type=="link") this.canvas.style.display="none";
		this.active=-1;
		this.items[this.hover].bullet.src=this.bullets["hover"];
		this.items[this.hover].button.src=this.items[this.hover].hover;
		this.items[this.hover].anchor.blur();
	} else {
		this.data(this.items[this.hover].label,this.items[this.hover].content,this.items[this.hover].note);
		this.items[this.active].bullet.src=this.bullets["blank"];
		this.items[this.active].button.src=this.items[this.active].image;
		this.active=this.hover
		this.items[this.active].bullet.src=this.bullets["active"];
		this.items[this.active].button.src=this.items[this.active].active;
	}
}

function PopupControl(id) {
	this.id=id;
	this.locked=0;
	this.active=-1;
	this.hover=-1;
	this.canvas;
	this.bullets=new Array();
	this.bullets["blank"]="http://www.comserv-usa.com/_images/spacer.gif";
	this.bullets["hover"]="http://www.comserv-usa.com/_images/bullet.jpg";
	this.bullets["active"]="http://www.comserv-usa.com/_images/bullet_dark.jpg";
	this.box=popupControlBox;
	this.list=popupControlList;
	this.bar=popupControlBar;
	this.data=popupControlData;
	this.show=popupControlShow;
	this.hide=popupControlHide;
	this.toggleLock=popupControlToggleLock;
	this.items=new Array();
	var divs=document.getElementsByTagName("div");
	for (var dcount=0;dcount<divs.length;dcount++) {
		if (divs[dcount].className!="PopupBox") continue;
		this.box(divs[dcount]);
		break;
	}
	var lists=document.getElementsByTagName("ul");
	for (var lcount=0;lcount<lists.length;lcount++) {
		if (lists[lcount].className!="PopupList") continue;
		this.list(lists[lcount]);
	}
	for (var dcount=0;dcount<divs.length;dcount++) {
		if (divs[dcount].className!="PopupBar") continue;
		this.bar(divs[dcount]);
	}
	var spans=document.getElementsByTagName("span");
	for (var scount=0;scount<spans.length;scount++) {
		if (spans[scount].className!="PopupLink") continue;
		this.items[this.items.length]=new PopupItem(spans[scount],this,"link");
	}
}

PControl=new PopupControl("PControl");