$(document).ready(function()
{
	$(".vmenu > li > div").click(function()
	{
		if( $(this).next().is(':visible') == false )
		{
			$('.vmenu ul').slideUp(300);
		} 
		$(this).next().slideToggle(300);
	});
	
	if( $.cookie( 'tgl-userroom' ) )
	{
		$( '#'+$.cookie( 'tgl-userroom' ) ).next().show();
	}

	if( $.cookie( 'bevn' )==1 )
	{
		$( '#tgl-events' ).next().hide();
		$( '#tgl-news' ).next().show();
	}

	if( $.cookie( 'bevn' )==2 )
	{
		$( '#tgl-events' ).next().show();
		$( '#tgl-news' ).next().hide();
	}

	$(".head-invtgl").click(function()
	{
		if( $(this).next().is(':visible') == false )
			 $.cookie( $(this).attr('id'), $(this).attr('id'), {expires: 7, path: '/'} );
		else $.cookie( $(this).attr('id'), null, {path:'/'} );

		$(this).next().slideToggle(200);
	});
	
	$(".head-ntgl").click(function()
	{
		if( $(this).next().is(':visible') == false )
		{
			$.cookie( 'bevn', '1', {expires: 7, path: '/'} );

			$('.head-evtgl').next().slideToggle(200);
			$(this).next().slideToggle(200);
		}
	});
	
	$(".head-evtgl").click(function()
	{
		if( $(this).next().is(':visible') == false )
		{
			$.cookie( 'bevn', '2', {expires: 7, path: '/'} );

			$('.head-ntgl').next().slideToggle(200);
			$(this).next().slideToggle(200);
		}
	});	

	$('input.ival').focus( function ()
	{
		if ( $(this).val() == $(this).attr('title') ) $(this).val('').css({color: '#000000'});
	});
	
	$('input.ival').blur( function ()
	{
		if ( $(this).val() == '' ) $(this).val( $(this).attr('title') ).css({color: '#808080'});
	});
	
	$('.rss').click(function(event){ event.stopPropagation();});
});

function onfocusLogin( obj )
{
	if( $(obj).val() == "E-mail" ) $(obj).val("");	
}

function onblurLogin( obj )
{
	if( $(obj).val() == "" ) $(obj).val("E-mail");
}

function onfocusPassword( obj )
{
	if( $(obj).val() == "Пароль" )
	{
		$(obj).replaceWith('<input id="userwpassword" type="password" class="authorization-input-text" name="password" value="" onfocus="onfocusPassword(this);" onblur="onblurPassword(this);"/>');
		$("#userwpassword").focus();
	}
}

function onblurPassword( obj )
{
	if( $(obj).val() == "" )
	{
		$(obj).replaceWith('<input id="userwpassword" type="text" class="authorization-input-text" name="password" value="Пароль" onfocus="onfocusPassword(this);" onblur="onblurPassword(this);"/>');
	}
}
