/*	ChillTip Version 1.2 - jQuery PlugIn by Christopher Hill - (http://www.chillwebdesigns.co.uk/) Last Modification: 25/12/10
	For more information, visit: (http://www.chillwebdesigns.co.uk/chilltip.html)
	Licensed under the Creative Commons Attribution 3.0 Unported License - http://creativecommons.org/licenses/by/3.0/
	- Free for use in both personal and commercial projects
	- Attribution requires leaving author name, author link, and the license info intact */
	
	// Settings for modification.													.
	ChillTipClassName	= ".ChillTip"; // Name of Class Used in the html
	ChillTipColor 		= "#000"; 	// ChillTip background color in hex		
	ChillTipBorderColor = "#333"; 	// ChillTip border colour in hex
	ChillTipBorderWidth	= "2"; 		// ChillTip border size in pixels
	ChillTipTextColor	= "#fff"; 	// ChillTip main font colour in hex		
	ChillTipTextSize	= "11"; 	// ChillTip content text size in pixels
	ChillTipTextPadding	= "10"; 	// ChillTip text padding size in pixels
	ChillTipOpacity 	= "90"; 	// ChillTip opacity in % (0-100)	
	ChillTipWidth		= "200"; 	// Maximum width of ChillTip in pixels	
	ChillTipFadeTime	= 250; 		// ChillTip fade in time in milliseconds
	ChillTipTopOffset 	= 20; 		// ChillTip mouse top offset in pixels
	ChillTipRightOffset = 20; 		// ChillTip mouse right offset in pixels
	ChillTipTextFont	= "Arial, Helvetica, sans-serif"; // ChillTip content font family	

	// The colors below can be changed to get the colour you desire
	ColorOne			= "#0033ff"; // This is color Blue in hex
	ColorTwo			= "#ff00cc"; // This is color Pink in hex
	ColorThree			= "#33cc00"; // This is color Green in hex
	ColorFour			= "#9900ff"; // This is color purple in hex	
	ColorFive			= "#ff0000"; // This is color Red in hex
	ColorSix			= "#ffff00"; // This is color Yellow in hex	
	
(function($){	

$(function(){							

// ChillTip Function
$.fn.ChillTip = function(){
		
	this.each(function(){
	// Get the title of class ChillTip.
	var title = this.title;
	// If class=ChillTip title check, if not empty or undefinded then run ChillTip
	if($(this).attr('title') != '' && $(this).attr('title') != 'undefined'){
	// Clear ChillTip title to prevent default browser tooltip showing.
	this.title = ''; 
	// ChillTip Hover Function
	$(this).hover(function(e){
						   
	var mousex 		= e.pageX +20; // Get X coodrinates.
    var mousey 		= e.pageY -20; // Get Y coordinates.
	
	// Add div chilltip to body
	$('body').append('<div id="chilltip"><p>' + title + '</p></div>');
		// ChillTip Styles								  
		$('#chilltip').css({
						background:ChillTipColor, 
						border:ChillTipBorderWidth + 'px solid', 
						borderColor:ChillTipBorderColor,					
						display:'none', 
						fontFamily:ChillTipTextFont, 
						height:'auto', 
						minWidth:'10px', 
						top:mousey, 
						left:mousex,
						maxWidth:ChillTipWidth + 'px', 
						position:'absolute', 
						width:'auto', 
						Zindex:'1001'
						});			
		// ChillTip paragraph styles
		$('#chilltip p').css({
						color:ChillTipTextColor, 
						float:'left', 
						fontSize:ChillTipTextSize + 'px',
						margin:'0', 
						padding:ChillTipTextPadding + 'px', 
						textAlign:'justify',					
						width:'auto'
						});
		// Span colors
		$('#chilltip p span.one').css({color:ColorOne}); 
		$('#chilltip p span.two').css({color:ColorTwo}); 
		$('#chilltip p span.three').css({color:ColorThree});
		$('#chilltip p span.four').css({color:ColorFour}); 
		$('#chilltip p span.five').css({color:ColorFive}); 
		$('#chilltip p span.six').css({color:ColorSix});	
		// IE6 or below Styles calculate MaxWidth 
		if($.browser.msie && $.browser.version <= 6 ){
		var ChillPWidth = $('#chilltip').width();
		if(ChillPWidth > ChillTipWidth){
		$('#chilltip').css({width:ChillTipWidth});
		}
		}		
		// If opacity = 100 fade in ChillTip
		if(ChillTipOpacity == '100'){$('#chilltip').fadeIn(ChillTipFadeTime);}
		// If opacity > 100 change the opacity of ChillTip then fade in
		else{$('#chilltip').css({
						filter:'alpha(opacity=ChillTipOpacity)', 
						mozOpacity:'0.' + ChillTipOpacity, 
						khtmlOpacity: '0.' + ChillTipOpacity,
						opacity: '0.' + ChillTipOpacity}).fadeIn(ChillTipFadeTime);}
		},		
		// MouseOut Function
		function(){
		// Remove ChillTip form body.
		$('#chilltip').remove();
		});	
		}
		}).css({cursor:'pointer'});				
		// Get height from class=ChillTip to top of window
		var borderT = $(window).scrollTop();
		// Get window width
		var borderR = $(window).width();
		// Get ChillTip width
		var chillW  = $('#chilltip').width();
		// Get ChillTip height
		var chillH  = $('#chilltip').height();		
		
		// Mousemove keep ChillTip in window.	
		this.mousemove(function(e){		
		if(borderR - (ChillTipRightOffset * 2) >= chillW  + e.pageX){
		left_pos = e.pageX + ChillTipRightOffset;
		}
		else{left_pos = borderR - chillW - ChillTipRightOffset;}
		if(borderT + (ChillTipTopOffset * 2) >= e.pageY - chillH){
		top_pos = borderT + ChillTipTopOffset;
		}
		else{top_pos = e.pageY - chillH - ChillTipTopOffset;}	
		var chillL = left_pos;
		var chillT = top_pos;
		$('#chilltip').css({left:chillL, top:chillT});
		});

				
// returns the jQuery object to allow for chainability.
return this;
}			
												
// Start ChillTip function if class=ChillTip													   
$(ChillTipClassName).ChillTip();															   
														   
// End of ChillTip
});
})(jQuery) 
