/* Author: 

*/

var currList;
var offset = 30;

$(document).ready(function(){
	$('#nav-about').mouseenter( function(e) {
		showList( $("#subnav-about"), 1);
	});
	$("#nav-service").mouseenter( function(e) {
		showList( $("#subnav-service"), 1);
	});
	$("#nav-careers").mouseenter( function(e) {
		showList( $("#subnav-careers"), -1);
	});
	
	listItemEvents( $('#subnav-about' ), 1 );
	listItemEvents( $('#subnav-service' ), 1 );
	listItemEvents( $('#subnav-careers' ), -1 );
	
});

function showList( e, dir ){

	
	var eid = e.attr('id');
	var cid = currList != undefined ? currList.attr('id') : "-";
	if( eid != cid ){
		if( currList != undefined ){
			hideList( currList );
		}
		var li = $(e).find( 'li' );
		li.each( function( idx ) {
			$(this).css('display', 'block');
			if( dir == -1 ){
				$(this).find( 'a' ).css( 'text-align', 'right' );
				$(this).css( 'text-align', 'right' );
			}
			
			$(this).stop( true, true );
			$(this).css( "margin-left", "-30px" );
			$(this).css('filter', 'alpha(opacity=0)');
			$(this).find('a').css('filter', 'alpha(opacity=0)');
			$(this).css({opacity :0, display: 'block'});
			
			var delay = idx * 100;
			$(this).delay( delay ).animate({ opacity: 1, marginLeft: "0" }, 'fast');
			$(this).find('a').delay( delay ).animate({ opacity: 1, marginLeft: "0" }, 'fast');
		});
		currList = e;
	}
}

function hideList( e ){
	var li = $(e).find( 'li' );
	li.each( function( idx ) {
		$(this).stop( true, true );
		$(this).fadeOut( "fast" );
	});
}

function listItemEvents( e, dir ){
	var xpos = dir * 10;
	//var xpos = 10;
	var a = $(e).find( 'a' );
	a.each( function(){ 
		$(this).mouseenter( function(){ 
			$(this).stop( true, true );
			$(this).animate({ left: xpos + "px" }, 'fast');
		}).mouseleave( function(){ 
			$(this).stop( true, true );
			$(this).animate({ left: "0" }, 'fast');
		})
	});
}


























