// JavaScript Document

/* Верхнее меню */
update_time=17000;
mode_banner_apimondiya="show";

$(document).ready(function (){
	$("#menu_up li").click(function(){
		location.href = $(this).find("a").attr("href");
		//.css('color','#000000');
		//location.href='/uslugi/sozdanie_saytov/';
		return false
	});

	/*$("#menu_up li").hover(
		function(){
			$(this).find("a").css('color','#000000');
		},
		function(){
			$(this).find("a").css('color','#d71920');
		}
	);*/

	$("#menu_down li").click(function(){
		location.href = $(this).find("a").attr("href");
		return false
	});

	/*$("#menu_down li").hover(
		function(){
			$(this).find("a").css('color','#000000');
		},
		function(){
			$(this).find("a").css('color','#d71920');
		}
	);*/
    banner_apimondiya();
    setInterval('banner_apimondiya()',update_time);    
	
    $('.topmenu .toggle').on('click',function(e){
		e.stopPropagation();
		e.preventDefault();
		width = $(window).width();
		console.log(width);
		if(width>767) {
			if(!$('.topmenu li:first-child').hasClass('open')){
				$('.topmenu').css('width','373px');
				$('.topmenu li span').show();
				$('.topmenu li:first-child').addClass('open');
			}else{
				$('.topmenu').css('width','59px');
				$('.topmenu li span').hide();
				$('.topmenu li:first-child').removeClass('open');
			}
		}else {
			if(!$('.topmenu li:first-child').hasClass('open')){
				$('.topmenu').css('width',width+'px');
				$('.topmenu li span').show();
				$('.topmenu li:first-child').addClass('open');
			}else{
				$('.topmenu').css('width','0px');
				$('.topmenu li span').hide();
				$('.topmenu li:first-child').removeClass('open');
			}
		}
	});
    $('.topmobileicon .icon').on('click',function(e){
		e.stopPropagation();
		e.preventDefault();
		width = $(window).width();
		console.log(width);
		if(width>767) {
			if(!$('.topmenu li:first-child').hasClass('open')){
				$('.topmenu').css('width','373px');
				$('.topmenu li span').show();
				$('.topmenu li:first-child').addClass('open');
			}else{
				$('.topmenu').css('width','59px');
				$('.topmenu li span').hide();
				$('.topmenu li:first-child').removeClass('open');
			}
		}else {
			width = width + 60;
			if(!$('.topmenu li:first-child').hasClass('open')){
				$('.topmenu').css('width',width+'px');
				$('.topmenu li span').show();
				$('.topmenu li:first-child').addClass('open');
			}else{
				$('.topmenu').css('width','0px');
				$('.topmenu li span').hide();
				$('.topmenu li:first-child').removeClass('open');
			}
		}
	});
	$('.topmenu>li').on('click',function(){
		a = $(this).find('a');
		location.href=a.attr('href');
	});
	$('.topmenu>li').hover(
		function(){
			$('.topmenu').css('width','373px');
			$('.topmenu li span').show();
			$('.topmenu li:first-child').addClass('open');
		},
		function(){
			width = $(window).width();
			if(width>767) {
				$('.topmenu').css('width','59px');
			}else {
				$('.topmenu').css('width','0px');
			}
			$('.topmenu li span').hide();
			$('.topmenu li:first-child').removeClass('open');
		}
	);
    $('html,body').on('click',function(e){
		if($('.topmenu li:first-child').hasClass('open')){
			e.stopPropagation();
			e.preventDefault();
			width = $(window).width();
			if(width>767) {
				$('.topmenu').css('width','59px');
			}else {
				$('.topmenu').css('width','0px');
			}
			$('.topmenu li span').hide();
			$('.topmenu li:first-child').removeClass('open');
		}
	});
	h = $('body').height() - 868 - 26;
	$('.topmenu .separator').css('height',h+'px');
	$('img[style="width:0px; height:0px; position:absolute; left:-1px; top:-1px;"]').css('top','-199px');
	setTimeout(function(){
		$('.news.review>div').css('overflow','none');
		$('.news.review>div').css('height',($('#article').height()-880)+'px');
		$('.news.review>div').jScrollPane();
		$('#article').css('padding-bottom','8px');
	},5000);
	$('.voice').on('click',function(e){
		e.stopPropagation();
		id = $(this).data('id');
		voice = $(this).data('voice');
		like = dislike = 0;
		if(voice==0) dislike=1;
		else like=1;
		$.ajax({
			url:'/ajax/poleznoe.php',
			dataType:'json',
			data:'id='+id+'&like='+like+'&dislike='+dislike,
			type:'post',
			success:function(data){
				$('.poleznoepopup').html('');
				$('.poleznoepopup').html(data.message).show(300);
				setTimeout(function(){
					$('.poleznoepopup').hide();
				},3000);
				count = Math.round(data.like) + Math.round(data.dislike);
				like = Math.round(100*data.like/count);
				dislike = Math.round(100*data.dislike/count);
				$('.visres1').css('width',like+'%').text(like+'%').show();
				$('.voice[data-voice="1"]').text('Да ('+data.like+')');
				$('.visres0').css('width',dislike+'%').text(dislike+'%').show();
				$('.voice[data-voice="0"]').text('Нет ('+data.dislike+')');
				console.log(count,100*data.like/count,100*data.dislike/count);
			}
		});
		return false;
	});
});

$(window).resize(function(){
	h = $('body').height() - 868 - 26;
	$('.topmenu .separator').css('height',h+'px');
	w = parseInt($('.slide').width());
	a = parseInt($('.slide>a').width());
	t = parseInt($('.slide>.slide_text').width());
	if(w<(a+t)){
		$('.slide_text').css({'bottom':'373px'});
	}else {
		$('.slide_text').css({'bottom':'0px'});
	}
});
function banner_apimondiya() {
    if (mode_banner_apimondiya=="show")
    {
        $('#apimondiya1').fadeIn(1000);
        $('#apimondiya2').delay(1000).fadeIn(1000);
        $('#apimondiya3').delay(2000).fadeIn(1000);
        $('#apimondiya4').delay(3000).fadeIn(1000);
        mode_banner_apimondiya="hide";
    } else
    {
        $('#apimondiya4').fadeOut(1500);
        $('#apimondiya3').fadeOut(1500);
        $('#apimondiya2').fadeOut(1500);
        $('#apimondiya1').fadeOut(1500);
        mode_banner_apimondiya="show";
        window.setTimeout(function () {banner_apimondiya();}, 500);


        
    }
}