var undefined;

var wun = wun == undefined ? {} : wun;

/* wun.imageTooltip <html>:
    
    <div class="wunImageTooltipBottom">
        <div class="wunImageTooltipTop">
            <div class="wunImageTooltipContent"><img /></div>
        </div>
    </div>

*/

wun.tooltip = {
    outerDiv : undefined,
    topDiv : undefined,
    bottomDiv : undefined,
    innerImage : undefined,
    createTooltip : function() {
	    this.outerDiv = document.createElement('div');
	    this.topDiv = document.createElement('div');
	    this.bottomDiv = document.createElement('div');
    	
	    this.outerDiv.className = "wunTooltipBottom";
	    this.topDiv.className = "wunTooltipTop";
	    this.bottomDiv.className = "wunTooltipContent";
    	
	    this.topDiv.appendChild(this.bottomDiv);
	    this.outerDiv.appendChild(this.topDiv);
	    document.body.appendChild(this.outerDiv);
    },
    exist : function() {
        if (this.outerDiv == undefined) this.createTooltip();
	    return this.outerDiv != undefined;
    },
    setContent : function(content, width) {
	    if( this.exist() ) {
	        if(this.bottomDiv.innerHTML != content) this.bottomDiv.innerHTML = content;
	        this.bottomDiv.style.width =  width != undefined ? width + "px" : "auto";
	        
	        //alert(this.bottomDiv + " : width = " +this.bottomDiv.width );
	    }
    },
    setOnclick : function (func) {
        if( this.exist() ) this.outerDiv.onclick = func; 
    },
    hide : function() {
        if( this.exist() ) this.outerDiv.style.display = "none";
    },
    show : function() {
        if( this.exist() ) this.outerDiv.style.display = "block";
    },
    toggle : function() {
        if( this.exist() ) this.outerDiv.style.display = this.outerDiv.style.display  != "block" ? "block" : "none";
    },
    move : function(sender, e) {
        if( this.exist() ) {
	        e = e || window.event;
	        var cursor = {x:0, y:0};
	        if (e.pageX || e.pageY) {
		        cursor.x = e.pageX;
		        cursor.y = e.pageY;
	        }
 	        else {
		        cursor.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
		        cursor.y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
	        }
        	
	        this.outerDiv.style.display = "block";
	        //this.outerDiv.style.width = this.innerImage.offsetWidth + "px";
	        this.outerDiv.style.top = cursor.y + "px";
	        this.outerDiv.style.left = cursor.x + 20 + "px";
	    }
    }
};