var undefined;

var wun = wun == undefined ? {} : wun;

/* wun.imageTooltip <html>:
    
    <div class="wunImageTooltipBottom">
        <div class="wunImageTooltipTop">
            <div class="wunImageTooltipContent"><img /></div>
        </div>
    </div>

*/

wun.imageTooltip = {
    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.innerImage = document.createElement('img');
    	
	    this.outerDiv.className = "wunImageTooltipBottom";
	    this.topDiv.className = "wunImageTooltipTop";
	    this.bottomDiv.className = "wunImageTooltipContent";
    	
	    this.bottomDiv.appendChild(this.innerImage);
	    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;
    },
    setSource : function(imgSource) {
	    if( this.exist() )
	    {
	        if(this.innerImage.src != imgSource) this.innerImage.src = imgSource;
	    }
    },
    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() )
        {
            //alert('this.outerDiv.style.display != "block" : ' + (this.outerDiv.style.display != "block"));
            if(this.outerDiv.style.display != "block")
            {
                this.outerDiv.style.display = "block";
            }
            else
            {
                this.outerDiv.style.display = "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";
	    }
    }
};