/*************************************************
class: tips
modified: 2004.05.17
project: Moon
version: 1.0 alpha9
author: Audrius Naslenas, audrius@metasite.net
All rights reserved
*************************************************/
var mouse_x,mouse_y;

function handlerMM_ns(e){
	mouse_x=e.pageX;
	mouse_y=e.pageY;
}
function handlerMM_ie4(e){
	mouse_x=event.x;
	mouse_y=event.y;
}
function handlerMM_ie5(e){
	var oframe=self;
	mouse_x=event.x+oframe.document.body.scrollLeft;
	mouse_y=event.y+oframe.document.body.scrollTop;
}



function tips(ObjName){


	//properciai
	this.divid='';
	this.msg=new Array();
	
	this.ns4=false;
	this.ns6=false;
	this.waiting=0;
	//metodai
	this.init=tips_init;
	this.load_tips=tips_load_tips;
	this.construct_msg=tips_construct_msg;
		
	this.show_tip=tips_show_tip;
	this.hide_tip=tips_hide_tip;
		
	this.on=_on;
	this.off=_off;
	this.img_preview=tips_img_preview;
	
	this.wait=_wait;
	this.timer=_timer;
	
	
	//implementation
function _on(nr,w){
	this.hide_tip();
	this.wait();
	this.show_tip(nr,w);
} 

function _off(nr){
	this.wait(false);
}
	
	function _wait(on){
		if(on==false) this.waiting=2;
		else this.waiting=1;
	}
	
	function _timer(objname){
		if (this.waiting==1) this.waiting=0;
		else if(this.waiting==2) this.hide_tip();
		if (objname==null) {this.waiting=0;return false;}
		setTimeout(objname+".timer('"+objname+"')", 1500);
	}
	
	
	
	//*****************
	function tips_load_tips(mas){
		this.msg=mas;
	}
function tips_init(divid){
//inicializacija
	if (divid==null) divid="tipslayer";
	this.divid=divid;
	 
	var ns4=(document.layers)? true:false;
	var ns6=(document.getElementById)? true:false;
	var ie4=(document.all)? true:false;
	var ie5=false;
	if(ie4){
		if(navigator.userAgent.indexOf('MSIE 5')>0 || navigator.userAgent.indexOf('MSIE 6')>0){
			ie5=true;
		}
		if(ns6){
			ns6=false;
		}
	}
	
	if((ns4)||(ns6)){
		document.onmousemove=handlerMM_ns;
		if(ns4)document.captureEvents(Event.MOUSEMOVE)
	}else if(ie5){
		document.onmousemove=handlerMM_ie5;
	}else{
		document.onmousemove=handlerMM_ie4;
	}
	this.ns4=ns4;
	this.ns6=ns6;
}

function tips_show_tip(a,width){
	var left=false;
	if (width==null) {	width=150;	}
	left=(width<0 ? true:false);
	width=Math.abs(width);
	if (width<100){width=100;}
	if (width>500){width=500;}
	var desc=this.construct_msg(a,width);
	var x,y;
	if (left) {
		x=mouse_x-width-15;
		y=mouse_y-15;
	}else{
		x=mouse_x+15;
		y=mouse_y;
	}
	var myobj;
	if(this.ns4) {
		eval("myobj=document."+this.divid);
		myobj.document.write(desc);
		myobj.document.close();
		myobj.left=x;
		myobj.top=y;
		myobj.visibility="show";
	}else if (this.ns6){
		myobj=document.getElementById(this.divid);
		myobj.innerHTML=desc;
		myobj.style.left=x;
		myobj.style.top=y;
		myobj.style.visibility="visible";
	}else{
		eval("myobj="+this.divid);
		myobj.innerHTML=desc;
		myobj.style.pixelLeft=x;
		myobj.style.pixelTop=y;
		myobj.style.visibility="visible";
	 }
}

	
function tips_hide_tip(){
	if(this.ns4) {
		eval("myobj=document."+this.divid);
		myobj.visibility="hide";
		myobj.top=-50;
	}else if (this.ns6){
		myobj=document.getElementById(this.divid);
		myobj.style.visibility="hidden";
		myobj.innerHTML="";
	}else{
		eval("myobj="+this.divid);
		myobj.style.visibility="hidden";
		myobj.innerHTML="";
	 }
}

function tips_construct_msg(a,width){
	var desc ='<table';
	if (width) desc+=' width="'+width+'"';
	desc+=' cellspacing=0 cellpadding=1 border=0 bgcolor="#636363"><tr><td><table width=100% cellspacing=1 cellpadding=0 border=0 bgcolor="#fdf5d7"><tr><td><div class=help>';
	desc += this.msg[a];
	desc += '</div></td></tr></table></td></tr></table>';
	return desc;
}

function tips_img_preview(src,width){
	var s='';
	s='';
	if (src!="") s="<img src=\""+src+"\" border=\"0\">";
	else return false;
	this.msg['tips_img']=s;
	this.show_tip('tips_img',width);
}

//constructor
this.timer(ObjName);

}


