$(window).load(function()
{
//##################################################################	
//MENU	

	var ml = $('#menu li').length-1;
	
	var mp = 0;
	$('#menu ul li').each(function()
	{
		mp += $(this).width();
	});
	
	mp = 960-mp;
	
	mp = Math.floor((mp/ml)/2);

	
	$('#menu li').css(
	{
		'margin-left': mp,
		'margin-right': mp
	});
	
	$('#menu li:first').css(
	{
		'margin-left': 0
	});
	
	$('#menu li:last').css(
	{
		'margin-right': 0
	});	
	
	var mw = $('#menu ul').width();
	
	$('#menu ul').css(
	{
		'width': mw,
		'float': 'none'	
	});
});



$(document).ready(function()
{	
//##################################################################	
//MENU		
	
	
	$('#menu li').each(function()
	{
		$('.i2', this).css('padding-top', '50px');
	
		//$(this).filter(':not(.selected)').find('a').css('opacity', '0');
		
		$(this).append('<span class="i3">'+$(this).text()+'</span>');
	});
	
	
	
	$('#menu li').hover(function()
	{		
		$(this).addClass('hover');
		//$(this).filter(':not(.selected)').find('a').delay(200).animate({'opacity': '1'},600);
		
		$(this).filter(':not(.selected)').find('a').animate({'opacity': '0'},200).animate({'opacity': '1'},400);
	}, 
	function()
	{		
		/*
		$(this).filter(':not(.selected)').find('a').animate({'opacity': '0'}, 500, function()
		{
			$(this).parents('li').removeClass('hover');
		});		
		*/
		
		$(this).removeClass('hover');
	});
	
	
	
	$('#menu li').click(function()
	{
		window.location = $('a',this).attr('href');
		
		return false;
	});

	
//##################################################################	
//PORTFOLIO	
	
	
	$('.cw2').append('<div class="nav"><div class="prev"><a href="#" onclick="return false;"></a></div><div class="next"><a href="#" onclick="return false;"></a></div></div>');
	
	
	$('.cw2 .w').hide();
	$('.cw2 .w:first').show();
	
	var pf = $('.cw2 .w').get();
	var pfl = pf.length;
	var pfnr = 0;
	
	
	if(!($('.cw2 .w').eq(pfnr).prev('.w').length)) 
	{
		$('.cw2 .nav .prev').addClass('disabled');
	}
	
	if(!($('.cw2 .w').eq(pfnr).next('.w').length)) 
	{
		$('.cw2 .nav .next').addClass('disabled');
	}
	
	
	$('.cw2 .nav .prev').click(function(){		
		if(pfnr > 0)
		{
			pfnr -= 1;
			
			$('.cw2 .w').hide();		
			$(pf[pfnr]).show();	
		}
		
		if(pfnr == 0) {
			$(this).addClass('disabled');
		} 
		else 
		{
			$('.cw2 .nav > *').removeClass('disabled');
		}
	});	

	$('.cw2 .nav .next').click(function(){	
		if(pfnr+1 < pfl)
		{
			pfnr += 1;
			
			$('.cw2 .w').hide();		
			$(pf[pfnr]).show();	
		}
		
		if(pfnr+1 == pfl) {
			$(this).addClass('disabled');
		} 
		else 
		{
			$('.cw2 .nav > *').removeClass('disabled');
		}	
	});	
	
	
	
//##################################################################	
//KONTAKT	
		

	if($('.cw7').length)
	{
		$('.cw7 .w form').validate({	
			rules: {
				'f_1': {
					required: true,
					minlength: 5
				},
				
				'f_2': {
					required: false,
					minlength: 2
				},
				
				'f_3': {
					required: false,
					email: true
				},
				
				'f_4': {
					required: true,
					/*phone:true*/
					minlength: 9
				},
				
				'f_5': {
					required: true,
					minlength: 5
				}
			}
		});
	}

});
