$().ready(function(){
	$('#jqm').jqm({ajax: '@href', trigger: 'a.jqma'});
	$('div.message').corner();
	$('#right div.box h2').corner('5px');
	$('div.box ul.razdeltree li.active').corner('5px');
	$('.treeCols').corner();
	$('#search').focus();
	$('ul.items li:even').addClass('odd');
	//$('ul.razdeltree li.l4').hide();
	//$('ul.razdeltree li.l5').hide();
	//$('ul.razdeltree li.l6').hide();
	$('ul.razdeltree li.active2').show();
	
	$('#content div.body a img').mouseover(function(){
		$(this).parent().attr('title', 'Кликните для увеличения');
	});

	$.datepicker.setDefaults(
        $.extend($.datepicker.regional["ru"])
    );
	
	$('input.date').datepicker({
		dateFormat: 'dd.mm.yy',
		changeYear: true,
		duration: ''
	});
	$('input.birth').datepicker( "option", "yearRange", '1900:2010' );

	width = $('body').css('width').substr(0,4);
	if(!width || width < 1100)
	{
		$('form.search').hide();
		$('#loginForm input').css('width', '75px');
		$('div.rightTopBody').css('text-align', 'left');
	}

     $('form.search').submit(function(){
	     q = $(this).contents('input.q').val();
         location.href='/search/index/'+q+'/';
         return false;
     });

     $('form.search2').submit(function(){
	     q = $('form.search2 input.q').val();
         location.href='/search/index/'+q+'/';
         return false;
     });


     
	/* Работа с оценками */

	var alreadyVote = false;

	$('div.stars a').mouseover(function(){
		if(!alreadyVote)
		{
			$(this).css('background-position', 'top');
			stars = $(this).prevAll('a');
			stars.css('background-position', 'top');
			count = stars.length+1;
			$(this).nextAll('div').html('Оценка <b>'+count+'</b>. Кликните для сохранения.');
		}
	});

	$('div.stars a').mouseout(function(){
		if(!alreadyVote)
		{
			$(this).css('background-position', 'bottom');
			$(this).prevAll('a').css('background-position', 'bottom');
			$(this).nextAll('div').html('');
		}
	});

	$('div.stars a').click(function(){
		if(!alreadyVote)
		{
			alreadyVote = true;
			$(this).nextAll('div').html('Спасибо! Ваша оценка сохранена.');
			$(this).parent().children('a').css('cursor', 'default');
		}
		return false;
	});
});

function ask(url, name, str, def)
{
    if(!def) def='';
    if(!str) str=name;
    value = prompt(str, def);
    if(value)
    {
        if (url.slice(url.length-1) == '/') amp='?'; else amp='&';
        location.href = url + amp + name + '=' + value;
    }
}

function agree(url, msg)
{
     if(!msg) msg = 'Вы уверены?';
     if (confirm(msg)) window.location.href=url;
}

