/**
 * @author on1ooker
 */

var quiz_count = 3;

$(document).ready(function(){
	
	Cufon.replace('.adv-blocks .title', {fontFamily: 'Calibri'});
	Cufon.replace('.notices .title', {fontFamily: 'Segoe Print'});
	
	$('.button-answer').click(function(){
		
		if ($('input:checked').length > 0)
		{
			$('body').css('cursor', 'wait');
			$.post($(this).attr('rel'), {item: $('input:checked').attr('value')}, function (data, textStatus) 
			{
				$('body').css('cursor', 'default');
		
				if (textStatus != '200')
				{
					$('.quiz').html(data);
				}	
				else
					alert('При голосовании произошла ошибка!');
			}, 'html');
		}	
		return false;
	});
	
	$('ul.vacancies-list').each(function(){
		$(this).css('display','none');	
	});
	
	$('ul.vacancies > li > a').click(function(){
  		$(this).parent().find('ul').slideToggle(250, function(){
			if (($.browser.msie) && ($.browser.version == 8)) {$('.center-block').height($('.center-block').find('.content').height())};
		});
		return false;
	})	
	
	$('.big-events .events').each(function(){
		$(this).css('display','none');	
	});
	
	$('.big-events a.cafe-name').click(function(){
  		$(this).parent().find('.events').slideToggle(250, function(){
			if (($.browser.msie) && ($.browser.version == 8)) {$('.center-block').height($('.center-block').find('.content').height())};
		});
		return false;
	})	
	
	$('.search-block .search-query').bind('blur',function(){
		if ($(this).attr('value') == '')
		{
			$('.search-block .hint').fadeIn(300);
		};
	})

	$('.search-block .search-query').focus(function(){
		$('.search-block .hint').fadeOut(10);
	});

	$('.search-block .hint').click(function()
	{
		$(this).fadeOut(10);
		$('.search-block .search-query').focus();
	})
	
	$('.question-form .update_captcha').click(function(){
		
		$.get($(this).attr('href'), null, function (data, textStatus) 
		{
			$('.question-form .captcha').find('img').replaceWith(data);
		});
		return false;
	})
	
	
	
	/*$('.adv-blocks td').hover(
		function(){
			
			if ($(this).hasClass('single-block'))
			{
				$(this).addClass('single-block-hover');
			
				if ($(this).parent().hasClass('top'))
				{
					var index = $('.adv-blocks .top td').index($(this));
					$('.adv-blocks .bottom').find('td').eq(index).addClass('single-block-hover');
				}
				else
				{
					var index = $('.adv-blocks .bottom td').index($(this));
					$('.adv-blocks .top').find('td').eq(index).addClass('single-block-hover');
				}
			 }		
		},
		function(){
			if ($(this).hasClass('single-block-hover')) 
			{
				$(this).removeClass('single-block-hover');
				
				if ($(this).parent().hasClass('top')) {
					var index = $('.adv-blocks .top td').index($(this));
					$('.adv-blocks .bottom').find('td').eq(index).removeClass('single-block-hover');
				}
				else {
					var index = $('.adv-blocks .bottom td').index($(this));
					$('.adv-blocks .top').find('td').eq(index).removeClass('single-block-hover');
				}
			}	
		}
	);
	*/
	
	
	$('.adv-blocks .adv-block').hover(
		function(){
			$(this).find('.right').css('z-index','100');
		},
		function(){
			$(this).find('.right').css('z-index','0');				
		}
	);
	
	$('table').each(function(){
		if (!$(this).hasClass('files') && !$(this).hasClass('direction') && !$(this).parent().hasClass('timetable'))
			$(this).find('tr:odd').addClass('odd');
	})
	
	$('.thickbox').fancybox({ 
		'zoomSpeedIn': 200, 
		'zoomSpeedOut': 200,
		'frameWidth': 100,
		'frameHeight': 100,
		'overlayShow': true,
		'hideOnContentClick' :false,
		'centerOnScroll' : false,
		'autoScale': false
	});
	
	
	$('.main-menu .fresh-food').hover(
		function(){
			$(this).find('a:first').addClass('hover');
			$('.main-menu .sub-menu:visible').stop();
			$('.main-menu .sub-menu:visible').removeAttr('style');
			$('.main-menu .sub-menu:visible').fadeOut(200);
			if (($.browser.msie) && ($.browser.version <= 7))
			{
				$(this).find('.sub-menu .bottom').width($(this).find('.sub-menu').width()-16);
			}
			$(this).find('.sub-menu').fadeIn(300);
		},
		function(){
			$(this).oneTime(300,function(){
				$(this).find('.sub-menu').stop();
				$(this).find('.sub-menu').removeAttr('style');
				$(this).find('.sub-menu').fadeOut(200);
				$(this).find('.hover').removeClass('hover');
			});
		}
	)
	
	$('.content-menu td').hover(
		function(){$(this).addClass('hover')},
		function(){$(this).removeClass('hover')}
	);
	
	$('.cafes .brands a').hover(
		function(){
			var rel = $(this).attr('rel');
			$('.schemes .scheme-arrow').stop();
			$('.schemes').find('#'+rel).effect("pulsate", { times:3 }, 700);
		},
		function(){
			var rel = $(this).attr('rel');
			$('.schemes').find('#'+rel).stop();
			$('.schemes .scheme-arrow').stop();
			$('.schemes').find('#'+rel).css('display','none');
			
		}
	);
	
	$('.schemes .scheme-cafe').hover(
		function(){
			var name = $(this).attr('name');
			$('.cafes .brands a').each(function(){ if ($(this).attr('rel') == name) $(this).addClass('hover'); });
		},
		function(){
			var name = $(this).attr('name');
			$('.cafes .brands a').removeClass('hover');
		}
	);
	
	$('.schemes .scheme-cafe').click(function(){return false;})

	show_quiz(0);	
	
	$('.content .more_quiz').click(function(){
		show_quiz(quiz_count-3);
		return false;
	})
});

function show_quiz (start_index)
{
	var quiz = $('.quiz-stat');
	for (i=start_index; i<quiz_count; i++)
	{
		$(quiz).eq(i).css('display','block');
	}
	if (quiz_count == quiz.length) $('.content .more_quiz').css('display','none')
	else quiz_count = quiz_count + 3;
	
}

