/*
	©copyright pi-squared
 	superior web design and development since 2001
	-
	www.pi-squared.co.za
	-
	toolTip v1.01
*/

$(document).ready(function(){

	var active;

	function displayCompanyBio() {
		//STOP any animations (ie- fading out) that are still running from earlier - the two trues are for CLEARQUEUE (don't do any further queued actions), and GOTOEND (skip to the end result of those actions)
		$('#companyBio').stop(true,true);
		//replace the HTML content of companyBio div with the HTML content of the active div
		$('#companyBio').html($(active).html());

		if (($(active).html()) == null) {
			$('#companyBio').hide();	
		} else {
			//FADEIN the companyBio div
			$('#companyBio').fadeIn(300);
		};
	}

	function hideCompanyBio() {
		//FADEOUT the companyBio div
		$('#companyBio').fadeOut(150, function() {
			$('#companyBio').html("");
		});
	}
	
	function moveCompanyBio(e) {
		tipLeft = e.pageX-($('#companyBio').outerWidth()/2);
		tipRight = e.pageX+($('#companyBio').outerWidth()/2);
		if (tipLeft < 0) {
			tipLeft = 0;
		}
		if (tipRight > $(window).width()) {
			tipLeft = $(window).width() - $('#companyBio').outerWidth();
		}
		tipBottom = e.pageY+$('#companyBio').outerHeight();
		tipTop = e.pageY;
		if (tipBottom > $(window).height()) {
			tipTop = $(window).height() - $('#companyBio').outerHeight();
		}
		//use CSS to position the companyBio div where the mouse is - position: absolute, top: the mouse's y co-ordinates (PAGEY), left: the mouse's x co-ordinates (PAGEX) minus 150 (half the width of the companyBio div)
		$('#companyBio').css({'position':'absolute','top':tipTop,'left':tipLeft});
	}
	
	//on MOUSEOVER of defined MAP AREAS....
	$('.stuff img, #map area').mouseover(function(e){
		//get the name of the active div from the ALT ATTR of what we've moused over, and REPLACE any whitespace with nothing (ie- Squareroot Cool Media becomes SquarerootCoolMedia) - we're doing that so that the alt tag is correct (because we're not SquarerootCoolMedia, we're Squareroot Cool Media), but we can't have spaces in the class name
		active = '.' + $(this).attr("alt").replace(/ /g,'');
		if(isNaN(active)){
			displayCompanyBio();
		}

	//on MOUSEMOVE while still over the defined MAP AREAS...
	}).mousemove(function(e){
		moveCompanyBio(e);

	//on MOUSEOUT of the defined MAP AREAS...
	}).mouseout(function(e){
		hideCompanyBio();
	});

	$('#companyBio').hover(function() {
		$('#companyBio').stop(true,true);
	}, function() {
		hideCompanyBio();
	});
	
})