$(document).ready(function(){


    $(".nav li").hover(function(){
		if($(this)){
			var index = $(".nav li").index($(this)[0]);
			if(index==0){
				$(this).children("a").addClass("clas");
			}else{
				$(this).children("a").addClass("otherClas");
			}
		}
    },function(){
		if($(this).children("a").hasClass("current")){
		}else{
			var index = $(".nav li").index($(this)[0]);
			if(index==0){
				$(this).children("a").removeClass();
				$(this).children("a").addClass("first");
			}else{
				$(this).children("a").removeClass();
			}
		}
    });
	$("#wangdian").hover(function(){
		if($(this).children("img").hasClass("en")){
			$(this).children("img").attr("src","images/index_r2_c2_hover_en.jpg");
		}else{
		  $(this).children("img").attr("src","images/btn_hover.jpg");
		}
	},function(){
		if($(this).children("img").hasClass("en")){
			$(this).children("img").attr("src","images/index_r2_c2_en.jpg");
		}else{
		  $(this).children("img").attr("src","images/index_r2_c2.jpg");
		}
	});

});

/*
 * 首页文章滚动
 */
$(function() {
    var $list = $('#article-list ul');
    var $item = $list.find('li');
    var height = $item.height();
    var length = $item.length;
    var isInAnimate = false;
    var interId = 0;

    $('#article-prev').click(function() {
        prev();
        return false;
    });
//    .mouseover(clear)
//    .mouseout(auto);

    $('#article-next').click(function() {
        next();
        return false;
    });
//    .mouseover(clear)
//    .mouseout(auto);

    $list.mouseover(clear).mouseout(auto);

    auto();

    function prev() {
        if (!isInAnimate) {
            isInAnimate = true;

            //重新获取排序
            $item = $list.find('li');

            //把最后一个放在最前面
            $list.css('margin-top',-height+'px');
            $list.prepend($item[length-1]);
            //向下滚动, 查看上面的文章
            $list.animate({
                'margin-top':0
            }, {
                'duration':500,
                'complete':function() {
                    isInAnimate = false;
                }
            });
        }
    }

    function next() {
        if (!isInAnimate) {
            isInAnimate = true;

            //重新获取排序
            $item = $list.find('li');

            //向上滚动, 查看下面的文章
            $list.animate({
                'margin-top':'-='+height
            },{
                'duration':500,
                'complete':function() {
                    //把第一个放到最后去
                    $list.append($item[0]);
                    $list.css('margin-top','0');
                    isInAnimate = false;
                }
            });
        }
    }

    function auto() {
        interId = setInterval(next, 5000);
    }

    function clear() {
        clearInterval(interId);
    }
});
