

// JavaScript Document
function switchTab(identify,index,count) {
	for(i=0;i<count;i++) {
		var CurTabObj = document.getElementById("Tab_"+identify+"_"+i) ;
		var CurListObj = document.getElementById("List_"+identify+"_"+i) ;
		if (i != index) {
			fRemoveClass(CurTabObj , "upH3") ;
			fRemoveClass(CurListObj , "upBox") ;
		}
	}
	fAddClass(document.getElementById("Tab_"+identify+"_"+index),"upH3") ;
	fAddClass(document.getElementById("List_"+identify+"_"+index),"upBox") ;
}

function switchSideTab(identify,index,count) {
	for(i=0;i<count;i++) {
		var CurTabObj = document.getElementById("Tab_"+identify+"_"+i) ;
		var CurListObj = document.getElementById("List_"+identify+"_"+i) ;
		if (i != index) {
			fRemoveClass(CurTabObj , "upH3") ;
			fRemoveClass(CurListObj , "upUL") ;
		}
	}
	fAddClass(document.getElementById("Tab_"+identify+"_"+index),"upH3") ;
	fAddClass(document.getElementById("List_"+identify+"_"+index),"upUL") ;
}

function fAddClass(XEle, XClass)
{/* shawl.qiu code, void return */
  if(!XClass) throw new Error("XClass 不能为空!");
  if(XEle.className!="") 
  {
    var Re = new RegExp("\\b"+XClass+"\\b\\s*", "");
    XEle.className = XEle.className.replace(Re, "");
	var OldClassName = XEle.className.replace(/^\s+|\s+$/g,"") ;
	if (OldClassName == "" ) {
		 XEle.className = XClass;
	}
	else {
		XEle.className = OldClassName + " " + XClass;
	}
   
  }
  else XEle.className = XClass;
}/* end function fAddClass(XEle, XClass) */

function fRemoveClass(XEle, XClass)
{/* shawl.qiu code, void return */
  if(!XClass) throw new Error("XClass 不能为空!");
  var OldClassName = XEle.className.replace(/^\s+|\s+$/g,"") ;
  if(OldClassName!="") 
  {
	
    var Re = new RegExp("\\b"+XClass+"\\b\\s*", "");
    XEle.className = OldClassName.replace(Re, "");
  }
}/* function fRemoveClass(XEle, XClass) */
function switchPic(screen) {
	if (screen > MaxScreen) {
		screen = 1 ;
	}
	
	for (i=1;i<=MaxScreen;i++) {
		document.getElementById("Switch_"+i).style.display = "none" ;
	}
	document.getElementById("Switch_"+screen).style.display = "block" ;
	showSwitchNav(screen);
	showSwitchTitle(screen);
	//Effect.Appear("Switch_"+screen);
			
	//switchLittlePic(screen);
	//showSwitchTitles(screen);
	CurScreen = screen  ;
}
function showSwitchNav(screen) {
	var NavStr = "" ;
	for (i=1;i<=MaxScreen;i++) {
		if (i == screen) {
			NavStr += '<li onmouseover="pauseSwitch();" onmouseout="goonSwitch();"><a href="javascript://" target="_self" class="sel">'+i+'</a></li>' ;
		}
		else {
			NavStr += '<li onmouseover="pauseSwitch();" onmouseout="goonSwitch();" onclick="goManSwitch('+i+');"><a href="javascript://" target="_self">'+i+'</a></li>' ;
		}
		
	}
	document.getElementById("SwitchNav").innerHTML = NavStr ;
}
function showSwitchTitle(screen) {
	var titlestr = "" ;
	titlestr = '<h3><a href="'+Switcher[screen]['link']+'" target="_blank">'+Switcher[screen]['title']+'</a></h3><p><a href="'+Switcher[screen]['link']+'" target="_blank">'+Switcher[screen]['stitle']+'</a></p>' ;
	document.getElementById("SwitchTitle").innerHTML = titlestr ;
}
function reSwitchPic() {
	refreshSwitchTimer = null;
	switchPic(CurScreen+1);
	refreshSwitchTimer = setTimeout('reSwitchPic();', 3000);
}
function pauseSwitch() {
	clearTimeout(refreshSwitchTimer);
}
function goonSwitch() {
	clearTimeout(refreshSwitchTimer);
	refreshSwitchTimer = setTimeout('reSwitchPic();', 3000);
}
function goManSwitch(index) {
	clearTimeout(refreshSwitchTimer);
	
	CurScreen = index - 1 ;
	reSwitchPic();
}

