$.fn.slideMenu = function(){

    $(this).click(function(){
        var thisParen = $(this).next('.lvl2_sub');
        var thisParenParent = $(thisParen).parent('ul');
        if($(this).is('.closed')){
            $(thisParen).slideDown('slow');
            $(this)
                .removeClass('closed')
                .addClass('open');
        }else{
            $(thisParen).slideUp('slow');
            $(this)
                .removeClass('open')
                .addClass('closed');
        }
        return false;
    });

}

$(document).ready(function(){
    $('.previews a').dblclick(function(){
        $ ('.gall').click() ;
    });

    var ImgWidth=$('.picture-slides-image').width();

    $('.previews a').click(function(){
        $('.gallery td.bigimage').css('width',ImgWidth + 'px');
    });



    $('.form_send').mouseover(function() {
        $(this).css('background-position','left -30px');
    });
    $('.form_send').mousedown(function() {
        $(this).css('background-position','left -60px');
    });
    $('.form_send').mouseup(function() {
        $(this).css('background-position','left -30px');
    });
    $('.form_send').mouseout(function() {
        $(this).css('background-position','left 0px');
    });

    $('.allpubs').click(function(){
        $(this).css('display','none');
        $('.morepubs').slideDown('slow');
        return false;
    });

    $('.menu_list a.closed').click(function(){
        if($(this).is('.open')){
            $('.menu_list a')
                .removeClass('open')
                .addClass('closed');
            $('.lvl2_sub').slideUp('slow');
        }else{
            $('.menu_list a.open')
                .removeClass('open')
                .addClass('closed');
            $('.lvl2_sub').slideUp('slow');
        }
    });




    $('.allnews').click(function(){
        $(this).css('display','none');
        $('#showallnews').slideDown();
        return false;
    });

    $('.menu_list > li a:first').css('background','transparent');
    $('.menu_list a.closed, .menu_list a.open').slideMenu();

    /*$('.brands').click(function(){
     $('.for_countries').css('display','none');
     $('.for_brands').css('display','block');
     $('.countries').removeClass('active');
     $('.brands').addClass('active');
     });
     $('.countries').click(function(){
     $('.for_brands').css('display','none');
     $('.for_countries').css('display','block');
     $('.brands').removeClass('active');
     $('.countries').addClass('active');
     });*/

    $('.TopMenu li:not(:has( > a[href*="/events/"]))').hover(
        function () {
            $(this).children('.lvl2').css('display','block');
        },
        function () {
            $(this).children('.lvl2').css('display','none');
        }
    );

    $('.pixel_triger').hover(
        function () {
            $('.pixel_triger img').fadeIn('fast');
        },
        function () {
            $('.pixel_triger img').fadeOut('fast');
        }
    );


    $('.ItemBlock').hover(
        function () {
            $(this).children('.bubble').slideDown(700);
        },
        function () {
            $(this).children('.bubble').slideUp(700);
        }
    );



});

$(window).load(function() {
    if($("body.index .ws_images").length) {
        $("body.index .ws_images").nivoSlider({
            effect:'fold',
            directionNav: false,
            pauseTime: 4000,
            directionNavHide: true,
            controlNav: false,
            controlNavThumbs: false,
            controlNavThumbsFromRel: false,
            pauseOnHover: true,
            keyboardNav: false });
    }
});

