$(function(){

    $('#carousel').jcarousel({scroll: 1, wrap: 'circular'});

    $.each($.browser, function(i, val) {
        if(i=='safari')
            $('#carousel_wrp ul').width(9999)
    });

    $('#carousel .slide_wrapper').hover(function(){
        $(this).parent().addClass('boxgrid').addClass('captionfull')
        $('.cover', this).stop().animate({left:'225px'},{queue:false,duration:160});
    }, function(){
        $('.cover', this).stop().animate({left:'472px'},{queue:false,duration:160});
    })

    // clients carousel
    $(window).load(function(){
        $(".jac").jac({
            childSizeFixed: false,
            rightText: next,
            leftText: prev
        });
    });
    $('.jac img').css('opacity', '0.6')
    $('.jac img').hover(function(){
        $(this).animate({opacity: '1'})
    },function(){
        $(this).animate({opacity: '0.6'})
    })

    if(!$('.pagination a').length)
        $('.pagination').hide()


    $(".big_images a").fancybox({
                'titleShow' : false,
                'transitionIn'  : 'elastic',
                'transitionOut' : 'elastic'
        });



    // navigation
    $('body').append('<div class="submenu" />')
    $('.nav li').hover(function(){
        if($('ul li', this).length)
        {
            if(typeof(timer) == 'nubmer')
            {
                clearTimeout(timer)
                timer = null
            }
            show = true;
            $('.submenu:hidden')
                .html('<div class="block"><div class="arrow"></div><ul>'+$('ul', this).html()+'</ul></div>')
                .css({top: $(this).offset().top+20, left: $(this).offset().left-169})
                .stop()
                .animate({'opacity': 'toggle', 'height': 'toggle'}, 'fast')
        }
        else {
            $('.submenu:visible').stop()
                .animate({'opacity': 'toggle', 'height': 'toggle'}, 'fast').hide()
        }
    },function(){
        show = false
        timer = setTimeout(function(){
            if(!show)
                $('.submenu:visible').animate({'opacity': 'toggle', 'height': 'toggle'}, 'fast')
            timer = null
        }, 500)
    })

    $('.submenu').hover(function(){
        clearTimeout(timer)
        timer = null
    },function(){
        show = false
        timer = setTimeout(function(){
            if(!show)
                $('.submenu:visible').animate({'opacity': 'toggle', 'height': 'toggle'}, 'fast').hide()
            timer = null
        }, 500)
    })


})
var timer;
var show = false;