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

$(function(){
//BEGIN jQuery

	//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'));
		}
	});
	
	//NAV
	/*
	$('#nav li.products').hover(
			function(){
				$('#subnav').show();
			},
			function(){
				$('#subnav').hide();
			}
	);
	*/
	
	//HOMEPAGE PRODUCTS STUFF
	$('.subinfo').hide();
	
	$(".subinfo:eq(0)").show();
	$('#home_products li:eq(0)').children("a").addClass("on");
	var li = $('#home_products li').hover(
			function(){
				$('#home_products li a').removeClass("on");
				$('.subinfo').hide();
				$(".subinfo:eq("+li.index(this)+")").show();
				$(this).children("a").addClass("on");
			}
	);
	
	// VIP SIDEBAR
	
	sidebarBusy = false;
	
	$('#vip_sidebar ul li:not([class*="recent"]) ul').hide();
	
	$('#vip_sidebar ul li a:first-child').click(function(){
		if(sidebarBusy == false){
			sidebarBusy = true;
			$(this).parent('li').siblings('li').children('ul:visible').stop([]).animate({height:'hide'}, 600, 'easeInOutExpo');
			$(this).next('ul').stop([]).animate({height:'show'}, 600, 'easeInOutExpo',function(){
				sidebarBusy = false;
			});
		}
		return false;
	});
	
	// services sidebar
	/*
	$('#services_sidebar ul li:not([class*="open"]) ul').hide();
	
	$('#services_sidebar ul li a.clickme').click(function(){
		if(sidebarBusy == false){
			sidebarBusy = true;
			$(this).parent('li').siblings('li').children('ul:visible').stop([]).animate({height:'hide'}, 600, 'easeInOutExpo');
			$(this).next('ul').stop([]).animate({height:'show'}, 600, 'easeInOutExpo',function(){
				sidebarBusy = false;
			});
		}
		return false;
	});
	*/
	
});

//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;
	}
});