//TOOLTIPS
$$('.toolTip').addEvents({
	'mouseenter':function(){
		var str		= this.get('rel');
		var pos		= this.getCoordinates(document.body);
		var cent	= 14-(pos.width/2);
		var cent2 	= 125-(pos.width/2);
		var x		= pos.left-cent;
		var x2		= pos.left-cent2;
		var y		= pos.top;
		toolTip(str,x,y,x2);
	},
	'mouseout':function(){
		if($('tipContainer2'))
		{
			$('tipContainer2').destroy();
		}
	}
});

var toolTip = function(str,x,y,x2)
{
	var tipCont = new Element('div',{
		'id':'tipContainer2',
		'styles':{
			'position':'absolute',
			'width':'auto',
			'height':'auto',
			'left':x,
			'top':y,
			'z-index':2000
		}
	});

	var tipCorner1 = new Element('div',{
		'id':'tipCorner1',
		'styles':{
			'position':'absolute',
			'width':14,
			'height':14,
			'left':0,
			'top':0,
			'background-image':'url(js/popsCorners.png)',
			'background-position':'left top'
		}
	});
	var tipCorner2 = new Element('div',{
		'id':'tipCorner2',
		'styles':{
			'position':'absolute',
			'width':14,
			'height':14,
			'right':0,
			'top':0,
			'background-image':'url(js/popsCorners.png)',
			'background-position':'right top'
		}
	});
	var tipCorner3 = new Element('div',{
		'id':'tipCorner3',
		'styles':{
			'position':'absolute',
			'width':14,
			'height':14,
			'right':0,
			'bottom':0,
			'background-image':'url(js/popsCorners.png)',
			'background-position':'right bottom'
		}
	});
	var tipCorner4 = new Element('div',{
		'id':'tipCorner4',
		'styles':{
			'position':'absolute',
			'width':14,
			'height':14,
			'left':0,
			'bottom':0,
			'background-image':'url(js/popsCorners.png)',
			'background-position':'left bottom'
		}
	});
	var tipBorderTop = new Element('div',{
		'id':'tipBorderTop',
		'styles':{
			'position':'absolute',
			'width':0,
			'height':14,
			'left':14,
			'top':0,
			'background-image':'url(js/popsBordersHoriz.png)',
			'background-position':'left top'
		}
	});
	var tipBorderBot = new Element('div',{
		'id':'tipBorderTop',
		'styles':{
			'position':'absolute',
			'width':0,
			'height':14,
			'left':14,
			'bottom':0,
			'background-image':'url(js/popsBordersHoriz.png)',
			'background-position':'left bottom'
		}
	});

	var tipTextCont = new Element('div',{
		'id':'tipTextCont',
		'styles':{
			'position':'relative',
			'width':28,
			'height':28,
			'overflow':'hidden'
		}
	});
	var tipText = new Element('div',{
		'id':'tipText',
		'html':str,
		'styles':{
			'position':'absolute',
			'width':222,
			'height':'auto',
			'top':0,
			'left':0,
			'color':'#000',
			'padding':14
		}
	});
	var tipInnerBg = new Element('div',{
		'id':'tipInnerbg',
		'styles':{
			'position':'absolute',
			'width':0,
			'height':0,
			'top':14,
			'left':14,
			'background-color':'#fff'
		}
	});

	var tipGrow = new Fx.Morph(tipTextCont,{
		'duration':100
	});
	var tipGrow2 = new Fx.Morph(tipCont,{
		'duration':100
	});
	var tipBorderTopM = new Fx.Morph(tipBorderTop,{
		'duration':100
	});
	var tipBorderBotM = new Fx.Morph(tipBorderBot,{
		'duration':100
	});
	var tipInnerBgM = new Fx.Morph(tipInnerBg,{
		'duration':100
	});

	tipCont.inject(document.body);
	tipBorderTop.inject(tipCont);
	tipBorderBot.inject(tipCont);
	tipCorner1.inject(tipCont);
	tipCorner2.inject(tipCont);
	tipCorner3.inject(tipCont);
	tipCorner4.inject(tipCont);
	tipInnerBg.inject(tipCont);
	tipTextCont.inject(tipCont);
	tipText.inject(tipTextCont);

	var textHeight		= $('tipText').getSize();
	var tipTextY		= textHeight.y;
	var tipVertBordY	= tipTextY-28;

	var tipBorderLeft = new Element('div',{
		'id':'tipBorderLeft',
		'styles':{
			'position':'absolute',
			'width':14,
			'height':0,
			'left':0,
			'top':14,
			'background-image':'url(js/popsBordersVert.png)',
			'background-position':'left top'
		}
	});
	var tipBorderRight = new Element('div',{
		'id':'tipBorderRight',
		'styles':{
			'position':'absolute',
			'width':14,
			'height':0,
			'right':0,
			'top':14,
			'background-image':'url(js/popsBordersVert.png)',
			'background-position':'right top'
		}
	});

	tipBorderLeft.inject(tipCont);
	tipBorderRight.inject(tipCont);

	var tipBorderLeftM = new Fx.Morph(tipBorderLeft,{
		'duration':100
	});
	var tipBorderRightM = new Fx.Morph(tipBorderRight,{
		'duration':100
	});

	//var tipH = tipCont.getSize();
	//var tipH = tipTextY
	var tipY2 = y-tipTextY;
	var tipY = y-tipTextY-10;
	$('tipContainer2').setStyle('top',tipY2);

	tipGrow.start({
		'width':250,
		'height':tipTextY
	});
	tipGrow2.start({
		'top':tipY,
		'left':x2
	});
	tipBorderTopM.start({
		'width':222
	});
	tipBorderBotM.start({
		'width':222
	});
	tipBorderLeftM.start({
		'height':tipVertBordY
	});
	tipBorderRightM.start({
		'height':tipVertBordY
	});
	tipInnerBgM.start({
		'width':222,
		'height':tipVertBordY
	});
}