$(document).ready(function(){	        

		// 明星商品自动滚动
		starProduct();
        setInterval(tabLoop, 6000);

		
});

function changeProductDiv(id)
{
	
	$("#tab_nav a").attr("class","");
	$("#tab_area div").hide();

	$("#tab_link_"+id).attr("class","now");
	$("#ProductShow_tab_"+id).show();

}

function changeClassTab(id)
{
	$("#BigClassPanel li").attr("class","");
	$("#TabList div").hide();

	$("#tab"+id).attr("class","now");
  if (id!="")
  {	
	$("#d"+id).show();
  }
}

function changeLClassTab(id)
{
	$("#c"+id).attr("class","now");

}


function tabLoop()
{
	
	if (typeof(tabNum) === "undefined")
	{
		tabNum = 2;
	}
	changeProductDiv(tabNum);
	tabNum = tabNum + 1;
	if (tabNum > 5)
	{
		tabNum = 1;
	}
	
}



// 明星商品左右滚动
(function($){
$.fn.extend({
        Scroll:function(opt,callback){
                //参数初始化
                if(!opt) var opt={};
                var _btnLeft = $("#"+ opt.left);//Shawphy:向左按钮
                var _btnRight = $("#"+ opt.right);//Shawphy:向右按钮
                var timerID;
				var initTimer;
                var _this=this.eq(0).find("ul:first");
                var     lineW=_this.find("li:first").width(), //获取行宽             
                        line=opt.line?parseInt(opt.line,10):parseInt(this.width()/lineW,10), //每次滚动的行数，默认为一屏，即父容器高度
                        speed=opt.speed?parseInt(opt.speed,10):500; //卷动速度，数值越大，速度越慢（毫秒）
                        timer=opt.timer //?parseInt(opt.timer,10):3000; //滚动的时间间隔（毫秒）
                if(line==0) line=1;
                var upWidth=0-line*lineW;
                
                //向左滚动函数
                var scrollLeft=function(){
                        _btnLeft.unbind("click",scrollLeft); //Shawphy:取消向左按钮的函数绑定
                        _this.animate({
                                marginLeft:upWidth
                        },speed,function(){
                                for(i=1;i<=line;i++){
                                        _this.find("li:first").appendTo(_this);
                                }
                                _this.css({marginLeft:0});
                                _btnLeft.bind("click",scrollLeft); //Shawphy:绑定向上按钮的点击事件                        
                        });
                        return false;
                }

                //Shawphy:向右滚动函数
                var scrollRight=function(){
                        _btnRight.unbind("click",scrollRight);
                        for(i=1;i<=line;i++){
                                _this.find("li:last").show().prependTo(_this);
                        }
                        _this.css({marginLeft:upWidth});
                        _this.animate({
                                marginLeft:0
                        },speed,function(){
                                _btnRight.bind("click",scrollRight);
                        });
                        return false;
                }

				//自动滚动	
				var scrollInit=function(){
					initTimer=setInterval(scrollRight,5000);						
				}

                 //鼠标事件绑定
                _btnLeft.click(scrollLeft);
                _btnRight.click(scrollRight);
				scrollInit();
				
        }       
})
})(jQuery);


// 明星商品自动滚动
function starProduct()
{

	$("#star_product").Scroll({line:1,speed:1000,timer:5000,left:"product_left",right:"product_right"});
}

