function initNav() {
    $("ul.menu li").hover(function() {
        if (!$(this).hasClass('on')) {
            $(this).addClass('over');
        }
    }, function() {
        if (!$(this).hasClass('on')) {
            $(this).removeClass('over');
        }
    })
}

function AutoScroll(obj) {
    $(obj).find('ul:first').animate({
        marginLeft:'-190px'
    }, 1000, function() {
        $(this).css({marginLeft:'0px'}).find('li:first').appendTo(this);
    });
}
function AutoScrollVer(obj) {
    $(obj).find('ul:first').animate({
        marginTop:'-95px'
    }, 1000, function() {
        $(this).css({marginTop:'0px'}).find('li:first').appendTo(this);
    });
}

function submitApplyForm() {
    try {
        var form = document.getElementById("info");
        var arr_input = form.getElementsByTagName("input");
        var way_cal = 0;
        for (var i = 0,len = arr_input.length; i < len; i++) {
            if (arr_input[i].getAttribute("require") == "true" && arr_input[i].value.length == 0) {
                alert("还有必填项没有填写！");
                return false;
            }
            if (arr_input[i].type == "checkbox" && arr_input[i].checked) {
                way_cal++;
            }
        }
        if (way_cal == 0) {
            alert("请选择“获知Coremail途径”");
            return false;
        }
        return true;
    } catch(e) {
        alert(e);
        return false;
    }
}

function initSubnav() {
    $('#menu li').each(function(index) {
        $(this).mouseover(function() {
            $("div[class='subnav']").hide();
            var idx = index + 1;
            $('#subnav_' + idx).fadeIn("fast");
        });
//        $(this).mouseout(function(){
//            $("div[class='subnav']").hide();
//        })
    });
}

function initHotFeature(){
    $('#hotFeature dl').each(function(){
        $(this).mouseover(function(){
            $(this).addClass('on');
        });
        $(this).mouseout(function(){
            $(this).removeClass('on');
        });
    })
}

function initIndexBanner(){
    $('#bannerBtnMenu a').each(function(index){
        var idx = index;
        $(this).click(function(){
            $("#SlideBanner a").hide().removeClass('on');
            $('#SlideBanner a:eq(' + idx + ')').fadeIn('fast').addClass('on');

            $("#bannerBtnMenu a").removeClass('on');
            $('#bannerBtnMenu a:eq(' + idx + ')').addClass('on');
        });
//        $(this).bind('click',function(){
//
//            $("#SlideBanner a").hide().removeClass('on');
//            $('#SlideBanner a:eq(' + idx + ')').fadeIn('fast').addClass('on');
//        })
    })

}


(function($) {
    $.fn.marquee = function(o) {
        //获取滚动内容内各元素相关信息
        o = $.extend({
            speed:        parseInt($(this).attr('speed')) || 30, // 滚动速度
            step:        parseInt($(this).attr('step')) || 1, // 滚动步长
            direction:    $(this).attr('direction') || 'up', // 滚动方向
            pause:        parseInt($(this).attr('pause')) || 1000 // 停顿时长
        }, o || {});
        var dIndex = jQuery.inArray(o.direction, ['right', 'down']);
        if (dIndex > -1) {
            o.direction = ['left', 'up'][dIndex];
            o.step = -o.step;
        }
        var mid;
        var div = $(this); // 容器对象
        var divWidth = div.innerWidth(); // 容器宽
        var divHeight = div.innerHeight(); // 容器高
        var ul = $("ul", div);
        var li = $("li", ul);
        var liSize = li.size(); // 初始元素个数
        var liWidth = li.width() + 10; // 元素宽
        var liHeight = li.height() + 9 || li.offsetHeight + 9; // 元素高
        var width = liWidth * liSize;
        var height = liHeight * liSize;
        if ((o.direction == 'left' && width > divWidth) ||
                (o.direction == 'up' && height > divHeight)) {
            // 元素超出可显示范围才滚动
            if (o.direction == 'left') {
                ul.width(2 * liSize * liWidth);
                if (o.step < 0) div.scrollLeft(width);
            } else {
                ul.height(2 * liSize * liHeight);
                if (o.step < 0) div.scrollTop(height);
            }
            ul.append(li.clone()); // 复制元素
            mid = setInterval(_marquee, o.speed);
            div.hover(
                     function() {
                         clearInterval(mid);
                     },
                     function() {
                         mid = setInterval(_marquee, o.speed);
                     }
                    );
        }
        function _marquee() {
            // 滚动
            if (o.direction == 'left') {
                var l = div.scrollLeft();
                if (o.step < 0) {
                    div.scrollLeft((l <= 0 ? width : l) + o.step);
                } else {
                    div.scrollLeft((l >= width ? 0 : l) + o.step);
                }
                if (l % liWidth == 0) _pause();
            } else {
                var t = div.scrollTop();
                if (o.step < 0) {
                    div.scrollTop((t <= 0 ? height : t) + o.step);
                } else {
                    div.scrollTop((t >= height ? 0 : t) + o.step);
                }
                if (t % liHeight == 0) _pause();
            }
        }

        function _pause() {
            // 停顿
            if (o.pause > 0) {
                var tempStep = o.step;
                o.step = 0;
                setTimeout(function() {
                    o.step = tempStep;
                }, o.pause);
            }
        }
    };
})(jQuery);

//$(document).ready(function(){
//
//});
window.onload = function() {

    var bro = $.browser;

    if (bro.msie && bro.version == '6.0') {
//        try {
            //For IE6
            if (document.getElementById('scrool_wrap_h')) {
                //首页客户案例初始化
                var wrap = setInterval('AutoScroll("#scrool_wrap_h")', 2000);
                $('#scrool_wrap').mouseover(function() {
                    clearInterval(wrap);
                });
                $('#scrool_wrap').mouseout(function() {
                    wrap = setInterval('AutoScroll("#scrool_wrap_h")', 2000);
                });
            }
            if (document.getElementById('scrool_wrap')) {
                //各分页客户案例初始化
                var wrap = setInterval('AutoScrollVer("#scrool_wrap")', 2000);
                $('#scrool_wrap').mouseover(function() {
                    clearInterval(wrap);
                });
                $('#scrool_wrap').mouseout(function() {
                    wrap = setInterval('AutoScrollVer("#scrool_wrap")', 2000);
                });
            }
//        } catch(e) {
//            alert(e);
//        }
    } else {
        $(".marquee").each(function() {
            $(this).marquee();
        });
    }
    initSubnav(); //子菜单
    initHotFeature();//产品卖点
    initIndexBanner(); //主页banner
}
