niceTooltips.prototype.createTooltips = function(){

	// save this obj
	var thisObj = this;
	
	// name for the generated tolltips
	var tooltipName = 'nice-tooltip';
	
	// enable global or not?
	if (thisObj.enableGlobal == '1'){
		var selector = '*[title]';
	}
	else {
		var selector = '.'+thisObj.htmlClass;
	}
	
	// traverse all dom elements
	$(selector).each(function(index){
		
		// create html for the tooltip
		var tooltipText = $(this).attr('title'); 
		
		if (tooltipText != ""){
			
			// create tooltip html
			var tooltipHtml = '<div class="'+tooltipName+'" id="'+(tooltipName+index)+'" style="background:'+thisObj.backColor+'; border: 1px solid '+thisObj.borderColor+'"><p style="color:'+thisObj.fontColor+';">'+tooltipText+'</p></div>';
	
			// append tooltip to body
			$('body').append(tooltipHtml);
			
			// reference to dom element of this tooltip
			var thisTooltip = $('#'+(tooltipName+index));
			
			// remove title-tag from dom element
			$(this).removeAttr('title');
			
			// mouseover function
			$(this).mouseover(function(){
				thisTooltip.css({opacity:thisObj.opacity, display:"none"});		
				tooltipTimeoutIn = setTimeout(function() {
					thisTooltip.fadeIn(thisObj.fadeInSpeed);
				}, thisObj.fadeInDelay);
				
			// watch mouse movement and position tooltip
			}).mousemove(function(kmouse){
				thisTooltip.css({left:kmouse.pageX+15, top:kmouse.pageY+15});
				
			// mouseout function
			}).mouseout(function(){
				clearTimeout(tooltipTimeoutIn);
				//thisTooltip.fadeOut(thisObj.fadeOutSpeed);
				tooltipTimeoutOut = setTimeout(function() {
					thisTooltip.fadeOut(thisObj.fadeOutSpeed);
					clearTimeout(tooltipTimeoutOut);
				}, thisObj.fadeOutDelay);
			});
		}
	
	});	
}
$('document').ready(function(){
	niceTooltipsObj = new niceTooltips()
	niceTooltipsObj.createTooltips();
});
