//Ajax Tooltip script: By JavaScript Kit: http://www.javascriptkit.com
//Last update (July 10th, 08'): Modified tooltip to follow mouse, added Ajax "loading" message.

var ajaxtooltip={
	fadeeffect: [true, 400], //enable Fade? [true/false, duration_milliseconds]
	useroffset: [10, 10], //additional x and y offset of tooltip from mouse cursor, respectively
	loadingHTML: '<div style="font-style:italic;color:#333;" id="fla_tooltip"><div style="background:url(images/package/bgloading.png);width:235px;height:48px;margin:5px 5px;"><img src="images/ajax-loader.gif" style="margin:6px 0 0 20px;float:left" /> <p style="margin:15px 0 0 37px;float:left">Fetching data...</p></div></div>',

	positiontip:function($tooltip, e){
		var docwidth=(window.innerWidth)? window.innerWidth-15 : ajaxtooltip.iebody.clientWidth-15;
		var docheight=(window.innerHeight)? window.innerHeight-18 : ajaxtooltip.iebody.clientHeight-15;
		var parentHeight = jQuery("#calendar ul").height()+jQuery("#calendar ul").offset().top;
		var parentWidth = jQuery("#calendar ul").width()+jQuery("#calendar ul").offset().left;
		var wScrollTop = jQuery(window).scrollTop();
		var twidth=233;//$tooltip.get(0).offsetWidth;
		var theight=200;//$tooltip.get(0).offsetHeight;
		var boundRight = parentWidth
		var boundBottom = docheight-(parentHeight-wScrollTop) 
		var tipx=e.pageX+this.useroffset[0];
		var tipy=e.pageY+this.useroffset[1];
		tipx=(e.clientX+twidth>boundRight)? tipx-twidth-(2*this.useroffset[0]) : tipx; //account for right edge
		tipy=(e.clientY+theight> (docheight -boundBottom))? tipy-theight-(2*this.useroffset[0])+30 : tipy; //account for bottom edge
		$tooltip.css({left: tipx, top: tipy});
	},

	showtip:function($tooltip, e){
			$tooltip.fadeIn(this.fadeeffect[1]).css({display:"block",opacity:1});
	},

	hidetip:function($tooltip, e){
			$tooltip.stop().fadeOut(200);
	}

}

jQuery(document).ready(function(){
	ajaxtooltip.iebody=(document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
	var tooltips=[]; //array to contain references to all tooltip DIVs on the page
	jQuery('*[title^="tip::"]').each(function(index){ //find all links with "title=pop:" declaration
		this.titleurl=jQuery.trim(this.getAttribute('title').split(':')[1]); //get URL of external file
		this.titleposition=index+' pos'; //remember this tooltip DIV's position relative to its peers
		tooltips.push(jQuery('<div class="ajaxtooltip"></div>').appendTo('body'));
		var $target=jQuery(this);
		//console.log($target);
		$target.data("title",$target.attr("title"));
		
		$target.removeAttr('title');
		$target.hover(
			function(e){ //onMouseover element
				
				jQuery('.borderdate').css({opacity:0.3});				
				jQuery(this).css({opacity:1});
				
				var $tooltip=tooltips[parseInt(this.titleposition)];
				var thisrel=this.getAttribute('dir');
				jQuery('.ajaxtooltip').stop().hide();
				var desc = thisrel.split('||');
				var _id = desc[0];
				var _img = desc[1];
				var _title = desc[2];
				var _detail = desc[3];
				var _world = desc[4];
				ajaxtooltip.positiontip($tooltip, e);
				//if (!$tooltip.get(0).loadsuccess){ //first time fetching Ajax content for this tooltip?
				
					$tooltip.html('<div id="date_'+_id+'" ></div>').show();
					$tooltip.get(0).loadsuccess=true;
					swfobject.embedSWF("popup_banner.swf", "date_"+_id,"233 ", "200", "9.0.0","js/swfobject/expressInstall.swf",
								{
									cl:_world,
									img:_img,
									title:_title,
									detail:_detail
								}, {scale: "noScale", wmode: "transparent" ,salign:"lt"});
					
				//}
					ajaxtooltip.showtip($tooltip, e);
			},
			function(e){ //onMouseout element
				var $tooltip=tooltips[parseInt(this.titleposition)];
				ajaxtooltip.hidetip($tooltip, e);
				jQuery('.borderdate').css({opacity:1});	
			}
		)
		$target.bind("mousemove", function(e){
			var $tooltip=tooltips[parseInt(this.titleposition)];
			ajaxtooltip.positiontip($tooltip, e);
			
		})
	})
})


