IE7 = navigator.userAgent.indexOf('MSIE 7') > -1
active = false;
var tooltip = {

	t: 0,
	cacheData: {},
	tooltip: $('#tooltip'),
	current: false,
	
	init: function() {
		
		$(document.body).append('<div id="tooltip"><div id="tooltip-top"></div><div id="tooltip-content"><div id="tooltip_q"></div></div><div id="tooltip-bottom"></div></div>');
		
		$('#vacancies a[id]').each(function(i) {
			$(this).bind('click', function() {
				$('#debug').text();
				tooltip.show(this.id);
//				$(this).css('border', '1px solid red');
				
				return false;
			});
			
//			$(this).bind('mouseover', tooltip.mouseoverHandler);
//			$(this).bind('mouseout', tooltip.mouseoutHandler);
		});
		
		$('#tooltip').bind('mouseover', this.mouseoverHandler);
		$('#tooltip').bind('mouseout', this.mouseoutHandler);
	},
	
	
	show: function(id) {

		if(this.current != id)
			active = false;

		this.current = id;
		
		if( active == false) 
		{
			var url = 'content/vacancy/'+ id + '.html';
			$('#tooltip_q').load(url);
	
			var offset = $('#'+id).offset();
			$('#tooltip').css({
				top:  (offset.top + 8) + 'px',
				left: (offset.left - 230) + 'px'
			});
			
			if(IE7)
				$('#tooltip').show();
			else
				$('#tooltip').fadeIn('fast');
			
			active = true;
		}
		else if(active == true) {
			this.hide();
			
		}
		
	},
	
	
	hide: function() {
		if(IE7)
			$('#tooltip').hide();
		else
			$('#tooltip').fadeOut('fast'); 
		active = false;
	},
	
	
	mouseoverHandler: function() {
		if(this.t) {
			clearTimeout(this.t);
		}
	},
	
	
	mouseoutHandler: function() {
		this.t = setTimeout(tooltip.hide, 1000);
	}
}



$(document).ready(function() {
	tooltip.init();
	//tooltip.show('msk-Account');
});