//------------------------------------
//	ENGAGE.JS
//	Author: 	Engage Interactive
//	Requires:	jquery 1.3.2
//				
//				
//------------------------------------

$(function(){
//BEGIN jQuery

	//CUFON
//	Cufon.replace('h2', 'h4', '#subnav .accordian > ul > li > a', { fontFamily: 'AmasisMT-Bold' });
	Cufon.replace('h2');
	Cufon.replace('h4');
	Cufon.replace('#subnav .accordian > ul > li > a');

	//TARGET BLANK REPLACEMENT
	
	$(".external").attr("target","_blank");
	
	//CLICKY FORM TITLES
	
	$('form input[title]').each(function(){
		$(this).attr('value', $(this).attr('title'));
	});
	$('form input[title]').focus(function(){
		if($(this).attr('value') == $(this).attr('title')){
			$(this).attr('value', '');
		}
	});
	$('form input[title]').blur(function(){
		if($(this).attr('value') == $(this).attr('title') || $(this).attr('value') == ''){
			$(this).attr('value', $(this).attr('title'));
		}
	});
	
	    
	// Stripey subnav   
    $('#subnav nav > ul > li:odd').addClass('odd');  
    $('#subnav nav > ul > li:even').addClass('even');  
      
	  
	  
	//////////////////////////
	// ACCORDIAN SUBNAV

	$('#subnav nav > ul > li > ul > li:odd').addClass('odd');
	$('#subnav nav > ul > li > ul > li:even').addClass('even');

	$('#subnav nav.accordian.people ul li a.office').click(function(){
		$l = $(this).parent('li');
		$u = $(this).next('ul');

		if( $l.hasClass('open') == true ){
//			Always want at least one to show
//			$l.removeClass('open');
			
		}else{
			$l.addClass('open').siblings('li.open').removeClass('open');
			segmentHeight($l);
		}
		
		return false;
	});
	
	function segmentHeight($e){
		h = $('#subnav nav.accordian ul li.open ul').height() - 10;
		$e.find('span.segments').css({height:h});
	}
	
	segmentHeight($('#subnav nav#people li.open'));


});


//////////////////////////
// EASING

jQuery.extend(jQuery.easing,{
	easeInOutExpo: function(x,t,b,c,d){
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	},
	easeInExpo: function (x, t, b, c, d) {
		return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
	},
	easeOutExpo: function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	}
});


//////////////////////////
// TIMERS

jQuery.timer = function(time,func,callback){
	var a = {timer:setTimeout(func,time),callback:null}
	if(typeof(callback) == 'function'){a.callback = callback;}
	return a;
};

jQuery.clearTimer = function(a){
	clearTimeout(a.timer);
	if(typeof(a.callback) == 'function'){a.callback();};
	return this;
};
