// JavaScript Document
/*
    © icw82 (functions)
*/

function getIEVersion()
{
	var ua=navigator.userAgent;	
	var set=ua.indexOf("MSIE ");
	if(set!=-1) return parseFloat(ua.substring(set+5,ua.indexOf(";", set)));
}
	var IEVersion=getIEVersion();


function hasBrowser(name)
{
	var ua=navigator.userAgent;
	var result=ua.indexOf(name);
	if(result!=-1) return true;
}


$(document).ready(function()
{
/*
     *    ФОРМА ПОИСКА
     */
    if(hasBrowser('Safari'))
        $('.search-form p').html('<input maxlength="80" name="query" size="20" type="search" placeholder="Поиск" results="" /><input type="image" class="enter" alt="?" src="layout/img/enter.png" />')
    else{
        $('.search-form p').html('<input maxlength="80" name="query" size="20" type="text" value="поиск" class="placeholder" /><input type="image" class="enter" alt="?" title="Искать" src="layout/img/enter.png" />');
        
        $('.search-form .placeholder').focus(function(){if($(this).attr('value')=='поиск') $(this).removeClass('placeholder').attr('value','');});
        $('.search-form .placeholder').blur(function(){if($(this).attr('value')=='') $(this).addClass('placeholder').attr('value','поиск');});
    }

    $('#page-404 .search-form p .enter').attr('src', 'layout/img/enter-dark.png');
	
	/* Навигация стрелками. С разрешения Татьяныча */		
	$(document).keydown(function(event){
		if (event.ctrlKey)
		{				
			switch (event.keyCode?event.keyCode:event.which?event.which:null)
			{
				case 0x27: /* > */; break;
				case 0x25: /* < */; break;
			}
		}
	})

	$('.form-open').click(function(){
		$(this).hide('fast').siblings('form').show('slow')
	})
	
//	$('.form-a button').click(function(){
//		$(this).parents('form').hide('slow').siblings('.form-sended').show('slow')
//	})


	if($('.analit-board .briefly').hasClass('active'))
		$('.detail-block').hide()
	if($('.analit-board .detail').hasClass('active'))
		$('.briefly-block').hide()

	$('.analit-board .briefly').click(function(){
		if($(this).hasClass('active')){}else
		{
			$(this).addClass('active')
			$('.analit-board .detail').removeClass('active');
			$('.briefly-block').show('slow')
			$('.detail-block').hide('fast')
			
		}
	})

	$('.analit-board .detail').click(function(){
		if($(this).hasClass('active')){}else
		{
			$(this).addClass('active')
			$('.analit-board .briefly').removeClass('active');
			$('.detail-block').show('slow', initGraphWrapper);
			$('.briefly-block').hide('fast')
		}
	})
	
	$('ul.u-menu li').mouseover(function(){
		$('.u-menu-frame .active').hide();
		$('.u-menu-frame .'+$(this).attr('class')).show()
	
	})

	$('ul.u-menu li').mouseout(function(){
		$('.u-menu-frame div').hide();
		$('.u-menu-frame .active').show();
	})
	
	
	//
	// НАВИГАЦИЯ ПО ДАТАМ
	//
	$('.date-navigation').find('.active').parents('ul').slideDown(400).siblings('span').addClass('opened');

	$('.date-navigation').find('span').click(function(){		
		if($(this).hasClass('opened')){
			$(this).removeClass('opened');
			$(this).next('ul').slideUp(150);
		}else{
			$(this).parents('.date-navigation').find('.opened').removeClass('opened').next('ul').slideUp(300)
			$(this).addClass('opened');
			$(this).next('ul').slideDown(300)
		}
	})

	 /*	ПЕРЕКЛЮЧАТЕЛЬ СТРАНИЦ	 */
	$('#'+$('.container-switch li.active').find('a').attr('name')).show().siblings('.container').hide();
	$('.container-switch li').click(function(){
		if(!$(this).hasClass('active')){
			$(this).addClass('active').siblings('li').removeClass('active');
			$('#'+$(this).find('a').attr('name')).show().siblings('.container').hide();
		}
	})


	if(IEVersion<8){
		$('.browser-warning').html('<div><p>Уважаемый пользователь!<br />Рекомендуем сменить ваш браузер, <strong>Internet Explorer '+IEVersion+'</strong>, на более быстрый удобный и качественный.<br />Например на <a href="http://www.mozilla-europe.org/ru/firefox/">Mozilla Firefox</a>, <a href="http://www.google.com/chrome/">Google Chrome</a>, <a href="http://ru.opera.com/">Opera</a>, <a href="http://www.apple.com/safari/">Apple Safari</a> или <a href="http://www.microsoft.com/windows/Internet-explorer/">обновить Internet explorer</a>.</p><p>Обращаем ваше внимание на то, что Internet Explorer 6 был выпущен в далёком 2001 году,<br />а Internet Explorer 7 в 2006. Оба лишь частично поддерживают основные веб-стандарты,<br />что не позволяет вам получать адекватное отображение страниц.</p></div>');
	}

/*
     *    ПРОСТАЯ АНИМАЦИЯ ЧИСЕЛ
     *    e — елемент; например #id, .class, #id > ul + p и т. д.
     *    n — число; желательно четырёхзначное.
     */
    function simpleAnimation(e,n){
        var t=2000;
        var f = 30;
        var delay=1000/f;
        var I=Math.floor((t/1000)*f);
        var i=1;
        var k=0.7;

        id=setInterval(function(){
            if(i<I){
                //out=n-((Math.pow(1/1.2,i))*n);
                out=Math.round(n-(1/(Math.pow(1.2,i))*n));
                //out=n*(Math.pow(k,i))
                //out=n*(1/i);
                e.text(out)
                i++;
            }else{
                e.text(n);
                clearInterval(id);
            }
        }, delay)        
    }
});

