

var rollHandler;

//页面初始化
$(function () {
    rollHandler = setInterval(function () { MarqueeNews() }, 50);
    $('#ulNews1').parent().bind('mouseover', function () {
        clearInterval(rollHandler);
    }).bind('mouseout', function () {
        rollHandler = setInterval(function () { MarqueeNews() }, 50);
    });
    $('.idTabs').idTabs("!mouseover");
    $('.idTabs2').idTabs("!mouseover");
    $('#acnnews').click(function () { window.open('http://news.dichan.sina.com.cn/'); });
    $('#acitynews').click(function () { window.open('http://news.dichan.sina.com.cn/' + $('#acitynews').attr('city')); });
    $('#akfs').click(function () { window.open('http://business.dichan.com/'); });
    $('#agys').click(function () { window.open('http://business.dichan.com/kfs.html'); });

    //搜索关键字提示
    var keywordsTips = [
        '请输入新闻关键字，如：生态 新闻 …',
        '请输入产品关键字，如：防辐射服 …',
        '请输入服务关键字，如：某某公司 …',
		'请输入服务关键字，如：博文标题 …',
        '请输入公司关键字，如：产品问题 …'
    ];

    //不同搜索类型初始化
    $('#ulSearchType a').each(function () {
        $(this).mouseover(function () {
            if ($('#txtKeywords').val() == '' || ($.inArray($('#txtKeywords').val(), keywordsTips) > -1)) {
                $('#txtKeywords').val(keywordsTips[$('#ulSearchType a').index($(this)[0])]);
                $('#txtKeywords').blur();
            }

            $('#txtKeywords').unbind('blur').unbind('focus');
            $('#txtKeywords').blur(function () {
                if ($(this).val() == '') {
                    $(this).val(keywordsTips[$('#ulSearchType a').index($('#ulSearchType .selected')[0])]);
                }
            }).focus(function () {
                if ($(this).val() == keywordsTips[$('#ulSearchType a').index($('#ulSearchType .selected')[0])]) {
                    $(this).val('');
                }
            });
        });
    });
    $('#ulSearchType a:first').trigger('mouseover');

    $('#txtKeywords').keydown(function (e) {
        var keyCode = window.event ? e.keyCode : e.which;
        if (keyCode == 13) {
            $('#btnSearch').click();
        }
    });

    //根据搜索类型搜索
    $('#btnSearch').click(function () {
        if ($('#txtKeywords').val() == '' || ($.inArray($('#txtKeywords').val(), keywordsTips) > -1)) { return; }
        var keywords = $('#txtKeywords').val();
        var channel = '';

        switch ($('#ulSearchType a').index($('#ulSearchType .selected')[0])) {
            case 0:
                channel = 1; break;
            case 1:
                channel = 2; break;
            case 2:
                channel = 3; break;
            case 3:
                channel = 4; break;
				case 4:
                channel = 5; break;
            default:
                channel = 6;
        }

        if (channel == 100)
            window.open('http://data.dichan.com/SearchResult.aspx?BuildingType=home&keywords=' + keywords);
		else if (channel == 1)
            window.open('/news/newssearch.aspx?newskeyword=' + keywords);
		else if (channel == 2)
            window.open('/product/prosearch.aspx?newskeyword=' + keywords);
		else if (channel == 3)
            window.open('/exhibition/company/comsearch.aspx?newskeyword=' + keywords);
		else if (channel == 4)
            window.open('/blog/bowensearch.aspx?newskeyword=' + keywords);
        else
            window.open('http://localhost/search.aspx?&q=' + keywords + '&channel=' + channel);
    });

    //更多城市站触发
    $('#divMoreCities').mouseover(function () {
        $('#divMoreCitiesContainer').show(0);
    }).mouseout(function () {
        $('#divMoreCitiesContainer').hide(0);
    });

    //Slider
    $("#divTradeData").easySlider({
        controlsShow: false,
        vertical: true,
        auto: true,
        pause: 4000,
        continuous: true
    });
});

