$(document).ready(function() {
	/* Navigation */
	
	$(document).ready(function() {
		$('.mainLabel > ul').each(function() {
			$(this).toggle();	
			$(this).addClass('currentOpen');			
		});
		$('.subsub').each(function() {
            if (!$(this).parent().hasClass('open')) {
		        $(this).toggle();
            }
		});
	});
	
	$('.mainLabel').mouseover(function() {
		$('.mainLabel').each(function() {
			$(this).parent().find('img.slider').remove();
		});

		$(this).parent().append('<img src="/images/slidedown.png" alt="slideDown" class="slider current" onclick="$(this).slideMenu(this)" />');
	});
	
	$('.hasSubs').click(function() {	
		
		/*
		if($(this).hasClass('currentOpen')) {					
			document.location.href=$(this).attr('href');
			return false;
		}
		
		$.cookie('currentOpen', null, { expires: -1});
		$.cookie('currentOpen', $(this).attr('href'), { expires: 1});
					
		$('.hasSubs').each(function() {
			$(this).next().slideUp();
			$(this).removeClass('currentOpen');			
		});	
		
		$(this).addClass('currentOpen');
		$(this).next().slideDown();	
		
		return false;	
		*/	
		return;
	});	
	
	$.fn.extend({
        slideMenu: function(element) {
			/*$(element).prev().prev().addClass('active');*/
			
			$('ul.sub').each(function() {
				$(this).slideUp();		
				/*$(this).prev().removeClass('active');*/
			});
			
			$(element).prev().slideDown();
        }
    });
});


// menutype switcher
/*
$('.menuswitch').click(function() {
	var typeNew = $(this).attr('rel');
	$.cookie('menutype', typeNew);
	location.reload();
});


switch($.cookie('menutype')) {
	case 'mouseoverslide':
		$('.mainLabel').mouseover(function() {
			if(!$.cookie('currentRunning')) {
				$.cookie('currentRunning', '1');
				if(!$(this).hasClass('openLabel')) {
					$('.mainLabel').each(function() {
						$(this).next().hide('fast');
						$(this).removeClass('openLabel');
					});
					$(this).next().slideDown('fast', function() {
						$.cookie('currentRunning', null);
					});
					$(this).addClass('openLabel');
				} else {
					$(this).removeClass('openLabel');
				}
			}
		});
		$('ul.subsub').hide();
			
		$('#wrapper').everyTime(750, 'controlled', function() {
			$.cookie('currentRunning', null);
		});
	break;
	case 'clickslide':			
		$('.mainLabel').click(function() {		
			if($(this).hasClass('i-am-link')) {
				return;
			}
			
			$('ul.sub').each(function() {
				$(this).slideUp();				
			});
			
			$('.mainLabel').each(function() {
				$(this).removeClass('i-am-link');			
			});
			$(this).addClass('i-am-link');
			$(this).next().slideDown();
			
			return false;
		});
	
		$('.hasSubs').click(function() {		
			if($(this).hasClass('i-am-link')) {
				return;
			}	
			$(this).next().slideToggle();
			$(this).addClass('i-am-link');	
				
			return false;
		});
	break;
	case 'clickmouseoverslide':	
	break;
}
*/

/* =================== */

/*
$('.mainLabel').mouseover(function() {
	if(!$(this).hasClass('openLabel')) {
		$(this).addClass('openLabel');
		$(this).next().slideToggle('slow');
		$('.mainLabel').next().slideUp('slow');
	} else {
		$(this).removeClass('openLabel');
		$(this).next().slideToggle('slow');
	}
	return false;
});
$('ul.subsub').hide();
$('ul.subsub').each(function() {
	if($(this).parent().hasClass('open')) {
	
	} else {
		$(this).hide();
	}
});
$('.mainLabel').click(function() {
	if(!$(this).hasClass('open')) {
		$('ul.sub').hide();
		$(this).addClass('openLabel');
		$(this).next().slideToggle('slow');
	} else {
		$(this).removeClass('openLabel');
		$(this).next().slideToggle('slow');
	}
	return false;
});

$('.hasSubs').click(function() {
	if(!$(this).next().hasClass('open')) {
		$(this).next().addClass('open');
		$(this).next().slideToggle('slow');
	} else {
		$(this).next().removeClass('open');
		$(this).next().hide('slow');
	}
	return false;
});

$('.hasSubsClickable').click(function() {
	if(!$(this).next().hasClass('open')) {
		$('.Clickable').parent().removeClass('open');
		$('.Clickable').parent().hide();
		$(this).next().addClass('open');
		$(this).next().slideToggle('slow');
		return false;
	} else {
		$(this).next().removeClass('open');
	}
});

$('.hasSubsClickable').dblclick(function() {
	$(this).next().removeClass('open');
	$(this).next().hide('slow');
	return false;
});*/