$(document).ready(function(){
	$('.db-block-more').css('display','none');
	$('.db-go-more').css('display','block');
	$('.db-go-more').click(function(){
		$('.db-go-more').slideUp();
		$('.db-block-more').slideDown();
		return false;
	});

	$(".switcher .switch-read-a, .switcher .switch-video-a").click(function(){
		$(".switcher .switch-video-a").toggleClass('active');
		$(".switcher .switch-read-a").toggleClass('active');
		$(".club-news-read").toggle();
		$(".club-news-video").toggle();
		});
	$(".switcher .switch-bombardir-a, .switcher .switch-assistent-a").click(function(){
		$(".switcher .switch-assistent-a").toggleClass('active');
		$(".switcher .switch-bombardir-a").toggleClass('active');
		$(".best-assistent").toggle();
		$(".best-bombardir").toggle();
		});
	if ($(".month-player").length && $(".player-vote").length)
		$(".switcher .switch-vote-a, .switcher .switch-player-a, .link-vote").click(function(){
			$(".switcher .switch-player-a").toggleClass('active');
			$(".switcher .switch-vote-a").toggleClass('active');
			$(".month-player").toggle();
			$(".player-vote").toggle();
		});

	$("#menu-main li").mouseenter(function(){
		$("#menu-main li").removeClass('hover hover-ie6');
		$(this).addClass('hover hover-ie6');
		});
	$("#menu-main li").mouseleave(function(){
		$("#menu-main li").removeClass('hover hover-ie6');
		});
	$(".link-login").click(function(){
		$(".overlay").show();
		$(".login").show('slow');
	});
	$(".login-button").click(function(){
		$('#form_authorize').submit();
		return false;
	});
	$(".link-close-popup, .overlay").click(function(){
		$(".login").hide("slow", function() {$(".overlay").fadeOut(200);});
	});

	if ($('.gamer-tabs').length) {
		$('.td1, .td2, .td3, .td4', $('.gamer-tabs')).click(function(){
			if (!$(this).hasClass('active') && !$(this).hasClass('disable')) {
				$('.td1, .td2, .td3, .td4', $('.gamer-tabs')).removeClass('active');
				$('.tab1, .tab2, .tab3, .tab4', $('.team-player')).hide();
				$(this).addClass('active');
				var itemClass = 'tab1';
				if ($(this).hasClass('td2')) itemClass = 'tab2';
				if ($(this).hasClass('td3')) itemClass = 'tab3';
				if ($(this).hasClass('td4')) itemClass = 'tab4';
				$('.'+itemClass, $('.team-player')).show();
			}
		});
	};
	
	if($(".calendar").length){
		var ccWidth = 0;
		$(".calendar:eq(0) tr:eq(0) td.eq-c").each(function(){
			ccWidth = ccWidth + $(this).width();
		});
		ccWidth = ccWidth - 30;
		$(".eq-c").width(parseInt(ccWidth/2));
		$(".eq-c > span").width(parseInt(ccWidth/2) - 8);
		$(".eq-c > span > b").width(parseInt(ccWidth/2) - 8 - 41);
	};
	
	$("#menu-main").mouseover(function(){
		$("select").hide();
	});
	$("#menu-main").mouseleave(function(){
		$("select").show();
	});
	
	if ($(".faq_list").length){
		$(".faq_list li .faq_ans").hide();
        $(".faq_list li .faq_name > a").toggle(
            function(){
                $(this).parent().parent().addClass("faq_open").find(".faq_ans").fadeIn();
            }, function(){
                $(this).parent().parent().removeClass("faq_open").find(".faq_ans").fadeOut();
            }
        );
       // $(".podmenu1 a:eq(0)").click();
    };

	if ($('.calendar .calendar-counter').length) {
		var obj = $('.calendar .table').eq(0);
		$('.calendar table').find("tr")
		.mouseover(function(){
			$(this).addClass('calendar-tr-background').siblings().removeClass('calendar-tr-background');
		})
		.mouseout(function(){
			$(this).removeClass('calendar-tr-background');
		})
		.click(function(){
			document.location = $(this).find('.calendar-counter a').eq(0).attr('href');
		});
	}

	//setMaxHeight($('.club-stadium-photos-item'));
});


$(window).resize(function(){

	if($(".calendar").length){
		$(".eq-c").css({width: "auto"});
		$(".eq-c > span").css({width: "auto"});
		$(".eq-c > span > b").css({width: "auto"});
		var ccWidth = 0;
		$(".calendar:eq(0) tr:eq(0) td.eq-c").each(function(){
			ccWidth = ccWidth + $(this).width();
		});
		ccWidth = ccWidth - 30;
		$(".eq-c").width(parseInt(ccWidth/2));
		$(".eq-c > span").width(parseInt(ccWidth/2) - 8);
		$(".eq-c > span > b").width(parseInt(ccWidth/2) - 8 - 41);
	};

});


window.onload = function() {
	if (document.getElementById("wrap-main").offsetWidth < 1280) {
		$('#menu-main').removeClass('menu-wide');
		if ($('#team-player-list').length) {$('.team-player-list ul li[class != "clear-li"]').css('width', (document.getElementById("team-player-list").offsetWidth));};
	}
	else {
		$('#menu-main').addClass('menu-wide');
	};
	if ($("#announce").length) {$('#announce-img').css('margin-left', -(600-(document.getElementById("announce").offsetWidth))/2);};

	if ($("#presscentre-announce").length) {
		var w = $('#presscentre-announce-img .announce-img').width();
		$('#presscentre-announce-img').css('margin-left', -(w-(document.getElementById("presscentre-announce").offsetWidth))/2);
	};
};

window.onresize = function() {
	if (document.getElementById("wrap-main").offsetWidth < 1280) {
		$('#menu-main').removeClass('menu-wide');
		if ($('#team-player-list').length) {$('.team-player-list ul li[class != "clear-li"]').css('width', (document.getElementById("team-player-list").offsetWidth));};
	}
	else {
		$('#menu-main').addClass('menu-wide');
		if ($('#team-player-list').length) {$('.team-player-list ul li[class != "clear-li"]').css('width', 290);};
	};
	if ($('#announce-img').length) {$('#announce-img').css('margin-left', -(600-(document.getElementById("announce").offsetWidth))/2);};

	if ($("#presscentre-announce").length) {
		var w = $('#presscentre-announce-img .announce-img').width();
		$('#presscentre-announce-img').css('margin-left', -(w-(document.getElementById("presscentre-announce").offsetWidth))/2);
	};
};

function updateVotemain(id) {
	var source = $('.gamer'+id).eq(0);
	var target = $('#player_vote').eq(0);
	if (source.length && target.length) {
		$('dt a', target).attr('href', $('.url', source).text());
		$('dt a img', target).attr('src', '/uploads/gamers/size1/'+$('.image', source).text());

		$('dd .player-country', target)
		.attr('style', 'background:url("/uploads/countries/size1/'+$('.country_image', source).text()+'") no-repeat 10px 5px;')
		.html($('.country', source).text() + '<br />' + $('.birthday', source).text());

		$('dd .row1 strong', target).text($('.games', source).text());
		$('dd .row2 strong', target).text($('.goals', source).text());
		$('dd .row3 strong', target).text($('.pass', source).text());

		$('form .gamer_id', target).val(id);
	}
}

function setMaxHeight(elems) {
	if (elems.length) {
		var maxheight = 0;
		elems.each(function() {
			if($(this).height() > maxheight) maxheight  = $(this).height();
		} );
		elems.height(maxheight);
	}
}
