/**
* hoverIntent r6 // 2011.02.26 // jQuery 1.5.1+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne brian(at)cherne(dot)net
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev])}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev])};var handleHover=function(e){var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t)}if(e.type=="mouseenter"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob)},cfg.timeout)}}};return this.bind('mouseenter',handleHover).bind('mouseleave',handleHover)}})(jQuery);;
(function ($) {
	
function shieldOut(obj) {	
	//Start fading out the shield
	$('#shield').stop().animate({		
		opacity: 0
	},'slow');
	
	//Hide all text descriptions
	$('#text .blurb').hide();
	//Show the correct description
	list = obj.children('.desc-link')[0].className.split(' ');
	$('#text .'+list[0]).show();	
			
	//Start fading in our description
	$('#text').stop().animate({
		opacity: 1
	},{
		duration: 'slow'
	});	
}

function shieldIn() {	
	//Start fading out our description	
	$('#text').stop().animate({		
		opacity: 0
	},{
		duration: 'slow',
		complete: function(){			
			$('#text .blurb').hide(); //Hide all the text once the text is faded out
		}
	});
	
	//Start fading in our shield
	$('#shield').stop().animate({		
		opacity: 1		
	},'slow');	
	
}

//Document Ready
$(document).ready(function(){
	
	//Bind the hover intent of the text
	$('#desc li').hoverIntent(
			function(){
				shieldOut($(this));
			}, 
			function(){
				shieldIn();
			}
		);
	$('#desc li').hover(
			function(){
				$(this).children('#desc .desc-link').addClass('active');
				$(this).children('#desc .arrows').addClass('active');				
			},
			function(){
				$(this).children('#desc .desc-link').removeClass('active');
				$(this).children('#desc .arrows').removeClass('active');
			}
		);
	
});

function ajax_load_blurb_completed(data) {	

	//Once ajax returns with the loaded nodes change the text
	
	$('#desc .blurb_A').siblings('.desc-small').html(data['blurb_A']['title'][0]);
	$('#desc .blurb_B').siblings('.desc-small').html(data['blurb_B']['title'][0]);
	$('#desc .blurb_C').siblings('.desc-small').html(data['blurb_C']['title'][0]);
	$('#desc .blurb_A').html(data['blurb_A']['title'][1]);
	$('#desc .blurb_B').html(data['blurb_B']['title'][1]);
	$('#desc .blurb_C').html(data['blurb_C']['title'][1]);
	$('#text .blurb_A').html(data['blurb_A']['body']);
	$('#text .blurb_B').html(data['blurb_B']['body']);
	$('#text .blurb_C').html(data['blurb_C']['body']);
	$('#desc .arrows').html('&gt;&gt;');
	
	//Fade in the text	
	$('#desc').animate({
		opacity: 1
	}, 'slow');
}

//Send an ajax request immediately to load text
$.ajax({
	type: 'POST',
	url: '/load-blurb/ajax',		
	success: ajax_load_blurb_completed	
});

})(jQuery);
;

