var KEY_GSTATIC_MAP = window['KEY_GSTATIC_MAP'] ? window['KEY_GSTATIC_MAP']  : (location.href.indexOf('local')!=-1 ? 'ABQIAAAAl3l7uHrKScJW5A8LoyZrWRT2yXp_ZAY8_ufC3CFXhHIE1NvwkxSL7TUWwkCU_EINqK7fr0Iz4ITa6Q' : 'ABQIAAAAl3l7uHrKScJW5A8LoyZrWRT2iLvoZZ4ypVVFuTZD1_70S9nIeBRkQo5r_Vqe2t-D4r_NxWEwreSF1g');
var SHOW_TIP_DELAY = 200;
var HIDE_TIP_DELAY =  100;

function PosObj(obj) {
	var b = obj.getBoundingClientRect(), doc = obj.ownerDocument, body = doc.body, docElem = doc.documentElement,
		clientTop = docElem.clientTop || body.clientTop || 0, 
		clientLeft = docElem.clientLeft || body.clientLeft || 0;

	return {x: b.left +  (docElem.scrollLeft || body.scrollLeft) - clientLeft,
			y: b.top  +  (docElem.scrollTop || body.scrollTop) - clientTop};

}


function g (id){
		return document.getElementById(id);
}

function gSzW(d) {
	var t = [0, 0], d=d || [document,window]; 
	if(typeof(d[1].innerWidth)=='number'){ 
		t = [d[1].innerWidth,d[1].innerHeight];
	}else if(d[0].documentElement && (d[0].documentElement.clientWidth||d[0].documentElement.clientHeight)){ 
		t = [d[0].documentElement.clientWidth,d[0].documentElement.clientHeight];
	}else if(d[0].body && ( d[0].body.clientWidth || d[0].body.clientHeight)){
		t = [d[0].body.clientWidth,d[0].body.clientHeight];
	}
		return t;
}

function showTip(o, data) {
		if (!o.getAttribute ('onmouseout')){
			o.setAttribute ('onmouseout', 'hideTip(this)');
		}
		if (o.shTm)return;
		if (o.hdTm)clearInterval (o.hdTm);
		
		o.shTm = setTimeout (function() {
						if (o.hdTm)clearInterval(o.hdTm);
						o.shTm = null;
						o.hdTm = null;
						o.className = 'tooltips_over';
						display_tooltip (o,data);
						o.tip = true;
				}, SHOW_TIP_DELAY);
}

function hideTip(o) {
	if (o.hdTm) return;
	if (o.shTm) clearInterval(o.shTm);
	
	o.hdTm = setTimeout(function(){
				if(o.shTm) clearInterval (o.shTm);
				o.shTm = null;
				o.hdTm = null;
					if (o.tip){ 
					o.className = 'tooltips';
					hidden_tooltip(o);
					o.tip=false;
					}
			}, HIDE_TIP_DELAY);
}

function display_tooltip (o, data){
	if (!window.ttip){
			ttip = document.createElement('div');
			ttip.className = 'tooltip_box';
			ttip.innerHTML = '<div class="arrow arrow_up" id="tooltip:arrow"><div></div></div> <div id="tooltip:content" class="content">aaa</div>';
			
			with(ttip.style){visibility='hidden'; top='0px'; left='-1000px';}
			document.body.appendChild(ttip);
			
	} else {
			ttip.style.visibility='hidden';
	}
	
			ttip.onmouseover = function(){ if (o.hdTm){ clearInterval (o.hdTm); o.hdTm = null;} };
			ttip.onmousemove = ttip.onmouseover;
			ttip.onmouseout = function(){ hideTip(o); };
			
		var type = typeof(data), pos = PosObj(o), Pos={x:0, y:0}, SzWin = gSzW(), html = '';
	
		ttip.style.width = 'auto';
		
		if (type=='string'){
			html = data;
			g('tooltip:content').innerHTML = html;
			var W = g('tooltip:content').offsetWidth;
			if( W<20)W = 20;
			ttip.style.width = (W>284) ? '300px' : (W)+'px';
		} else {
			html = '<a href="http://maps.google.com/maps?hl=en'+(data.m?'&q='+data.m:'')+''+(data.c?'&spn='+data.c:'')+'&z='+data.z+'" target="_blank" title="Go to Google Maps"><img src="http://maps.google.com/staticmap?zoom='+data.z+'&size=300x200&key='+KEY_GSTATIC_MAP;
			if (data.c)html += '&center='+data.c; 
			if (data.m)html +='&markers='+data.m;
			html += '" border="0"></a> ';
			if (data.t){ html += '<div class="c_">'+data.t+'</div>';}
			
			g('tooltip:content').innerHTML = html;
			ttip.style.width = '316px';
		}
		
			var H = ttip.offsetHeight;
			Pos.y = pos.y+o.offsetHeight+15;
			Pos.x = pos.x+((o.offsetWidth-ttip.offsetWidth)/2);
			
		if (Pos.x<10){
			Pos.x = 10;
			g('tooltip:arrow').style.left = ((pos.x-Pos.x)+(o.offsetWidth/2))+'px';
		} else {
			g('tooltip:arrow').style.left = '50%';
		}
		
		
		if (Pos.y+H > SzWin[1]){
			Pos.y = pos.y-H-15;
			g('tooltip:arrow').className='arrow arrow_down';
		} else {
			g('tooltip:arrow').className='arrow arrow_up';
		}
		
	ttip.style.top = Pos.y+'px';
	ttip.style.left = Pos.x+'px';
	ttip.style.visibility = 'visible';
}

function hidden_tooltip (o){
	if (window.ttip){
		ttip.style.visibility = 'hidden';
	}
}
