/* TABS/ACCORDIONS — jQuery Tools 1.2.6 http://flowplayer.org/tools/tabs/ */
(function(a){a.tools=a.tools||{version:"v1.2.6"},a.tools.tabs={conf:{tabs:"a",current:"current",onBeforeClick:null,onClick:null,effect:"default",initialIndex:0,event:"click",rotate:!1,slideUpSpeed:400,slideDownSpeed:400,history:!1},addEffect:function(a,c){b[a]=c}};var b={"default":function(a,b){this.getPanes().hide().eq(a).show(),b.call()},fade:function(a,b){var c=this.getConf(),d=c.fadeOutSpeed,e=this.getPanes();d?e.fadeOut(d):e.hide(),e.eq(a).fadeIn(c.fadeInSpeed,b)},slide:function(a,b){var c=this.getConf();this.getPanes().slideUp(c.slideUpSpeed),this.getPanes().eq(a).slideDown(c.slideDownSpeed,b)},ajax:function(a,b){this.getPanes().eq(0).load(this.getTabs().eq(a).attr("href"),b)}},c,d;a.tools.tabs.addEffect("horizontal",function(b,e){if(!c){var f=this.getPanes().eq(b),g=this.getCurrentPane();d||(d=this.getPanes().eq(0).width()),c=!0,f.show(),g.animate({width:0},{step:function(a){f.css("width",d-a)},complete:function(){a(this).hide(),e.call(),c=!1}}),g.length||(e.call(),c=!1)}});function e(c,d,e){var f=this,g=c.add(this),h=c.find(e.tabs),i=d.jquery?d:c.children(d),j;h.length||(h=c.children()),i.length||(i=c.parent().find(d)),i.length||(i=a(d)),a.extend(this,{click:function(c,d){var i=h.eq(c);typeof c=="string"&&c.replace("#","")&&(i=h.filter("[href*="+c.replace("#","")+"]"),c=Math.max(h.index(i),0));if(e.rotate){var k=h.length-1;if(c<0)return f.click(k,d);if(c>k)return f.click(0,d)}if(!i.length){if(j>=0)return f;c=e.initialIndex,i=h.eq(c)}if(c===j)return f;d=d||a.Event(),d.type="onBeforeClick",g.trigger(d,[c]);if(!d.isDefaultPrevented()){b[e.effect].call(f,c,function(){j=c,d.type="onClick",g.trigger(d,[c])}),h.removeClass(e.current),i.addClass(e.current);return f}},getConf:function(){return e},getTabs:function(){return h},getPanes:function(){return i},getCurrentPane:function(){return i.eq(j)},getCurrentTab:function(){return h.eq(j)},getIndex:function(){return j},next:function(){return f.click(j+1)},prev:function(){return f.click(j-1)},destroy:function(){h.unbind(e.event).removeClass(e.current),i.find("a[href^=#]").unbind("click.T");return f}}),a.each("onBeforeClick,onClick".split(","),function(b,c){a.isFunction(e[c])&&a(f).bind(c,e[c]),f[c]=function(b){b&&a(f).bind(c,b);return f}}),e.history&&a.fn.history&&(a.tools.history.init(h),e.event="history"),h.each(function(b){a(this).bind(e.event,function(a){f.click(b,a);return a.preventDefault()})}),i.find("a[href^=#]").bind("click.T",function(b){f.click(a(this).attr("href"),b)}),location.hash&&e.tabs=="a"&&c.find("[href="+location.hash+"]").length?f.click(location.hash):(e.initialIndex===0||e.initialIndex>0)&&f.click(e.initialIndex)}a.fn.tabs=function(b,c){var d=this.data("tabs");d&&(d.destroy(),this.removeData("tabs")),a.isFunction(c)&&(c={onBeforeClick:c}),c=a.extend({},a.tools.tabs.conf,c),this.each(function(){d=new e(a(this),b,c),a(this).data("tabs",d)});return c.api?d:this}})(jQuery);

