var fromX= -1;           // How much from the actual mouse X should the description box appear?
var fromY= 21;           // How much from the actual mouse Y should the description box appear?
var ns4center= 1;        // Centering the text in ns4 doesn't work with css, use this variable instead... the value is 1 or 0
var useFading= 0;        // 1 for a fading effect in windows explorer 5+ and all platforms ns6, 0 for no fading effect.
var animation= 1;        // 1 if you want animation, 0 for no animation.
var detectiontype= 1;    // 1 for 'smooth' window size detection, 0 for 'flip' window size detection.
var delay= 300;          // The time before showing the popup, in milliseconds.
var fixed=1;


/*** There should be no need to change anything beyond this. ***/ 

// A unit of measure that will be added when setting the position of a layer.
var px = bwsr.ns4||window.opera?"":"px";

if(document.layers){ //NS4 resize fix.
    scrX= innerWidth; scrY= innerHeight;
    onresize= function(){if(scrX!= innerWidth || scrY!= innerHeight){history.go(0)} };
}

// object constructor...
function makeTooltip(obj){	
							
   	this.elm= document.getElementById? document.getElementById(obj):bwsr.ie4?document.all[obj]:bwsr.ns4?document.layers[obj]:0;
   	this.css= bwsr.ns4?this.elm:this.elm.style;
   	this.wref= bwsr.ns4?this.elm.document:this.elm;
	this.obj= obj+'makeTooltip'; eval(this.obj+'=this');
	this.w= bwsr.ns4? this.elm.clip.width: this.elm.offsetWidth;
	this.h= bwsr.ns4? this.elm.clip.height: this.elm.offsetHeight;
};
makeTooltip.prototype.measureIt= function(){
	this.w= bwsr.ns4? this.elm.clip.width: this.elm.offsetWidth;
	this.h= bwsr.ns4? this.elm.clip.height: this.elm.offsetHeight;
};
makeTooltip.prototype.writeIt= function(text){
	if (bwsr.ns4) {this.wref.write(text); this.wref.close()}
	else this.wref.innerHTML= text;
};

// Mousemove detection
var mouseX=0,mouseY=0,setX=0,setY=0;
function getMousemove(e){
	mouseX= (bwsr.ns4||bwsr.ns6)? e.pageX: bwsr.ie&&bwsr.win&&!bwsr.ie4? (event.clientX-2)+document.documentElement.scrollLeft : event.clientX+document.documentElement.scrollLeft;
	mouseY= (bwsr.ns4||bwsr.ns6)? e.pageY: bwsr.ie&&bwsr.win&&!bwsr.ie4? (event.clientY-2)+document.documentElement.scrollTop : event.clientY+document.documentElement.scrollTop;
	//alert(event.clientY);
	if (isLoaded && hovering && animation) placeIt();
};
function placeIt(){
	//alert(mouseY + " " + screenHscrolled);
	if (detectiontype==1) setX= mouseX+fromX+tooltip.w > screenWscrolled ? screenWscrolled-tooltip.w: mouseX+fromX+2;
	if (detectiontype==1) { 
		if (mouseY+fromY+tooltip.h > screenHscrolled) {
			setY=  screenHscrolled-tooltip.h;
		}
		else {
			//alert(document.body.scrollTop);
			setY=  mouseY+fromY;
			
		}
	}
	if (detectiontype==0) setX= mouseX+fromX+tooltip.w > screenWscrolled ? mouseX-fromX-tooltip.w: mouseX+fromX;
	if (detectiontype==0) setY= mouseY+fromY+tooltip.h > screenHscrolled ? mouseY-fromY-tooltip.h: mouseY+fromY;
	if (setX<0) setX= 0;
	if (setY<0) setY= 0;
	
	if (fixed == 1) {
		
		pos = findPos();
		setX=pos[0]-87;
		setY=pos[1]+24;
		
	}
	
	tooltip.css.left= setX+px;
	tooltip.css.top= setY+px;
	
};

// Main popUp function.
var hovering=false, screenWscrolled=0, screenHscrolled=0;
makeTooltip.prototype.showTimer= null;
var obj_menu;
function popUp(num,mdetection){
	fixed = mdetection;
	if(isLoaded){
		clearTimeout(tooltip.popTimer);
		dopopOut();
		if (bwsr.ns4){
			var text= '<span class="netscape4Style">' + (ns4center?'<center>':"") + messages[num] + (ns4center?'</center>':"") + '</span>';
			tooltip.writeIt(text);
		}
		if (!bwsr.ns4) tooltip.writeIt(messages[num]);
		screenWscrolled= screenW + (bwsr.ie?document.documentElement.scrollLeft:pageXOffset);
		//alert(screenH);
		screenHscrolled= screenH + (bwsr.ie?document.documentElement.scrollTop:pageYOffset);
		hovering= true;
		
		/* I'm using a timeout for ie4 here, because it doesn't store the measurements quickly enough. Does anybody know why this happens? */
		if (bwsr.ie4) setTimeout('tooltip.measureIt(); placeIt();', delay/2);
		else { tooltip.measureIt(); placeIt(); }
		if (useFading) tooltip.showTimer= setTimeout('tooltip.blendIn()', delay);
		if (!useFading) tooltip.showTimer= setTimeout('tooltip.css.visibility="visible"', delay);
    }
};

