﻿$(document).ready(function() {
    $('#txtGlobalSearchKeyword').unbind().focus(function() {
        var value = $.trim($(this).val());
        if (value == '请输入您关注的主题')
            $(this).val('').css('color', '#333');
    }).blur(function() {
        var value = $.trim($(this).val());
        if (value.length == 0)
            $(this).val('请输入您关注的主题').css('color', '#848484');
    }).keypress(function(e) {
        var event = e || window.event;
        if (event.keyCode == 13)
            GlobalSearch();
    }).jqueryinputfilter({
        url: commonControllerUrl,
        marginTop: 32,
        objectType: 3, //过滤主题
        autoInput: true,
        afterChoiceEvent: 'GlobalSearch',
        canAdd: true //需要添加按钮
    });

    $('.menu').unbind().hover(function() {
        var $divItem = $(this).find('div');
        for (var i = 0; i < $divItem.length; i++) {
            switch (i) {
                case 0:
                    $divItem.eq(i).removeClass('menu-left');
                    $divItem.eq(i).addClass('menu-lefthover');
                    break;
                case 1:
                    $divItem.eq(i).removeClass('menu-center');
                    $divItem.eq(i).addClass('menu-centerhover');
                    break;
                case 2:
                    $divItem.eq(i).removeClass('menu-rigth');
                    $divItem.eq(i).addClass('menu-rigthhover');
                    break;
            }
        }
    },
     function() {
         var $divItem = $(this).find('div');
         for (var i = 0; i < $divItem.length; i++) {
             switch (i) {
                 case 0:
                     $divItem.eq(i).removeClass('menu-lefthover');
                     $divItem.eq(i).addClass('menu-left');
                     break;
                 case 1:
                     $divItem.eq(i).addClass('menu-center');
                     $divItem.eq(i).removeClass('menu-centerhover');
                     break;
                 case 2:
                     $divItem.eq(i).addClass('menu-rigth');
                     $divItem.eq(i).removeClass('menu-rigthhover');
                     break;
             }
         }
     });

    $('a.showmorelink').unbind().click(function(event) {
        event.stopPropagation();
        var $morelink = $(this).next();
        if ($morelink.css('display') == 'none')
            $morelink.show();
        else
            $morelink.hide();
    });

    $('#btnGlobalSearch').unbind().bind('click', GlobalSearch);

    var widthHottopics1 = $('.global-search-hottopics').width();
    var itema = $('.global-search-hottopics').find('a');
    var widthHottopics2 = 0;
    for (var i = 0; i < itema.length; i++) {
        widthHottopics2 += itema.eq(i).width();
        if (widthHottopics2 > widthHottopics1) {
            itema.eq(i).remove();
        }
    }
});

function GlobalSearch() {
    var txtGlobalSearchKeyword = $.trim($('#txtGlobalSearchKeyword').val());
    if (txtGlobalSearchKeyword == '' || txtGlobalSearchKeyword == '请输入您关注的主题') {
        AlertTips("系统提示：", "请输入搜索条件！", 1, "$('#txtGlobalSearchKeyword')[0].focus()");
        return false;
    }

    var searchUrl = '/Search/?keyword=' + escape(txtGlobalSearchKeyword) + '&domainID=0&pageIndex=1';
    GoUrl(searchUrl);
}


function ClickHideThis() {
    if ($('#divDesignWordsUpTips').length > 0)
        $('#divDesignWordsUpTips').hide();
    $('.divShareThis,.divShareThisArrow').hide();
    $('#divShowMiniBlogTips').hide();
    $('#divAddMiniBlogKeyword,#divKeywordTopicListBorder,#divKeywordTopicListInfo').hide();
    $('.divConfidantInfo').hide();
    $('.morelink-border').hide();
}
