/*-----------------------------------------------------------------------------------------------*/

/*                                      SIMPLE jQUERY TOOLTIP                                    */

/*                                      VERSION: 1.1                                             */

/*                                      AUTHOR: jon cazier                                       */

/*                                      EMAIL: jon@3nhanced.com                                  */

/*                                      WEBSITE: 3nhanced.com                                    */

/*-----------------------------------------------------------------------------------------------*/



$(document).ready(function() {

	var txt = '';

	$('.toolTip').hover(

		function() {

		this.tip = this.title; this.tip = this.title;

		var text = $(this).html();

		

		var html = $.ajax({ type: "POST", url: "update.php", data: "sid="+this.rel, async: false}).responseText;

		txt = html.split('||')

		

		$(this).append(

			'<div class="toolTipWrapper">'

				+'<div class="toolTipTop"><img src="images/ques.gif" hspace="4" vspace="7" border="0" align="right" style="cursor:pointer"  onclick="window.location.href=\'advertise.php\'; return false;"></div>'

				+'<div class="toolTipMid" onclick="window.open(\''+txt[1]+'\'); return false;">'

					+ txt[0]

				+'</div>'

				+'<div class="toolTipBtm"></div>'

			+'</div>'

		).css("z-index","10000");

		

		oldId = this;

		

		this.title = "";

		this.width = $(this).width();

		$(this).find('.toolTipWrapper').css({left:this.width-42})

		$('.toolTipWrapper').show();

		

		//Call Ajax

		$.ajax({

		  type: "POST",

		  url: "update.php",

		  data: "word="+text+"&aid="+this.rel,

		  success: function(msg){

			  //alert(msg);

			}

		});

						

		

	},

	function() {

		$('.toolTipWrapper').fadeOut(100);

		$(this).children().remove();

			this.title = this.tip;

			$(this).css("z-index","0");

		}

	);

	

	$('.tip').hover(

		function() {

		var html = $.ajax({ type: "GET", url: "tooltip.php", data: "id="+this.rel, async: false}).responseText;

			

		$(this).append(

			'<div class="tipWrapper" style="position:absolute; background:#FFFFFF; border:solid 1px #CCCCCC; padding-left:10px; padding-bottom:3px;"><div class="tipMid" style="width:180px;">'+html+'</div></div>'

		).css("z-index","10000");

		

		// get the field position

		var sf_pos    = $(this).offset();

		var sf_top    = sf_pos.top;

		var sf_left   = sf_pos.left;

		this.width = $(this).width();
	    //alert(sf_left);

		if(sf_left > 680) {

			$(this).find('.tipWrapper').css({width:300})

			$(this).find('.tipWrapper').css({left:-304})

			$(this).find('.tipWrapper').css({top:10})

		} else {

			$(this).find('.tipWrapper').css({width:190})

			//$(this).find('.tipWrapper').css({left:this.width+5})
			$(this).find('.tipWrapper').css({left:sf_left})


		}

		

		$('.tipWrapper').show();

	},

	function() {

		$('.tipWrapper').fadeOut(100);

			$(this).html('<img src="images/info_icon.gif" border="0" align="absmiddle" />');

			$(this).css("z-index","0");

		}

	);
	
	//-------------222-------------
	
		$('.tip2').hover(

		function() {

		var html2 = $.ajax({ type: "GET", url: "tooltip.php", data: "id="+this.rel, async: false}).responseText;

			

		$(this).append(

			'<div class="tipWrapper2" style="position:absolute; background:#FFFFFF; border:solid 1px #CCCCCC; padding-left:10px; padding-bottom:3px;"><div class="tipMid2" style="width:180px;">'+html2+'</div></div>'

		)

		var sf_pos2    = $(this).offset();

		var sf_top2    = sf_pos2.top;

		var sf_left2   = sf_pos2.left;

		this.width = $(this).width();

		//alert(sf_left2);
	


		if(sf_left2 > 800) {

			$(this).find('.tipWrapper2').css({width:190})

			$(this).find('.tipWrapper2').css({left:50})

			$(this).find('.tipWrapper2').css({top:500})


		} else {

			//alert(sf_left2);
			$(this).find('.tipWrapper2').css({width:190})
			//$(this).find('.tipWrapper').css({left:this.width+5})
			$(this).find('.tipWrapper2').css({left:sf_left2})


		}




		

		$('.tipWrapper2').show();

	},

	function() {

		$('.tipWrapper2').fadeOut(100);

			$(this).html('<img src="images/info_icon.gif" border="0" align="absmiddle" />');

			$(this).css("z-index","0");

		}

	);
	
	//--------------------------

});
