jQuery(document).ready(function(){
	jQuery('#dd-nav > ul > li:first').addClass('dd-li-first');
	jQuery('#dd-nav > ul > li:last').addClass('dd-li-last');
	
	jQuery('#dd-nav li').each(function(){
		if( jQuery(this).find('> .dd').length > 0 ){
			jQuery(this).addClass('dd-li-hasdd');
		}
	});
	jQuery('#dd-nav > ul > li > .dd li .dd').addClass('second-drop');
	
	jQuery('#dd-nav .dd').hide();
	
	jQuery('#dd-nav li').hover(
		function(){
			var sub = jQuery(this).find('> .dd').eq(0);
			
			if( sub.length == 0 )
				return;
				
			sub.show();
			jQuery(this).addClass('dd-li-active');
			jQuery(this).find('a:eq(0)').addClass('dd-a-active');
		},
		function(){
			var sub = jQuery(this).find('> .dd').eq(0);
			
			if( sub.length == 0 )
				return;
				
			sub.hide();
			jQuery(this).removeClass('dd-li-active');
			jQuery(this).find('a:eq(0)').removeClass('dd-a-active');
		}
	);
	
	
	// Set active class
	var location = window.location.href;
	var active_link = false;
	jQuery('#dd-nav').find('a').each(function(){
		var href = jQuery(this).attr('href');
		if( location.indexOf(href) != -1 ){
			active_link = jQuery(this);
			return false;
		}
	});
	
	if( location.indexOf('aspx') == -1 ) {
		active_link = jQuery('#dd-nav a[href="/default.aspx"]');
	}
	
	if( active_link ) {
		active_link.parents('li').each(function(){
			if( jQuery(this).parent().parent().attr('id') == 'dd-nav' ){
				jQuery(this).addClass('active');
				jQuery(this).find('a').eq(0).addClass('active');
				return false;
			}
		});
	}
	
	if( $('.side-title').length > 0 ) {
		$('.side-title').html($('#dd-nav a.active:eq(0) small.cnt').text() );
		var location = window.location.href;		
		var active_link = false;
		$('#dd-nav').find('a').each(function(){
			var href = $(this).attr('href');
			if( location.indexOf(href) != -1 ){
				active_link = $(this);
				return false;
			}
		});
		if( active_link ) {
			active_link.parents('li').each(function(){
				if( $(this).parent().parent().attr('id') == 'dd-nav' ){
					$('.side-title').html( $(this).find('a').eq(0).find('small.cnt').html() );
					return false;
				}
			});
		}
	};
	
	if( typeof(DONT_USE_DEFAULT_STYLE) == 'undefined' || !DONT_USE_DEFAULT_STYLE )
		jQuery('#dd-nav').addClass('default-menu');
	
});