// Hiding routines
makeTooltip.prototype.popTimer= null;
function popOut(){
	if (isLoaded) tooltip.popTimer= setTimeout('dopopOut()', 30)
};
function dopopOut(){
	hovering= false;
	clearTimeout(tooltip.showTimer);
	tooltip.css.visibility= 'hidden';
	clearTimeout(tooltip.fadeTimer);
	tooltip.i= 0;
};

// Measure screensize.
var scrollbarWidth= bwsr.ns6&&bwsr.win?14:bwsr.ns6&&!bwsr.win?16:bwsr.ns4?16:0;
function measureScreen() {
	tooltip.css.top= 0+px;
	tooltip.css.left= 0+px;
	screenW= (bwsr.ie?document.documentElement.clientWidth:innerWidth) - scrollbarWidth;
	screenH= (bwsr.ie?document.documentElement.clientHeight:innerHeight);
};

// Opacity methods.
makeTooltip.prototype.blendIn= function(){
	if (bwsr.ie && bwsr.win && !bwsr.ie4) {
		this.css.filter= 'blendTrans(duration=0.5)';
		this.elm.filters.blendTrans.apply();
		this.css.visibility= 'visible';
		this.elm.filters.blendTrans.play();
	}
	else {
		this.css.visibility= 'visible';
		if (!bwsr.ns4) this.fadeIt();
	}
};
makeTooltip.prototype.step= 8;
makeTooltip.prototype.i= 0;
makeTooltip.prototype.fadeTimer= null;
makeTooltip.prototype.fadeIt= function(){
	this.i+= this.step;
	//this.css.filter= 'alpha(opacity='+this.i+')';
	this.css.MozOpacity= this.i/100;
	if (this.i<100) this.fadeTimer= setTimeout(this.obj+'.fadeIt()', 40);
	else this.i= 0;
};

// Init function...
var isLoaded= false;
function popupInit(){
	//Fixing the browsercheck for opera... this can be removed if the browsercheck has been updated!!
	bwsr.opera5 = (navigator.userAgent.indexOf("Opera")>-1 && document.getElementById)?true:false
	if (bwsr.opera5) bwsr.ns6 = 0
	
	//Extending the browsercheck to add windows platform detection.
	bwsr.win= (navigator.userAgent.indexOf('Windows')>-1)

	tooltip= new makeTooltip('divTooltip');
	tooltip.elm.onmouseover= function(){ clearTimeout(tooltip.popTimer); if(bwsr.ns4){setTimeout('clearTimeout(tooltip.popTimer)',20)}; };
	//tooltip.elm.onmouseout= dopopOut;
	if (bwsr.ns4) document.captureEvents(Event.MOUSEMOVE);
	document.onmousemove= getMousemove;
	measureScreen();
	if (!bwsr.ns4) onresize= measureScreen;
	if (!bwsr.ns4) tooltip.elm.className= 'normalStyle';
	if (bwsr.ie && bwsr.win && !bwsr.ie4) tooltip.css.filter= 'alpha(opacity=100)'; //Preloads the windows filters.
	isLoaded= true;
};

function findPos(){
  if(bwsr.ns4){   //Netscape 4
    var x = document.layers.layerMenu.pageX
    var y = document.layers.layerMenu.pageY
  }else{ //other browsers
    var x=0; var y=0; var el,temp
   // alert("seprator"+obj_menu);
    el = bwsr.ie4?document.all["logout"]:document.getElementById("logout");
	
    if(el != null) {
	    if(el.offsetParent){
	      temp = el
	      while(temp.offsetParent){ //Looping parent elements to get the offset of them as well
	        temp=temp.offsetParent; 
	        x+=temp.offsetLeft
	        y+=temp.offsetTop;
	      }
	    }
	
	  }  
	    x+=el.offsetLeft
	    y+=el.offsetTop
    
  }

  //Returning the x and y as an array

  return [x,y]
}

// Initiates page on pageload if the browser is ok.
if(bwsr.bwsr && !isLoaded) onload= popupInit;