/*	DOM Ready events
----------------------------------------------- */
$j(document).ready(function() {

	/* Fire home page specific functions */
	if ($j('body.futurefinder-home')) {
		
		// add speech bubble
		$j('.charactergrid').append('<div id="Bubble" class="bubble"><p></p></div>');
		
		
		$j('.charactergrid .icon').mouseover(function(){
		
			// define the bubble for this charactergrid!!
			var bubble = $j(this).parent().children('.bubble');
			
			bubble.hide();
			
			var position = $j(this).position();
			var x = (position.left+60)+'px';
			var y = (position.top-220)+'px';
			var color = $j(this).find("img").attr("class");
			var text = $j(this).find("a").attr("title");
			
			if($j(this).hasClass('last')) {
				x = (position.left-150)+'px';
				$j('.bubble').css({ left:x, top:y }).removeClass().addClass('bubble bubble-'+color+'-right');
			}
			else{
				$j('.bubble').css({ left:x, top:y }).removeClass().addClass('bubble bubble-'+color);
			}
			
			bubble.children('p').text(text);
			bubble.show();
			
		});
		
		$j('.charactergrid').mouseout(function(){
			$j(this).children('.bubble').hide();
		})
		
		$j('.bubble').mouseover(function(){
			$j(this).show();
		});
		
		// hide all chars
		$j('.charactergrid').hide();

		// show a random set from the available 5
		$j('.charactergrid').eq(Math.round(Math.random()*4)).show();
	}

});
