$(function(){
	
	$(".scrollable").scrollable({
		circular: true,
		speed: 1000,
		easing: 'custom'
	}).navigator({
		navi: '.posuvnik'
	}).autoscroll({
		interval: 5000
	});

	$.easing.custom = function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	}
	
	$("ul.topmenu").superfish(); 
	
	$(".poll_show").each(function()
	{
		var anketa = $(this);

		$("label", this).click(function()
		{	
			anketa.parent().prev('.poll_loading').show();
			
			var vote_id = $(this).find("input").val();
			var poll_id = $(this).parent().find("input[name=pool_id]").val();
	
			$.ajax({
				type: "GET",
				url: "/ajax/poll.php",
				data: "poll_id=" + poll_id + "&vote_id=" + vote_id,
				dataType: "html",
				success: function(msg)
				{
					anketa.html(msg).hide().fadeIn("slow");
					var cookie = $.cookie('poll');
					if (cookie)
					{
						$.cookie('poll', cookie + ';' + poll_id, {expires:180, path:'/'});
					}
					else
					{
						$.cookie('poll', poll_id, {expires:180, path:'/'});	
					}					
				}
			});

			anketa.parent().prev('.poll_loading').fadeOut(500);
			
			return false;
		
		});	
	});
	
	$("ul.tabs").tabs(".tabs-content > div");
	
	equalHeight($('.first_line'));
	equalHeight($('.second_line'));
	equalHeight($('.img'));
	
  $("a[rel='fancybox'], a[rel='clearbox'], a[rel='fancybox2']").fancybox({'zoomSpeedIn': 800, 'zoomSpeedOut': 400, 'overlayShow': true, 'enableEscapeButton': true, 'titleShow': true, 'transitionIn': 'elastic', 'transitionOut': 'elastic', 'overlayColor' : '#fff', 'centerOnScroll': true, 'titlePosition': 'over'});

});

function equalHeight(group)
{
	tallest = 0;
	group.each(function(){
		thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}
