var PromptClass = function() {
   
	tblStyle = {
		position : 'absolute',
		display : 'none',
		opacity : '0',
		filter : 'alpha(opacity=0)',
		fontFamily : prompt_Op['pr_font'],
		fontSize : '11px',
		color : prompt_Op['pr_font_color'],
		border : '0px'
	}
	
    // создаем саму подсказку
	this.table = document.createElement('table');
	
	for(var z in tblStyle) {
	    this.table.style[z] = tblStyle[z];
	}
	
	for(var i = 0; i < 2; i++) {
	    this.table.insertRow(i);
		
		for(var a = 0; a < 4; a++) {
		    this.table.rows[i].insertCell(a);
		}
	}
	var dir = prompt_Op['pr_bg_dir'] + prompt_Op['pr_kind'];
	this.table.rows[0].cells[1].colSpan = 2;
	this.table.rows[0].deleteCell(2);
	this.table.cellSpacing = 0;
	this.table.cellPadding = 0;
	
	var cell = this.table.rows[0].cells[0];
	cell.style.width = '6px';
	(img = new Image()).src = dir + '/borderLeft.png';
	cell.appendChild(img);
	
	var cell = this.table.rows[0].cells[1];
	cell.align = 'center';
	cell.style.backgroundImage = 'url(' + dir + '/centerLine.png)';
	cell.style.backgroundPosition = 'bottom left';
	cell.style.backgroundRepeat = 'repeat-x';
	
	var cell = this.table.rows[0].cells[2];
	cell.style.width = '10px';
	(img = new Image()).src = dir + '/borderRight.png';
	cell.appendChild(img);
	
	var cell = this.table.rows[1].cells[0];
	cell.style.width = '6px';
	cell.align = 'left';
	cell.style.verticalAlign = 'top';
	(img = new Image()).src = dir + '/borderLeftBottom.png';
	cell.appendChild(img);
	
	var cell = this.table.rows[1].cells[1];
	cell.style.width = '33px';
	cell.align = 'left';
	cell.style.verticalAlign = 'top';
	(img = new Image()).src = dir + '/bottom.png';
	cell.appendChild(img);
	
	var cell = this.table.rows[1].cells[2];
	cell.style.backgroundImage = 'url(' + dir + '/bottomLine.png)';
	cell.style.backgroundPosition = 'top';
	cell.style.backgroundRepeat = 'repeat-x';
	
	var cell = this.table.rows[1].cells[3];
	cell.style.width = '10px';
	cell.align = 'left';
	cell.style.verticalAlign = 'top';
	(img = new Image()).src = dir + '/borderRightBottom.png';
	cell.appendChild(img);
	
	// обработка всех требуемых объектов
    this.init = false;
    this.DOMOnload(this.start);
}

PromptClass.prototype = {
    
	timer : null,
	opacity  : 0,
	step : 0.03,
	x : 0,
	y : 0,
	
	DOMOnload : function(func) {
	    
		var doc = document;
	    if(doc.addEventListener) {
	        doc.addEventListener('DOMContentLoaded', func, false);	
	    }
	    else if(doc.attachEvent) {
	        if(doc.documentElement.doScroll && window == window.top) {
			    (function() {
			        try {
				        doc.documentElement.doScroll('left');
					    func();
				    }
				    catch(e) {
				        setTimeout(arguments.callee, 10);
				    }
				})()
			}
	    }
		this.addEvent(window, 'load', func);
    },
	
	start : function() {
		
		if(pr.init == false) {
			document.body.appendChild(pr.table);
	        var allObj = document.getElementsByTagName('*');
	        var objLen = allObj.length;

		    for(var i = 0; i < objLen; i++) {
		        var classes = allObj[i].className.split(/\s+/);		

			    for(var k in classes) {
			        if(classes[k] == 'prompt') {
				       var ov = function(title) {
				           return function(e) {
					           pr.over(e, title);
					       }
				       }
				   
				       var ou = function() {
				           return function() {
					           pr.out();
					       }
				       } 

				       pr.addEvent(allObj[i], 'mouseover', ov(allObj[i].title));
					   pr.addEvent(allObj[i], 'mouseout', ou());
					   allObj[i].title = '';
				    }     
			    }
		    }
		    pr.init = true;
		}
	},
	
	addEvent : function(obj, evnt, func) {
	    if(obj.attachEvent) {
		    obj.attachEvent('on' + evnt, func);	
		}
		else if(obj.addEventListener) {
		    obj.addEventListener(evnt, func, false);
		}
		else {
		    obj['on' + evnt] = func;
		}
	},
	
    setOpacity : function(obj) {
		
		obj.filters && obj.filters.alpha
		    ? obj.filters.alpha.opacity = this.opacity * 100
			: obj.style.filter = 'alpha(opacity = ' + this.opacity * 100 + ');';
		
		obj.style.opacity = this.opacity;	
	},
	
	getOpacity : function(obj) {
	    
		var result;
		result = obj.filters && obj.filters.alpha
		              ? obj.filters.alpha.opacity
				      : 1;
		result = obj.style.opacity != 'undefined' && obj.style.opacity != ''
		              ? obj.style.opacity
					  : 1; 
		return result;
	},
	
	getMousePos : function(e) {
	    
		var e = e || window.event;
		if(document.attachEvent) {
		    this.x = e.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
		    this.y = e.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
		}
		else if(document.addEventListener) {
		    this.x = e.clientX + window.scrollX;
			this.y = e.clientY + window.scrollY;
		}
	},
	
    over : function(e, title) {
	    
		if(this.timer != null) {
		    clearTimeout(this.timer);
			this.timer = null;
		}
        
		this.getMousePos(e);
		var w   = title.length;
		var txt = document.createTextNode(title);
		var cell = this.table.rows[0].cells[1];
		if(cell.hasChildNodes()) cell.removeChild(cell.lastChild);
		this.table.rows[0].cells[1].appendChild(txt);
		var tLen  = txt.length;
        var width = tLen >= 5 ? parseInt(tLen * 7 - 35) : 0;
        this.table.rows[1].cells[2].setAttribute('width', width);
		this.table.style.display = 'block';	
		this.table.style.left =  (this.x + 15) + 'px';
		this.table.style.top = (this.y - 60) + 'px';
		this.timer = setTimeout(function() {
		    pr.show(); 
		});
	},
	
	out : function() {

	    if(this.timer != null) {
		    clearTimeout(this.timer);
			this.timer = null;
		}
		
		this.timer = setTimeout(function() {
		    pr.hide();    
		});
	},
	
	show : function() {
	    
		this.setOpacity(this.table);
		this.opacity += this.step;

		if(this.opacity > 1) {
		    clearTimeout(this.timer); 
			this.opacity = 1;
		}
		else {
		    this.timer = setTimeout(function() {
		        pr.show(); 
		    });
		}
	},
	
	hide : function() {
	    
		this.setOpacity(this.table);
		this.opacity -= this.step;
		
		if(this.opacity < 0) {
		    clearTimeout(this.timer);
		    this.opacity = 0;
			this.table.style.display = 'none';
		}
		else {
		    this.timer = setTimeout(function() {
			    pr.hide();
			});
		}
	}
		
}
var pr = new PromptClass();
