var timeoutSet=0;
var $j = jQuery.noConflict();

function swapHint()
{
	timeoutSet=0;
	$j('#topEstimateHint b').animate({'height': 'toggle', 'opacity': 'toggle'},'fast');
	$j('#topEstimateHint span').animate({'height': 'toggle', 'opacity': 'toggle'},'fast');
	if(timeoutSet==0) {
		setTimeout('swapHint()',3000);
		timeoutSet=1;
	}
}

$j(document).ready(function()
{
	swapHint();

	// filter
	var iniShowF=$j('#showF').attr('checked')?1:0;
	var iniShowM=$j('#showM').attr('checked')?1:0;
	var iniRateAgeFrom=$j('#rateAgeFrom').val();
	var iniRateAgeTo=$j('#rateAgeTo').val();

	$j('a#filter')
		.click(function() {
			$j('#filterSet').animate({'height': 'hide', 'opacity': 'hide'}, 'fast');
			$j(this).animate({'height': 'hide', 'opacity': 'hide'}, 'fast',
			function() {$j('div.whomToShow').animate({'height': 'show', 'opacity': 'show'}, 'slow')});
		});


	$j('#searchCr')
	.click(function() {
		$j('#filterSet').animate({'height': 'hide', 'opacity': 'hide'}, 'fast');
		$j('#filter').animate({'height': 'hide', 'opacity': 'hide'}, 'fast',
		function() {$j('div.whomToShow').animate({'height': 'show', 'opacity': 'show'}, 'slow')});
	});

	$j('h3#whomToShowBut')
		.css('cursor', 'pointer')
		.hover(function() {$j(this).css('text-decoration', 'underline')}, function() {$j(this).css('text-decoration', 'none')})
		.click(function() {
			$j('div.whomToShow').animate({'height': 'hide', 'opacity': 'hide'},'normal',
				function() {
					$j('a#filter').animate({'height': 'show', 'opacity': 'show'},'normal');
					//$j('#filterSet').animate({'height': 'show', 'opacity': 'show'}, 'fast');
				});
		});

	// login
	$j('.log a').click(openLogIn);

	//$j('button#logInButton').click(logIn);

	$j('.topEstimate .bg a')
		.css('cursor', 'pointer')
		.hover(function() {$j(this).css('top', '7px')}, function() {$j(this).css('top', '8px')})
		.mousedown(function() {$j(this).css('top', '8px')})
		.mouseup(function() {$j(this).css('top', '7px')});


	$j('.topModeration a')
		.css('cursor', 'pointer')
		.hover(function() {$j(this).css('top', '8px')}, function() {$j(this).css('top', '9px')})
		.mousedown(function() {$j(this).css('top', '9px')})
		.mouseup(function() {$j(this).css('top', '8px')});

	$j('.topEstimate .bg a.b2 u').css('opacity', 0.3);
	$j('.topEstimate .bg a.b4 u').css('opacity', 0.3);

	$j('a.b1')
		.hover(function() {scoreOver(1)}, function() {scoreOut(1)})
		.click(function() {vote(1)});
	$j('a.b2')
		.hover(function() {scoreOver(2)}, function() {scoreOut(2)})
		.click(function() {vote(2)});
	$j('a.b3')
		.hover(function() {scoreOver(3)}, function() {scoreOut(3)})
		.click(function() {vote(3)});
	$j('a.b4')
		.hover(function() {scoreOver(4)}, function() {scoreOut(4)})
		.click(function() {vote(4)});
	$j('a.b5')
		.hover(function() {scoreOver(5)}, function() {scoreOut(5)})
		.click(function() {vote(5)});

function hideTag(){
		$j('#showAll').attr('checked',false);
		$j('#showTagsBlock').animate({'height': 'hide', 'opacity': 'hide'}, 'fast');
}

function vote(i){
	var curFoto = $j('#currentFoto').attr('src');
	$j('#prevFoto').val(curFoto.substring(curFoto.lastIndexOf('/')+1, curFoto.length-4));
	$j('#vote').val(i);

	$j('#voteForm').submit();
	return true;
}

function swapHint(){
	timeoutSet=0;
	$j('#topEstimateHint b').animate({'height': 'toggle', 'opacity': 'toggle'},'fast');
	$j('#topEstimateHint span').animate({'height': 'toggle', 'opacity': 'toggle'},'fast');
	if(timeoutSet==0) {
		setTimeout('swapHint()',3000);
		timeoutSet=1;
	}
}

function scoreOver(score){
	$j('#topEstimateHint').hide();
	$j('#scoreHint')
		.show()
		.addClass('score'+score)
		.html(eval('score'+score));
}

function scoreOut(score){
	$j('#scoreHint')
		.removeClass('score'+score)
		.hide();
	$j('#topEstimateHint').show();
	if(timeoutSet==0) swapHint();
}

function openLogIn() {
	$j("li.log a").parent().animate({'height': 'hide', 'opacity': 'hide'},'fast',
	function() {
		$j('.logBox').animate({'height': 'show', 'opacity': 'show'},'normal');
		$j('#sendMePassBox').animate({'height': 'hide', 'opacity': 'hide'},'fast');
		$j('li.forgot').animate({'height': 'show', 'opacity': 'show'}, 'fast');

	});
	}
})