/* SLIDESHOW (tabs plugin) — jQuery Tools */
(function(a){var b;b=a.tools.tabs.slideshow={conf:{next:".forward",prev:".backward",disabledClass:"disabled",autoplay:!1,autopause:!0,interval:3e3,clickable:!0,api:!1}};function c(b,c){var d=this,e=b.add(this),f=b.data("tabs"),g,h=!0;function i(c){var d=a(c);return d.length<2?d:b.parent().find(c)}var j=i(c.next).click(function(){f.next()}),k=i(c.prev).click(function(){f.prev()});function l(){g=setTimeout(function(){f.next()},c.interval)}a.extend(d,{getTabs:function(){return f},getConf:function(){return c},play:function(){if(g)return d;var b=a.Event("onBeforePlay");e.trigger(b);if(b.isDefaultPrevented())return d;h=!1,e.trigger("onPlay"),e.bind("onClick",l),l();return d},pause:function(){if(!g)return d;var b=a.Event("onBeforePause");e.trigger(b);if(b.isDefaultPrevented())return d;g=clearTimeout(g),e.trigger("onPause"),e.unbind("onClick",l);return d},resume:function(){h||d.play()},stop:function(){d.pause(),h=!0}}),a.each("onBeforePlay,onPlay,onBeforePause,onPause".split(","),function(b,e){a.isFunction(c[e])&&a(d).bind(e,c[e]),d[e]=function(b){return a(d).bind(e,b)}}),c.autopause&&f.getTabs().add(j).add(k).add(f.getPanes()).hover(d.pause,d.resume),c.autoplay&&d.play(),c.clickable&&f.getPanes().click(function(){f.next()});if(!f.getConf().rotate){var m=c.disabledClass;f.getIndex()||k.addClass(m),f.onBeforeClick(function(a,b){k.toggleClass(m,!b),j.toggleClass(m,b==f.getTabs().length-1)})}}a.fn.slideshow=function(d){var e=this.data("slideshow");if(e)return e;d=a.extend({},b.conf,d),this.each(function(){e=new c(a(this),d),a(this).data("slideshow",e)});return d.api?e:this}})(jQuery);

/*FLASH- http://jquery.thewikies.com/swfobject/*/
(function(F,C){var D=function(H){var G,I=[];for(G in H){if(/string|number/.test(typeof H[G])&&H[G]!==""){I.push(G+'="'+H[G]+'"')}}return I[A]("")},E=function(I){var G,K,J=[],H;if(typeof I=="object"){for(G in I){if(typeof I[G]=="object"){H=[];for(K in I[G]){H.push([K,"=",encodeURIComponent(I[G][K])][A](""))}I[G]=H[A]("&amp;")}if(I[G]){J.push(['<param name="',G,'" value="',I[G],'" />'][A](""))}}I=J[A]("")}return I},B=false,A="join";F[C]=(function(){try{var G="0,0,0",H=navigator.plugins["Shockwave Flash"]||ActiveXObject;G=H.description||(function(){try{return(new H("ShockwaveFlash.ShockwaveFlash")).GetVariable("$version")}catch(J){}}())}catch(I){}G=G.match(/^[A-Za-z\s]*?(\d+)[\.|,](\d+)(?:\s+[d|r]|,)(\d+)/);return{available:G[1]>0,activeX:H&&!H.name,version:{major:G[1]*1,minor:G[2]*1,release:G[3]*1},hasVersion:function(K){var N=this.version,L="major",M="minor",J="release";K=(/string|number/.test(typeof K))?K.toString().split("."):K||[0,0,0];K=[K[L]||K[0]||N[L],K[M]||K[1]||N[M],K[J]||K[2]||N[J]];return(K[0]<N[L])||(K[0]==N[L]&&K[1]<N[M])||(K[0]==N[L]&&K[1]==N[M]&&K[2]<=N[J])},expressInstall:"expressInstall.swf",create:function(J){if(!F[C].available||B||!typeof J=="object"||!J.swf){return false}if(J.hasVersion&&!F[C].hasVersion(J.hasVersion)){J={swf:J.expressInstall||F[C].expressInstall,attrs:{id:J.id||"SWFObjectExprInst",name:J.name,height:Math.max(J.height||137),width:Math.max(J.width||214)},params:{flashvars:{MMredirectURL:location.href,MMplayerType:(F[C].activeX)?"ActiveX":"PlugIn",MMdoctitle:document.title.slice(0,47)+" - Flash Player Installation"}}};B=true}else{J=F.extend(true,{attrs:{id:J.id,name:J.name,height:J.height||180,width:J.width||320},params:{wmode:J.wmode||"opaque",flashvars:J.flashvars}},J)}if(F[C].activeX){J.attrs.classid=J.attrs.classid||"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000";J.params.movie=J.params.movie||J.swf}else{J.attrs.type=J.attrs.classid||"application/x-shockwave-flash";J.attrs.data=J.attrs.data||J.swf}return["<object ",D(J.attrs),">",E(J.params),"</object>"][A]("")}}}());F.fn[C]=function(G){if(typeof G=="object"){this.each(function(){var I=document.createElement(C);var H=F[C].create(G);if(H){I.innerHTML=H;if(I.childNodes[0]){this.appendChild(I.childNodes[0])}}})}else{if(typeof G=="function"){this.find("object").andSelf().filter("object").each(function(){var I=this,H="jsInteractionTimeoutMs";I[H]=I[H]||0;if(I[H]<660){if(I.clientWidth||I.clientHeight){G.call(this)}else{setTimeout(function(){F(I)[C](G)},I[H]+66)}}})}}return this}}(jQuery,"flash"));

