/*!
 * titanROSE Vaultify 2.0.3
 * http://titanrose.com/
 *
 * Copyright 2010, titanROSE
 */

var ttCache = new Array();
var ttID = 0;

$(document).ready(function() {
	$('a').hover(
		function(){
			var ttName = $(this).attr('vault_tt');
			if(ttName != undefined) return;
	
			var url = $(this).attr('href');
			if(ttCache[url] != undefined){
				$(this).attr('vault_tt', ttCache[url]);
				return;
			}
			
			var result = url.match(/^http:\/\/vault\.titanrose\.com\/(player|item|npc|skill|map|achievement)\/(.*)\.html/);
			if(result == null || result.length != 3) return;

			ttName = 'vault_tt_' + (++ttID);
			
			$('<div/>', {
				id: ttName,
				text: 'Loading...',
				style: 'position: absolute; display: none; top: -1000px; left: -1000px; visibility: hidden; z-index: 100;'
			}).appendTo("body");
			
			ttCache[url] = ttName;
			$(this).attr('vault_tt', ttName);
			
			$.ajax({
				url: "http://vault.titanrose.com/tooltip.php?type=" + result[1] + "&id=" + result[2],
				success: function(data){
					$('#' + ttName).html(data);
				}
			});
		},
		function(){
			var ttName = $(this).attr('vault_tt');
			if(ttName == undefined) return;

			$('#' + ttName)
				.css('left', '-1000px')
				.css('top', '-1000px')
				.css('display', 'none')
				.css('visibility', 'hidden');
		}
	);
	
	$('a').mousemove(
		function(e){
			var ttName = $(this).attr('vault_tt');
			if(ttName == undefined) return;
			
			$('#' + ttName)
				.css('left', (e.pageX + 10) + 'px')
				.css('top', (e.pageY + 10)  + 'px')
				.css('display', 'inline')
				.css('visibility', 'visible');
		}
	);
	
	$('<link>', {
		rel: 'stylesheet',
		type: 'text/css',
		href: 'http://vault.titanrose.com/css/tooltip.css'
		}).appendTo('head');
});

