function showNav() {
    $(this).addClass('hover');
    $('div.sub-menu', this).css({
        display:'block'
    }).addClass('hover');
}
function hideNav() {
    $(this).removeClass('hover');
    $('div.sub-menu', this).css({
        display:'none'
    }).removeClass('hover');
}
$(document).ready(function() {
    $('#modal-form').jqm({ajax: '/callback/', trigger: '#modal',onLoad:function(){$(this).blur()}});
    $("#main-menu>li").each(function(){
        if ($(".sub-menu",this).length) {
            $(this).addClass("parent");
        }
    });
    $("#subscribe input[type=text]").focus(function(){
        if ($(this).val() == 'Ваш e-mail') {
            $(this).css({
                color:"#000"
            }).val('');
        }
    }).focusout(function(){
        if (!$(this).val()) {
            $(this).css({
                color:"#676767"
            }).val('Ваш e-mail');
        }
    });
    $("#subscribe").submit(function(){
        var re = /^\w+([\.-]?\w+)*@(((([a-z0-9]{2,})|([a-z0-9][-][a-z0-9]+))[\.][a-z0-9])|([a-z0-9]+[-]?))+[a-z0-9]+\.([a-z]{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/i;
        if(!re.test($("input[type=text]",this).val()))
            return false;
       return data2sugar($(this).serializeObject());
    });
    //    $("#clients-thumbs").tn3();
    //    $("#clients .scrollable").slideover();
    $("#clients .scrollable").jMyCarousel({
        btnPrev: $('#clients-prev'),
        btnNext: $('#clients-next'),
        visible: '830px',
        circular: true
    });
    $("#clients, #reviews").disableSelection();
    //    .mouseover(function(){
    //        $(this).stop();
    //    }).mouseout(function(){
    //        $(this).forward();
    //    });
    $("#clients").mouseover(function(){
        $(".scrollable img",this).each(function(){
            var src = $(this).attr("src").match(/[^\.]+/) + "_c.png";
            $(this).attr("src",src);
        });
    }).mouseout(function(){
        $(".scrollable img",this).each(function(){
            var src = $(this).attr("src").replace("_c", "");
            $(this).attr("src",src);
        });
    });
    $("#reviews .scrollable").scrollable({
        circular: true
    });
    //    .autoscroll({
    //        autoplay: false,
    //        interval: 5000
    //    });
    $('#home-banners').cycle({
        fx: 'fade',
        timeout:  10000,
        speed: 300,
        pager:  '#home-banners-nav'
    });
    $("#main-menu li.parent").hoverIntent({
        sensitivity: 7, // number = sensitivity threshold (must be 1 or higher)
        interval: 50,   // number = milliseconds of polling interval
        over: showNav,  // function = onMouseOver callback (required)
        timeout: 100,   // number = milliseconds delay before onMouseOut function call
        out: hideNav    // function = onMouseOut callback (required)
    });
    $("#minimap").mouseleave(function(){
        $(".lang", this).addClass("selected");
    });
    $("#minimap .lang li.active a").mouseover(function(){
        $(this).parents("ul").removeClass("selected");
    });
    $("#minimap .lang li a").click(function(){
        $.cookie('sitelang',$(this).attr('href'),{path:'/'});
    });
});