$(document).ready(function () {
    dropDowns();
    expandSearch();
    $('#billboard.scrolling .controller').tabs('#billboard > .frame', { effect: 'fade', fadeOutSpeed: 'slow', rotate: true});
    modalBox();
	modalBoxOld();
    myTooltip();
    $('ol, ul').prev('p').css('margin-bottom', '0'); //lists captions
	$('ul.bicol li:nth-child(even), .officials LI:nth-child(even)').css({'margin-right' : '0'});
    $('#cse-search-box').attr('autocomplete', 'off');
    gallery();
	galeryOld();
	collapsibles();
	$("ul.tabs").tabs("div.panes > nav");
	$("ul.tabs_main").tabs("div.panes > div, div.panes > section", {initialIndex: 1});
	$('body[class!=search] iframe, body object[id!=tut01]').wrap('<div class="ridgepole" />');
	mSearch();
	$('.tut01').flash({swf:'/a/video/01.swf',height:331,width:522});
	// $('.on_demand').addClass('closed');
    // $('#f_sign_up').attr('autocomplete','off').validationEngine();
	// JS 'media queries'
	// var screenWidth = (screen.width < 480px) ? true : false;
	//if(!screenWidth) { ... }
});

function dropDowns() {
    $(document).click(function (e) {
        if ($(e.target).is('.menu .label')) {
            return;
        }
        $('.menu ul').hide();
        $('.menu .label').removeClass('down');
        $('#billboard .overlay').remove();
    });
	//$('html').click(function () {
       // $('.menu ul').hide();
       // $('.menu .label').removeClass('down');
       // $('#billboard .overlay').remove();
    // });
    $('.menu ul').click(function (event) {
        event.stopPropagation();
    });
    $(document).keydown(function (e) {
        if (e.keyCode == 27) {
            $('.menu ul').hide();
            $('.menu .label').removeClass('down');
            $('#billboard .overlay').remove();
        }
    });
    $('.menu .label').click(function (event) {
        $('.menu ul').hide();
        $(this).parents('.menu').children('ul').toggle();
        $('.menu .label').removeClass('down');
        $(this).addClass('down');
        $('#billboard').append('<div class="overlay"></div>');
        return false;
    });
}

function expandSearch() {
    $('#q').focus(function () {
        $(this).animate({
            width: ['340px', 'swing']
        });
        $('.menu ul').hide();
        $('.menu .label').removeClass('down');
        $('#header nav').append('<div class="overlay"></div>');
        $('#header nav ul').animate({ 'opacity': 0.43}, 430);});
    $('#q').blur(function () {
        $(this).animate({ width: ['115px', 'swing']});
        $('#header .overlay').remove();
        $('#header nav ul').animate({ 'opacity': 1}, 430);});
}

