var WdToolTip2=Class.create();
WdToolTip2.prototype={
    Left:1,
    Right:2,
    Top:4,
    Bottom:8,
    MaxWidth:500,
    MaxHeight:500,
    ContentWidth:"auto",
    ContentHeight:"auto",
    Version:"2",
    initialize:function(c,b,a){
        this.ContentCssClass=b;
        this.toolTipType=this.Left+this.Top;
        this.timer=null;
        this.currentToolTipId=null;
        this.containerID="ID_"+c;
        this.ImagesPath=a;
        this._loadImages()
    },    
    Show:function(f,h,a,n){
        if(f.id==null||f.id==""){
            var j=new Date();
            f.id="id_"+j.getTime()
        }
        this.ContentWidth="auto";
        this.ContentHeight="auto";
        if(this.currentToolTipId==f.id&&$(this.currentToolTipId)){
            return
        }else{
            this.currentToolTipId=f.id
        }
        this.RemoveToolTip();
        var m=Position.cumulativeOffset(f);
        var c=Position.realOffset(f);
        var l=$(f).getWidth();
        var g=$(f).getHeight();
        var e=Prototype.Browser.IE?parseInt(document.documentElement.clientWidth/2):parseInt(window.innerWidth/2);
        var b=Prototype.Browser.IE?parseInt(document.documentElement.clientHeight/2):parseInt(window.innerHeight/2);
        if(Prototype.Browser.Opera){
            //c[0]=document.body.scrollLeft;
           // c[1]=document.body.scrollTop
        }
        this.toolTipType=(m[0]-c[0]>e?this.Right:this.Left)+(m[1]-c[1]>b?this.Bottom:this.Top); //alert(e+' | '+b);
            var k=document.createElement("div");
            if(this.toolTipType&this.Top){
                k.id=this.containerID;
                k.style.position="absolute";
                k.style.display="block";
                k.style.left=m[0]+"px";
                k.style.top=(m[1]+g+1)+"px";
                k.innerHTML='<table border="0" cellspacing="0" cellpadding="0"><tr><td colspan="3"><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td width="6"><img src="'+this.ImagesPath+'top/str_11.png" width="6" height="22" alt="" /></td>'+((this.toolTipType&this.Right)?'<td><img src="'+this.ImagesPath+'top/str_12.png" width="100%" height="22" alt="" /></td>':"")+'<td width="37"><img src="'+this.ImagesPath+"top/arrow_top_"+(this.toolTipType&this.Right?"right":"left")+'.png" width="37" height="22" alt="" /></td>'+((this.toolTipType&this.Left)?'<td><img src="'+this.ImagesPath+'top/str_12.png" width="100%" height="22" alt="" /></td>':"")+'<td width="6"><img src="'+this.ImagesPath+'top/str_14.png" width="6" height="22" alt="" /></td></tr></table></td></tr><tr><td width="5"><img src="'+this.ImagesPath+'top/str_21.png" width="6" height="5" alt="" /></td><td style="background-image: url('+this.ImagesPath+'top/str_22.png); background-repeat: repeat-x; background-position: top;"></td><td width="5"><img src="'+this.ImagesPath+'top/str_23.png" width="6" height="5" alt="" /></td></tr><tr valign="top"><td width="5" style="background-image: url('+this.ImagesPath+'top/str_bg.png); border-left: 1px solid #61599F;"><div style="background-image: url('+this.ImagesPath+'top/str_33.png); background-repeat: repeat-x; background-position: top; height:50px; width: 5px;"></div></td><td style="background-image: url('+this.ImagesPath+'top/str_bg.png);"><table width="100%" height="50" border="0" cellspacing="0" cellpadding="0" style="background-image: url('+this.ImagesPath+'top/str_33.png); background-repeat: repeat-x; background-position: top; padding: 3px;"><tr><td class="'+this.ContentCssClass+'" style="width: '+this.ContentWidth+"px; height: "+this.ContentHeight+'px;">'+h+'</td></tr><tr><td><img src="'+this.ImagesPath+'spacer.gif" width="150" height="0" alt="" style="visibility: hidden;" /></td></tr></table></td><td width="5" style="background-image: url('+this.ImagesPath+'top/str_bg.png); border-right: 1px solid #61599F;"><div style="background-image: url('+this.ImagesPath+'top/str_33.png); background-repeat: repeat-x; background-position: top; height:50px; width: 5px;"></div></td></tr><tr><td width="6"><img src="'+this.ImagesPath+'top/str_41.png" height="6" width="6" alt="" /></td><td><img src="'+this.ImagesPath+'top/str_42.png" height="6" width="100%" alt="" /></td><td width="6"><img src="'+this.ImagesPath+'top/str_43.png" height="6" width="6" alt="" /></td></tr></table>';
               document.body.appendChild(k)
            }else{
              if(this.toolTipType&this.Bottom){
                k.id=this.containerID;
                k.style.position="absolute";
                k.style.display="block";
                k.style.left=m[0]+"px";
                k.style.top=m[1]-1+"px";
                
                var contimageSrc = h.match(/src=\'(http:\/\/[^\']+)\'/i);   
                if(contimageSrc != null){
                  h = '';          
                } 
                
                k.innerHTML='<table border="0" cellspacing="0" cellpadding="0"><tr><td width="6"><img src="'+this.ImagesPath+'bottom/str_11.png" height="6" width="6" alt="" /></td><td><img src="'+this.ImagesPath+'bottom/str_12.png" height="6" width="100%" alt="" /></td><td width="6"><img src="'+this.ImagesPath+'bottom/str_13.png" height="6" width="6" alt="" /></td></tr><tr valign="bottom"><td width="5" style="background-image: url('+this.ImagesPath+'bottom/str_bg.png); border-left: 1px solid #61599F;"><div style="background-image: url('+this.ImagesPath+'bottom/str_23.png); background-repeat: repeat-x; background-position: bottom; height:50px; width: 5px;"></div></td><td style="background-image: url('+this.ImagesPath+'bottom/str_bg.png);"><table width="100%" height="50" border="0" cellspacing="0" cellpadding="0" style="background-image: url('+this.ImagesPath+'bottom/str_23.png); background-repeat: repeat-x; background-position: bottom; padding: 3px;"><tr><td class="'+this.ContentCssClass+'" id="wbToolTipContentWhite">'+h+'</td></tr><tr><td><img src="'+this.ImagesPath+'spacer.gif" width="150" height="0" alt="" style="visibility: hidden;" /></td></tr></table></td><td width="5" style="background-image: url('+this.ImagesPath+'bottom/str_bg.png); border-right: 1px solid #61599F;"><div style="background-image: url('+this.ImagesPath+'bottom/str_23.png); background-repeat: repeat-x; background-position: bottom; height:50px; width: 5px;"></div></td></tr><tr><td width="5"><img src="'+this.ImagesPath+'bottom/str_31.png" width="6" height="5" alt="" /></td><td style="background-image: url('+this.ImagesPath+'bottom/str_32.png); background-repeat: repeat-x; background-position: bottom;"></td><td width="5"><img src="'+this.ImagesPath+'bottom/str_33.png" width="6" height="5" alt="" /></td></tr><tr><td colspan="3"><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td width="6"><img src="'+this.ImagesPath+'bottom/str_41.png" width="6" height="22" alt="" /></td>'+((this.toolTipType&this.Right)?'<td><img src="'+this.ImagesPath+'bottom/str_42.png" width="100%" height="22" alt="" /></td>':"")+'<td width="37"><img src="'+this.ImagesPath+"bottom/arrow_bottom_"+(this.toolTipType&this.Right?"right":"left")+'.png" width="37" height="22" alt="" /></td>'+((this.toolTipType&this.Left)?'<td><img src="'+this.ImagesPath+'bottom/str_42.png" width="100%" height="22" alt="" /></td>':"")+'<td width="6"><img src="'+this.ImagesPath+'bottom/str_44.png" width="6" height="22" alt="" /></td></tr></table></td></tr></table>';                 
                document.body.appendChild(k);    
                
                if(contimageSrc != null){ 
                  loading_img = contimageSrc[1];
                  var conImg = document.createElement('img');
                  conImg.toolTipType = (this.toolTipType&this.Right)?'right':'left';
                  conImg.onload = function(){               
                      if(this.src == loading_img){          
                          k.style.top = parseInt(k.style.top.replace(/px/,'')) - this.height + 42 + 'px'; 
                          if(this.toolTipType == 'right'){ 
                          k.style.left = parseInt(k.style.left.replace(/px/,'')) - this.width + 150 + 'px';
                          }
                          $('wbToolTipContentWhite').innerHTML = '';
                          $('wbToolTipContentWhite').appendChild(this);                    
                      }
                  }
                  conImg.src = contimageSrc[1];                  
                } 
              }
            }
            this.loadPngImages();
            this.moveToolTipCenter(m[0]+l/2,m[1]);
            var i=1
    },
    RemoveToolTip:function(){
        var a=$(this.containerID);
        if(a){
            a.remove();
        this.currentToolTipId=null
        }
    },
    moveToolTipCenter:function(c,b){
        var a=$(this.containerID);
        if(a){
            if(this.toolTipType&this.Left){
                a.style.left=c-7+"px"
            }else{
                if(this.toolTipType&this.Right){
                    a.style.left=c+7-a.getWidth()+"px"
                }
            }
            if(this.toolTipType&this.Bottom){
                a.style.top=b-a.getHeight()-1+"px"
            }
        }
    },
    loadPngImages:function(){
        var a=$(this.containerID).getElementsBySelector("img");
        a.each(this._checkForPng)
    },
    _checkForPng:function(){
        if(Prototype.Browser.IE&&arguments[0].src.endsWith(".png")){
            var a=arguments[0].src;
            var b=arguments[0].src.substr(0,arguments[0].src.lastIndexOf("/"));
            arguments[0].src=b+"/spacer.gif";
            arguments[0].style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+a+"', sizingMethod='scale')"
        }
    },
    _loadImages:function(){
        var b=[];
        for(var a=0;a<b.length;a++){
            setTimeout(function(){var c=new Image();c.src=this.ImagesPath+b[a]},0)
        }
    }
};
