$('document').ready(function(){
    $(".footerLogos a").hover(function(){
        var currentId = $(this).attr("id");
        $("#"+currentId+" img.a").addClass('hide');
        $("#"+currentId+" img.b").addClass('show');
    }, function(){
        $(".footerLogos a img.a").removeClass('hide');
        $(".footerLogos a img.b").removeClass('show');
    });

    $("div.indexGroupMembers >div.groupsHolder > div.oneGroup").hover(function(){
        $(this).addClass('groupActive');
    }, function(){
        $(this).removeClass('groupActive');
    });

    $("li a").hover(function(){
        $(this).parents("li").addClass('hover');
    }, function(){
        var e = $(this).parents("li").attr("class");
        if(e=="hover" || e=="  hover"){
            $(this).parents("li").removeClass('hover');
        }else{
            if(e=="active hover"){
                $(this).parents("li").removeClass('hover');
            }
        }
    });

    $("li.hasChilds").hover(function(){
        $(this).addClass('hover');
    }, function(){
        $(this).removeClass('hover');
    });

    $.each($(".inlineBlock"), function(i, item) {
        var w = $('.inlineBlockImg > p > img', $(this)).attr('width');
        $(item).css('width', w);
    });

    $("a.sliderLink").click( function(){
        var e = $(this).attr("id");
        $("div.inlineBlockBigImg").removeClass('active');
        $("div.inlineBlockBigTexLeft").removeClass('active');
        $("div.inlineBlockBigTexRightLink").removeClass('active');
        $("#"+e).parent().parent().addClass('active');
        $("#"+e+"Img").addClass('active');
        $("#"+e+"Text").addClass('active');
        return false;
    });

    $("div.contentRight > div.contentRightGroupsBlock > div.contentRightGroupsBlockTop > div.contentRightGroupsBlockBottom > div.groupTop").hover(function(){
        $(this).addClass('hover');
    }, function(){
        $(this).removeClass('hover');
    });

    $(".faqHolder .faqQuestionHolder:last-child").css("border-bottom","none");
    $("div.faqQuestionHolder a.link").click(function(){
        ;
        e=$(this).parents("div.faqQuestionHolder").attr('class')
        if(e!=="faqQuestionHolder active"){
            $(this).parents("div.faqQuestionHolder").addClass('active');
            return false;
        }else{
            $(this).parents("div.faqQuestionHolder").removeClass('active');
            return false;
        }
    });

    $(".searchResult:last-child").css({
        "border-bottom":"none",
        "margin-bottom":"0px"
    });
});

/* mindaugas */
$(function(){
	
	$('a.fancybox').fancybox();
	
    var header_right_contents = $('.headerRightInfoRandomBlocks');
    var header_right_contents_l = header_right_contents.length;
    var random = Math.floor(Math.random()*header_right_contents_l);

    header_right_contents.each(function(n){
        if(n == random){
            $('.contentTopInfoRight').html($(this).html());
            return true;
        }
    });


    /* search result paging*/
    var searchResultHolder = $('#searchResultsHolder');
    var searchResultBack = $('.searchResultsPaging a.back');
    var searchResultNext = $('.searchResultsPaging a.next');
    var searchResultA = $('.searchResultsPaging a');
    var searchResultTTp = $('.searchResultsPaging .ssearchResultTTp').val();

    var searchResultActive = 1;

    searchResultA.click(function(e){
        e.preventDefault();

        var id = parseInt($(this).attr('href').replace('#', ''));
        if(id != searchResultActive){

            searchResultHolder.html($('#searchResultPage_'+id).html());

            $('#npg_'+searchResultActive).removeClass('active');
            $('#npg_'+id).addClass('active');

            if(id > 1){
                searchResultBack.attr('href', '#'+(id-1));
            }else{
                searchResultBack.attr('href', '#1');
            }

            if(id < searchResultTTp){
                searchResultNext.attr('href', '#'+(id+1));
            }else{
                searchResultNext.attr('href', '#'+searchResultTTp);
            }
        }
        searchResultActive = id;
    });


    /* news paging*/
    var newsPgHolder = $('#newsPgsHolder');
    var newsPgBack = $('.newsPaging a.back');
    var newsPgNext = $('.newsPaging a.next');
    var newsPgA = $('.newsPaging a');
    var newsPgTTp = $('.newsPaging .newsTTp').val();

    var newsPgActive = 1;

    newsPgA.click(function(e){
        e.preventDefault();

        var id = parseInt($(this).attr('href').replace('#', ''));
        if(id != newsPgActive){

            newsPgHolder.html($('#newsPage_'+id).html());

            $('#npg_'+newsPgActive).removeClass('active');
            $('#npg_'+id).addClass('active');

            if(id > 1){
                newsPgBack.attr('href', '#'+(id-1));
            }else{
                newsPgBack.attr('href', '#1');
            }

            if(id < newsPgTTp){
                newsPgNext.attr('href', '#'+(id+1));
            }else{
                newsPgNext.attr('href', '#'+newsPgTTp);
            }
        }
        newsPgActive = id;
    });

    /* DUK */
    var anchor = window.location.hash.replace('#', '');
    var active_faq = $('div.faqQuestionHolder[title='+anchor+']')
    if(active_faq.length > 0){
        active_faq.addClass('active');
    }else{
        $('div.faqQuestionHolder:first').addClass('active');
    }
});