function modalBox() {
    $('a[rel*="extra"]').click(function (e) {
        //Cancel the link behavior
        e.preventDefault();
        //Create modal box container and overlay
        if ($('#modal_box').length == 0) {
            $('body').append('<div id="modal_box" class="section"></div><div id="overlay" style="filter: alpha(opacity=64)"></div>');
        }
        var href = $(this).attr('href');
        //Create figcaption text
        if ($(this).attr('title')) {
            var title = $(this).attr('title');
        } else {
            var title = ':-)';
        }
        //Check href to separate html and pics
        if ($(this).is('a[href$=.png], a[href$=.jpg], a[href$=.gif], a[href$=.gif]')) {
            //Create figure, figcaption and open image in modal box
            $('#modal_box').append('<div class="single figure"><div class="figcaption">' + title + '<button class="close">Закрыть</button></div><img src="' + href + '" alt="" /></div><div class="footer"></div>');
            $.getScript('/a/js/modal-box.js');
            $('#modal_box').fadeIn('300');
            $('#overlay').fadeIn('300');
        } else {
            //Load HTML in modal box
            $('#modal_box').load(href, function () {
                $.getScript('/a/js/modal-box.js');
            });
            $('#modal_box').fadeIn('300');
            $('#overlay').fadeIn('300');
        }
        $(document).keydown(function (e) {
            if (e.keyCode == 27) {
                $('#modal_box').fadeOut('fast');
                $('#overlay').fadeOut('fast');
                $('#modal_box').empty();
            }
        });
    });
}

function myTooltip() {
    $('.tooltip').append('<span class="png"></span>');
    $('.dfn').hover(

    function () {
        $(this).siblings('.tooltip').show('fast');
    }, function () {
        $(this).siblings('.tooltip').hide('fast');
    });
}

function gallery() {
    $('a[rel*="gallery"]').click(function (e) {
        //Cancel the link behavior
        e.preventDefault();
        var href = $(this).attr('href');
        //Create figcaption text
        if ($(this).attr('title') && $('figure.gallery p')[0]) {
            var title = $(this).attr('title');
        } else {
            var title = '';
        }
        var figure = $('figure.gallery');
		var img = $('figure.gallery img');
        var figcaption = $('figure.gallery p');
        img.remove();
		figcaption.empty();
        figure.append('<img src="' + href + '" alt="' + title + '" />');
        figcaption.append(title);
    });
}

function galeryOld() {
    $('a.loadinto-gallery').click(function (e) {
        //Cancel the link behavior
        e.preventDefault();
        var href = $(this).attr('href');
        //Load HTML in gallery frame
        $('#gallery').load(href);
    });
}

function modalBoxOld() {
    $('a.loadinto-modal_box').click(function (e) {
        //Cancel the link behavior
        e.preventDefault();
        //Create modal box container and overlay
        if ($('#modal_box').length == 0) {
            $('body').append('<div id="modal_box" class="section"></div><div id="overlay" style="filter: alpha(opacity=64)"></div>');
        }
        var href = $(this).attr('href');
        $('#modal_box').load(href, function () {
            $.getScript('/a/js/modal-box.js');
        });
        $('#modal_box').fadeIn('300');
        $('#overlay').fadeIn('300');
        //Close modal box on escape key press
        $(document).keydown(function (e) {
            if (e.keyCode == 27) {
                $('#modal_box').fadeOut('fast');
                $('#overlay').fadeOut('fast');
                $('#modal_box').empty();
            }
        });
    });
}

function collapsibles() {
	//$('.first_opened div.first').show();
	$('.on_demand H3').click(function(event) {
		$(this).next('div').slideToggle();
		$(this).toggleClass('opened');
	});
}

function mSearch() {
	$('#btn_search_m').click(function (event) {
$('html').toggleClass('disabled');
    });
}
