var start_date;

function OnlineDate()
{
	start_date=new Date(start_date.valueOf()+1000);
	x1=start_date.getHours();
	x2=start_date.getMinutes();
	x3=start_date.getSeconds();
	str=((x1<10)?'0'+x1:x1)+":"+((x2<10)?'0'+x2:x2)+":"+((x3<10)?'0'+x3:x3);
	$('#online-date i').html(str);
	setTimeout('OnlineDate()',1000);
}

$(document).ready(function()
{
	var scrollable_position=5;
	var scrollable_height=$('#scrollable-panel .scrollable-content').height();

	z=$('#online-date i').html();
	if ( z )
	{
		start_date=new Date();
		start_date.setHours(z.replace(/(\d+):\d+:\d+/,"$1"));
		start_date.setMinutes(z.replace(/\d+:(\d+):\d+/,"$1"));
		start_date.setSeconds(z.replace(/\d+:\d+:(\d+)/,"$1"));
		OnlineDate();
	}

	$('.gallery-detail a').click(function()
	{
		asd=window.open( $(this).attr('href') ,'foto-detail','width=550,height=665,top=1px,left=1px,scrollbars=yes,resizable=yes');
		asd.focus();
		return false;
	});

	$('.foto-report a.thumb').click(function()
	{
		//alert($(this).attr('href'));
		a=$(this).attr('href');
		$(this).attr('title',$('#foto-content a.title').attr('title'));
		$(this).html("<img src='"+$('#foto-content img').attr('src')+"'/>"+$('#foto-content a.title').attr('fotos')+" фото");
		$('#foto-content').load ( $(this).attr('href')+'?ajax=1' );
		$(this).attr('href',$('#foto-content a.title').attr('href'));
		return false;
	});

	$('#weather-currency .tablist td a').click(function()
	{
		if ($(this).hasClass('w'))
		{
			$('#weather-currency div.weather').show();
			$('#weather-currency div.currency').hide();
		}
		else
		{
			$('#weather-currency div.weather').hide();
			$('#weather-currency div.currency').show();
		}
		return false;
	});
	
	$('#birthdays-holidays .tablist td a').click(function()
	{
		if ($(this).hasClass('w'))
		{
			$('#birthdays-holidays div.birthdays').show();
			$('#birthdays-holidays div.holidays').hide();
		}
		else
		{
			$('#birthdays-holidays div.birthdays').hide();
			$('#birthdays-holidays div.holidays').show();
		}
		return false;
	});


	$('.panel .tablist a.ajax').click(function()
	{
		a=$(this).parent().parent().parent().parent().parent();
		if (!$('a.focus',a).is('a'))	
			a.append("<a class='focus'></a>");
		$('.tablist td',a).removeClass('current');
		$(this).parent().addClass('current');
		$('.focus',a).focus();
		if ($(this).attr('href')!='#')
		{
			$('.panel-content',a).load(
				$(this).attr('href')+'?ajax=1'
			);
		}
		return false;
	});
	
	$('#a-month-select').click(function()
	{
		$(this).hide();
		$('#form-month-select').show();
		return false;
	});
	$('#form-month-select').submit(function()
	{
		year=$('#form-month-select .select-year').val();
		month=$('#form-month-select .select-month').val();
		ajax=year+'-'+month+'-01';
		$('#calendar-content').load(
			'/news/calendar.php?ajax='+ajax+'&c_lenta='+$('#lenta_prefix').val(),
			null,
			function()
			{
				$('#calendar_loading').fadeOut("slow",function()
				{
					$('#calendar_please_select_day').show();
				});
				
			});
		$('#calendar_please_select_day').hide();
		$('#calendar_loading').show();
		return false;
	});
	
	
	$('#scrollable-panel a.down').click(function()
	{
		return false;
	});
	$('#scrollable-panel a.up').click(function()
	{
		return false;
	});
	
	$('#scrollable-panel a.down').mouseover(function()
	{
		$('#scrollable-panel .up').css('visibility','visible');
		$("#scrollable-panel .scrollable-content").animate(
			{top:(-1*scrollable_height+400)},
      		5000,
      		'linear',
      		function(){$("#scrollable-panel .down").css('visibility','hidden');} 
      	);
      	
	});
	
	$('#scrollable-panel a.up').mouseover(function()
	{
		$('#scrollable-panel .down').css('visibility','visible');
		$("#scrollable-panel .scrollable-content").animate(
			{top:0}, 
			5000,
			'linear',
			function(){$("#scrollable-panel .up").css('visibility','hidden');}
		);
		
		
	})
	
	$('#scrollable-panel a.down').mouseout(function()
	{
		$("#scrollable-panel .scrollable-content").stop();
				
	});
	$('#scrollable-panel a.up').mouseout(function()
	{
		$("#scrollable-panel .scrollable-content").stop();
				
	});
	
	$('.notice #scrollable-panel a.down').click(function()
	{
		return false;
	});
	$('.notice #scrollabl-panele a.up').click(function()
	{
		return false;
	});
	
	$('.notice #scrollable-panel a.down').mouseover(function()
	{
		$('.notice #scrollable-panel .up').css('visibility','visible');
		$(".notice #scrollable-panel .scrollable-content").animate(
			{top:(-1*scrollable_height+400)},
      		5000,
      		'linear',
      		function(){$(".notice #scrollable-panel .down").css('visibility','hidden');} 
      	);
      	
	});
	
	$('.notice #scrollable-panel a.up').mouseover(function()
	{
		$('.notice #scrollable-panel .down').css('visibility','visible');
		$(".notice #scrollable-panel .scrollable-content").animate(
			{top:0}, 
			5000,
			'linear',
			function(){$(".notice #scrollable-panel .up").css('visibility','hidden');}
		);
		
		
	})
	
	$('.notice #scrollable-panel a.down').mouseout(function()
	{
		$(".notice #scrollable-panel .scrollable-content").stop();
				
	});
	$('.notice #scrollable-panel a.up').mouseout(function()
	{
		$(".notice #scrollable-panel .scrollable-content").stop();
				
	});
	
	function VoteAction()
	{
		$('.vote ul li').mouseover(function()
		{
			$(this).addClass('over');
		});
		$('.vote ul li').mouseout(function()
		{
			$(this).removeClass('over');
		});
		$('.vote #vote-submit').click(function()
		{
			vote_form=$(this).parent().parent();
			$('#loading').show();
			ans = $('ul li input:checked',vote_form).val();
			$.post(
				vote_form.attr('action')+'&ajax=1',
				{answer:ans},
				function(data)
				{
					$('.vote .panel-content').html(data);
					$('#loading').hide();
					VoteAction();
				}
			);
			return false;
		});
	}
	$('.vote .tablist a.ajax').click(function()
	{
		VoteAction();
		return false;
	});
	
	VoteAction();
	
	
});


function MarkALL(n, id_id, chk){ 
	for(var i = 0; i <= n; i++){ 
		document.getElementById(id_id+i).checked = chk; //если кнопка "отметить все" отмечена, то chk будет содержать значение True, в противном случае False
	}
}