var PU = function popUp(className, fileExtension) {
	if(!className)		{ className = "popup"; }
	if(!fileExtension)	{ this.extendElement.fileExtension = "php"; }
	var links = document.getElementsByTagName("a");
	var testClass = new RegExp("(^|\\s)" + className + "(\\s|$)");
	for( var i = 0, len = links.length; i < len; i++ ) {
		if( testClass.test(links[i].className) ) {
			for( var item in this.extendElement ) {
				links[i][item] = this.extendElement[item];
			}
		}
	}
}
PU.prototype = {
	extendElement : {
		onclick : function() {
			this.clearTimer();
			this.getContent();
			return false;
		},
		onmouseover : function() {
			var This = this;
			this.clearTimer();
			if(!this.content || this.content.style.display == "none") {
				this.timer = setTimeout(function() { This.getContent(); }, 1000);
			}
		},
		onmouseout : function() {
			var This = this;
			this.clearTimer();
			this.timer = setTimeout(function() { This.content.style.display = "none"; This.clearTimer(); }, 2000);
		},
		getContent : function() {
			if(window.ActiveXObject) {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			else if(window.XMLHttpRequest){
				xmlHttp = new XMLHttpRequest();
			}
			xmlHttp.open("GET", this.popupContentLocation + this.popupUrl() +"."+ this.fileExtension , true);
			var This = this;
			xmlHttp.onreadystatechange = function() {
				if( xmlHttp.readyState == 4 ) {
					This.callback(xmlHttp.responseText);
				}
			};
			xmlHttp.send(null);
			this.clearTimer();
		},
		popupUrl : function() {
			var popupUrl = this.href;
			popupUrl = popupUrl.substring(popupUrl.indexOf('?')+1, popupUrl.length).replace("content=", "");
			return popupUrl;
		},
		clearTimer : function() {
			if(this.timer !== null) { clearTimeout(this.timer); this.timer = null; }
		},
		
		callback : function(content) {
			if( this.contentOn === false && this.contentSet === false ) {
				var span = document.createElement("span");
				span.innerHTML = content;
				span.className = "tooltipContent";
				this.parentNode.appendChild(span);
				this.contentOn = true;
				this.contentSet = true;
				this.content = span;
				this.content.style.left = this.offsetWidth + "px";
				this.content.style.display = "inline";
			} else {
				this.content.style.display = this.content.style.display == "inline" ? "none" : "inline";
			}
		},
		
		fileExtension : "php",
		popupContentLocation : "/popups/",
		content : null,
		contentOn : false,
		contentSet : false,
		timer : null,
		styleGuide : {
			left : this.offsetWidth + "px"
		}
	}
};