﻿function SelectPage(selfObj, att, TagsId, HeadAtt, cssName){
	var tag = document.getElementById(TagsId).getElementsByTagName("a");
	var taglength = tag.length;
	for(i=0; i<taglength; i++){
		tag[i].className = "";
	}
	//$("#"+TagsId+" [class="+cssName+"]").removeClass(cssName);
	//$("#"+TagsId+" li [class="+cssName+"]").removeClass(cssName);  //有li的标签
	selfObj.className = cssName;
	for(i=0; i<taglength; i++){
	    document.getElementById(HeadAtt + i).style.display = "none";
	}
	document.getElementById(HeadAtt + att).style.display = "block";
}


function SelectPageLi(selfObj, att, TagsId, HeadAtt, cssName) {
    var tag = document.getElementById(TagsId).getElementsByTagName("li");
    var taglength = tag.length;
    for (i = 0; i < taglength; i++) {
        tag[i].className = "";
    }
    //$("#"+TagsId+" [class="+cssName+"]").removeClass(cssName);
    //$("#"+TagsId+" li [class="+cssName+"]").removeClass(cssName);  //有li的标签
    selfObj.className = cssName;
    for (i = 0; i < taglength; i++) {
        document.getElementById(HeadAtt + i).style.display = "none";
    }
    document.getElementById(HeadAtt + att).style.display = "block";
}

function PicSwitching(SliceTags, SlicePage, cssName, lab) {
    var currentIndex = 0;
    var currentHtml;
    var DEMO; //函数对象
    $("#" + SliceTags + " " + lab).eq(0).addClass(cssName);
    $("#" + SlicePage + " " + lab).eq(0).show(); //默认
    autoScroll();

    $("#" + SliceTags + " " + lab).hover(function () {
        StopScrolll();
        //currentIndex = Number($(this).html()) - 1;  //标签为数字时可以用这方法，否则用以下方法
        currentHtml = $(this).html();
        currentIndex = 0;
        $(this).parent().children().each(function () {
            if ($(this).html() == currentHtml)
                return false;
            currentIndex++;
        });

        $("#" + SliceTags + " " + lab).removeClass(cssName)//所有的li去掉当前的样式加上正常的样式
        //$(this).addClass(cssName); //ie6显示有问题
        $("#" + SliceTags + " " + lab).eq(currentIndex).addClass(cssName);
        //$("#" + SliceTags + " " + lab).eq(currentIndex).attr("id", "n" + (currentIndex + 1).toString());  //特殊情况下加上id才能切换样式
        //$("#" + SlicePage + " " + lab).not($("#" + SlicePage + " " + lab)[currentIndex]).hide(); //除了自身别的全部隐藏
        $("#" + SlicePage + " " + lab).hide(); //除了自身别的全部隐藏
        $("#" + SlicePage + " " + lab).eq(currentIndex).show(); //缓慢显示(有个小bug)

    }, function () {
        //当鼠标离开对象的时候获得当前的对象的ID以便能在启动自动时与其同步
        autoScroll();
    });

    $("#" + SlicePage + " " + lab).hover(function () {
        StopScrolll();

    }, function () {
        //当鼠标离开对象的时候获得当前的对象的ID以便能在启动自动时与其同步
        //var currentID = $(this).attr("id"); //取当前元素的ID
        //currentIndex = Number(currentID.substring(currentID.length - 1));

        currentHtml = $(this).html();
        currentIndex = 0;
        $(this).parent().children().each(function () {
            if ($(this).html() == currentHtml)
                return false;
            currentIndex++;
        });
        autoScroll();
    });

    //自动滚动
    function autoScroll() {
        //$("#SliceTags li:last").removeClass(cssName);
        //$("#ifocus_tx li:last").hide();
        $("#" + SliceTags + " " + lab).eq(currentIndex).addClass(cssName);
        $("#" + SliceTags + " " + lab).eq(currentIndex - 1).removeClass(cssName);
        //$("#" + SliceTags + " " + lab).eq(currentIndex).attr("id", "n" + (currentIndex + 1).toString());  //特殊情况下加上id才能切换样式
        $("#" + SliceTags + " " + lab).eq(currentIndex - 1).removeAttr("id");

        $("#" + SlicePage + " " + lab).eq(currentIndex).show();  //缓慢显示
        $("#" + SlicePage + " " + lab).eq(currentIndex - 1).hide();

        currentIndex++; currentIndex = currentIndex >= $("#" + SliceTags + " " + lab).length ? 0 : currentIndex;
        DEMO = setTimeout(autoScroll, 3000);  //数字越大图片切换得越慢
    }
    function StopScrolll() {
        //当鼠标移动到对象上面的时候停止自动滚动
        clearTimeout(DEMO);
    }
}
