//	ns_tooltip.js
//	created by Nikita Seleckis
//	www.seleckis.lv

// EDIT SETTINGS

// Tags available for tooltips
var elements = new Array("div", "span", "img")

// Attributes with text for tooltip
var attrs = new Array("rel", "alt")

// STOP EDITING

var l = 0, t = 0
function getMouseXY(e) {
	var IE = document.all?true:false
	if (IE) {
		l = event.clientX + document.body.scrollLeft
		t = event.clientY + document.body.scrollTop
	}
	else {
		l = e.pageX
		t = e.pageY
	}  
	$d("#ns_tt").css("left", l)
	$d("#ns_tt").css("top",	t)
	return true
}

function parsePreTags(rel){
	var repl = { "[" : "<", "]" : ">" }
	for(r in repl){
		var srch = new RegExp("\\" + r, "g");
		rel = rel.replace(srch, repl[r])
	}
	return rel
}

var $d = jQuery.noConflict();
$d(document).ready(
	function() {
		$d("body").append("<div id='ns_tt'></div>")
		$d("#ns_tt").hide()
		attrs = attrs.reverse()
		for(e in elements){
			var el = elements[e]
			$d(el).mouseover(function(){
				var rel =""
				for (a in attrs){
					if(typeof($d(this).attr(attrs[a])) != "undefined")
						var rel = $d(this).attr(attrs[a])
				}
				rel = parsePreTags(rel)
				$d("#ns_tt").empty()
				$d("#ns_tt").append("<span>" + rel + "</span>")
				$d("#ns_tt").show()
			})
			$d(el).mouseout(function(){
				$d("#ns_tt").hide()
			})
		}
		document.onmousemove = getMouseXY
	}
)
