/******* GLOBALS [BEGIN] *******/
var is_opera = /opera\/9/i.test(navigator.userAgent);
var is_gecko = /gecko/i.test(navigator.userAgent);
var is_ie    = /MSIE/.test(navigator.userAgent);
/******* GLOBALS [END] *******/
function Cursor () {
	
	var xCoordinate;
	var yCoordinate;
	
	var truebody = function (){
		if(!window.opera && document.compatMode && document.compatMode!="BackCompat"){
			return document.documentElement;
		}
		else{
			return document.body;
		}
	}
	
	this.updateCursorPosition = function (DOMEvent) {
		if (is_ie) {
			xCoordinate = event.clientX + truebody().scrollLeft;
			yCoordinate = event.clientY + truebody().scrollTop;
		} else {
			xCoordinate = DOMEvent.pageX > 0 ? DOMEvent.pageX : 0;
			yCoordinate = DOMEvent.pageY > 0 ? DOMEvent.pageY : 0;
		}
	}
	
	this.getX = function () {
	   return xCoordinate;
	}
	
	this.getY = function () {
	   return yCoordinate;
	}
}

function Image (path){
	this._path = path;
	this._enabledLoading;
	this._preloadImage;
}

function Popup (popupObject){
	
	var obj = popupObject;
	var eventTimeout;
	var offsetx = 20;
	var offsety = 20;
	var wasOver = false;
	
   var cursorObj = new Cursor();
	if(!is_ie){
		document.captureEvents(Event.MOUSEMOVE);
	}
	document.onmousemove = cursorObj.updateCursorPosition;
	
	this.image = new Image();
	
	obj.style.display = "none";
	obj.style.zIndex = "999";
	
	this.getObject = function () {
		return obj;
	}
	
	this.getObjectStyle = function () {
		return obj.style;
	}
	
	this.getCursorObject = function () {
		return cursorObj;
	}
	
	this.setOffsetFromCursor = function (xOffset, yOffset) {
		offsetx = xOffset;
		offsety = yOffset;
	}
	
	this.setDimension = function (objWidth, objHeight) {
		this.style.height = objHeight;
		this.style.width = objWidth;
	}
	
	this.setContent = function (htmlSource) {
		obj.innerHTML = htmlSource;
	}
	
	this.setInnerObjectContent = function (id, htmlSource) {
		
	}
	
	this.dropTimeout = function () {
		clearTimeout(eventTimeout);
	}
	
	var enableMove = function () {
		wasOver=true;
	}
	
	var disableMove = function () {
		wasOver=false;
	}
	
	this.toPosition = function (xPos, yPos) {
		obj.style.top = yPos + offsety + "px";
		obj.style.left = xPos + offsetx + "px";
	}
	
	this.show = function (htmlSource) {
		if(wasOver == true){
			obj.style.top = cursorObj.getY() + offsety + "px";
			obj.style.left = cursorObj.getX() + offsetx + "px";
			obj.style.display = "block";
			
			if(arguments.length == 1 && typeof(arguments[0]) == typeof("string")){
				if(obj.innerHTML != htmlSource){
					obj.innerHTML = htmlSource;
				}
			}
		}
	}
	
	
	
		this.show2 = function () {
		if(wasOver == true){
			obj.style.top = cursorObj.getY() + offsety + "px";
			obj.style.left = cursorObj.getX() + offsetx + "px";
			obj.style['visibility'] = "visible";
			obj.style['display'] = "block";
			var str ='';
			for(var i =0; i<obj.style.length; i++){
			//str +=obj.style[i]+' '+obj.style[obj.style[i]]+"\n";
			}
			//alert(str);
			//visibility: visible;
			
		}
	}
	
	this.showWithTimeout = function (timeout, htmlSource) {
		if(eventTimeout){
			clearTimeout(eventTimeout);
			eventTimeout = 0;
		}
		
		tmpfunc = this.show;
		enbl = enableMove;
		if(arguments.length == 1 && typeof(arguments[0]) == typeof("string")){
			enbl();
			tmpfunc(arguments[0]);
		}
		else if(arguments.length == 2){
			eventTimeout = setTimeout("enbl();tmpfunc('" + htmlSource + "');", timeout);
		}
		else{
			eventTimeout = setTimeout("enbl();tmpfunc();", timeout);
		}
	}
	
	this.showWithTimeout2 = function (adon) {

		var frm = document.getElementById("frm");
		if(adon.length > 0){
		//alert(adon);
		frm.src =adon;
		document.getElementById("ppp").innerHTML = adon;
		//document.getElementById("ppp").innerHTML = document.getElementById("ppp").innerHTML.replace(/{item}/i, adon);
		}
		//alert(frm.src);
		
		tmpfunc = this.show2;
		enbl = enableMove;
		enbl();
		tmpfunc();
		
		return false;

	}
	
	
	this.hide = function () {
		obj.style.display = "none";
		wasOver = false;
		clearTimeout(eventTimeout);
		obj.style.top = "250px";
		obj.style.left = "-500px";
		//this.dropTimeout();
		//this.toPosition(-500, 250);
	}
	
	this.hideWithTimeout = function (timeout) {
		if(eventTimeout){
			clearTimeout(eventTimeout);
			eventTimeout = 0;
		}
		tmpfunc = this.hide;
	   eventTimeout = setTimeout("tmpfunc();", timeout);
	}
	
	this.setIframe = function (src) {
		var frm = document.getElementById("frm");
		frm.src =src;

	}
}

//popupObj = new Popup(document.getElementById('preview_div'));
//alert(document.getElementById('preview_div').id);

