function doSearch(el,event_obj) {
    if(event_obj.keyCode == 13){
        if(window.justSearchSelected){
            window.justSearchSelected = false;
            return false;
        }
        doRealSearch(el)
    }
}
function doRealSearch(el) {
    if ($(el).val().length < 4) {
        alert(searchShort);
    }
    else {
        $("#searchForm").action = searchLink + '/' + encodeURIComponent($(el).val()) + '/';
        document.location = searchLink + '/' + encodeURIComponent($(el).val()) + '/';
    }
}

function initAutoComplete( p_target, p_url, p_width ) {
    jQuery(document).ready(function () {
        jQuery( ""+p_target ).autocomplete( p_url, {
            width: p_width,
            minChars:2,
            max: 6,
            highlightItem: true,
            multiple: true,
            multipleSeparator: " ",
            matchContains: true
        });
    });
}

$(document).ready(function(){
    /* videoTabs */
    $(function () {
        var tabContainers = $('.videoTabs div.tabs > div');
        tabContainers.hide().filter(':first').show();

        $('.videoTabs div.cont a').hover(function () {
            tabContainers.hide();
            tabContainers.filter(this.hash).show();
            $('.videoTabs div.cont a').removeClass('selected');
            $(this).addClass('selected');
            return false;
        }).filter(':first').click();
    });
    /* end videoTabs */


    /* drop-down All */
    $('.dropdownMenu').hover(
        function() {
            $('.menuHover', this).addClass("slideDown");
            $(this).find('.downList').stop(true, true);
            $(this).find('.downList').slideDown(200);
        },
        function() {
            $('.menuHover', this).removeClass("slideDown");
            $(this).find('.downList').slideUp('fast');
        }
        );
    /* end drop-down All */

    /* Позиционирование новогодней подложки */
    if ($('.content')) {
    //var contentBg = $('<div class="contentBg" />');
    //var contentWrapper = $('<div class="contentWrapper" />');
    //$('.content').wrap(contentWrapper).wrap(contentBg);
    $('.content').wrap('<div class="contentWrapper"><div class="contentBg"/></div>');
    var scrollBackground;
    (scrollBackground = function () {
    var browserWindow = $(window);
    var contentBg = $('.contentBg');
    var content = $('.content');
    var footer = $('.footer');
    var backHeight = 700;

    if ((backHeight >= content.height()) || ((browserWindow.height() + browserWindow.scrollTop()) >= footer.offset().top)) {
                contentBg.css('backgroundPosition', '50% -700px'); //скрывается фиксированный фон
                content.css('backgroundPosition', '50% 100%'); //показывается скроллируемый фон
            }
            else if ((browserWindow.height() + browserWindow.scrollTop()) >= (content.offset().top + backHeight)) {
                content.css('backgroundPosition', '50% -700px'); //скрывается скроллируемый фон
                contentBg.css('backgroundPosition', '50% 100%'); //показывается фиксированный фон
            }
            else {
                contentBg.css('backgroundPosition', '50% -700px'); //скрывается фиксированный фон
                content.css('backgroundPosition', '50% 0'); //показывается скроллируемый фон
            }
        })();
        $(window).bind('resize scroll', scrollBackground);
    }

    /* registration */
    $(function(){
        /*$(".popupReg .clickReg:first").addClass("selected");
			$(".popupReg .formsReg:not(:first)").hide();*/

        $(".popupReg .clickReg").click(function(){
            $(this).next(".formsReg").slideToggle("slow")
            .siblings(".formsReg:visible").slideUp("slow");
            $(this).toggleClass("selected");
            $(this).siblings(".clickReg").removeClass("selected");
//            $('#user_form_captcha').html('<img id="capimg" class="fr" src="http://'+REG_MAIN_WEB_DOMAIN+'captcha/?rand={math equation=rand()}" alt="Captcha Box" title="Captcha" border="0" align="left" onclick="this.src = this.src.replace(this.src.substr(this.src.indexOf(\'=\')+1),\'\') + Math.random(); "/>');
        });
        $("#close_auth_forms").click(function(){
            $("#overlay").css("display","none");
            $("#user_login_form").css("display","none");
            $("#user_forgot_form").css("display","none");
            $("#user_register_form").css("display","none");
            $("#popup_user_forms").css("display","none");
            $('#user_form_captcha').html('');
        });

        $("#open_forgot_pass").click(function(){
            $("#overlay").css("display","block");
            $("#user_login_form").css("display","none");
            $("#user_register_form").css("display","none");
            $("#popup_user_forms").css("display","block");
            $("#user_forgot_form").css("display","block");
        });
        /* is used streight function openUserForm
        $("#open_login_form").click(function(){
            $("#overlay").css("display","block");
            $("#user_forgot_form").css("display","none");
            $("#user_register_form").css("display","none");
            $("#popup_user_forms").css("display","block");
            $("#user_login_form").css("display","block");
            return false;
        });
        $("#open_register_form").click(function(){
            $("#overlay").css("display","block");
            $("#user_forgot_form").css("display","none");
            $("#user_login_form").css("display","none");
            $("#popup_user_forms").css("display","block");
            $("#user_register_form").css("display","block");
            return false;
        });
        */
    });
/* end registration */
    
});

function openUserForm(ftype){
    $("#overlay").css("display","block");
    $("#user_forgot_form").css("display","none");
    $("#user_login_form").css("display","none");
    $("#user_register_form").css("display","none");
    $("#popup_user_forms").css("display","block");
    //$("#user_"+ftype+"_form").css("display","block");
//    if(ftype == 'register')
//        $('#user_form_captcha').html('<img id="capimg" class="fr" src="http://'+REG_MAIN_WEB_DOMAIN+'captcha/?rand={math equation=rand()}" alt="Captcha Box" title="Captcha" border="0" align="left" onclick="this.src = this.src.replace(this.src.substr(this.src.indexOf(\'=\')+1),\'\') + Math.random(); "/>');
    return false;
}

function openSmsInform(pNumber){
            $("#overlay").css("display","block");
            $("#user_form_send_sms").css("display","block");
            $("#profile_cod_number").html(pNumber);
    return false;
}

function closeSmsInform(){
            $("#overlay").css("display","none");
            $("#user_form_send_sms").css("display","none");
    return false;
}

function openPopUp(){
    $("#overlay").css("display","block");
    $("#user_forgot_form").css("display","none");
    $("#user_login_form").css("display","none");
    $("#user_register_form").css("display","none");
    $("#popup_user_forms").css("display","block");
    return false;
}

function closePopUp(){
    $("#overlay").css("display","none");
    $("#user_forgot_form").css("display","none");
    $("#user_login_form").css("display","none");
    $("#user_register_form").css("display","none");
    $("#popup_user_forms").css("display","none");
    return false;
}

function removeCornerClass(ele){
    var reg = new RegExp('(\\s|^corners\\s|$)');
    ele.className=ele.className.replace(reg,' ');
}
