function layerswich(a,b,c){	
	$(b).hide(); //Hide all content
	$("ul"+a+" li:first").addClass(c).show(); //Activate first tab
	$(b+":first").show(); //Show first tab content
	
	//On Click Event
	$("ul"+a+" li.tab").click(function() {
		$("ul"+a+" li.tab").removeClass(c); //Remove any "active" class
		$(this).addClass(c); //Add "active" class to selected tab
		$(b).hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("name"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		
	});
}



function page_go(id,num, c,t,cid){
    var Prev = id + "Prev";
    var Next = id + "Next";    
    var pageId = id + "Page";
    var Page = 0;
    var currentPage = 1;
    var PageNumber = Math.ceil(t/num);
    var activeClick = true;
    var gopage = 0;
    if(num>t){activeClick = false;}
    if(c >= num){
        if(t!=null){
            gopage = Math.ceil(c/num);
            if(c % num == 0) gopage++;         
        }
        updateProduct('goto', gopage);
    }
    
    function updateProduct(type, gopage) {
        if(type=='pre') {Page -= parseInt(num);currentPage--};
        if(type=='next') {Page += parseInt(num);currentPage++};
        if(type=='goto' && gopage != null) {Page = (gopage-1) * num ; currentPage = gopage;}
        if(Page<0) {
            Page=num*(PageNumber-1);
            currentPage=PageNumber;
        }
        if(Page>=t) {
            Page=0;
            currentPage=1;
        }
        $('#'+pageId).html(currentPage +'/'+PageNumber);
        for(i=0;i<num;i++){
            if(i >= productPrice.length){
                break;
            }
            
            n_page = i + Page;
            
            $('#cell_price'+i).html(productPrice[n_page]);
            $('#cell_link'+i).attr('href',productLink[n_page]);
            $('#cell_link'+i).attr('title',productName[n_page]) ;
            
            $('#li'+i).css('display','block');
            if(productID[n_page] == null){
                $('li'+i).css('display','none');
                continue;
            }
            if(num==5)$('#cell_img'+i).attr('src',baseURL+"images/root/loading_img_b.gif");
            if(num==10)$('#cell_img'+i).attr('src',baseURL+"images/root/loading_img_s.gif");
            $('#cell_img'+i).attr('alt',productName[n_page]);
            $('#cell_img'+i).attr('title',productName[n_page]);
            $('#cell_img'+i).attr('src',imgURL+productIMG[n_page]);
             
            if(cid != null){
                if(cid == productID[n_page]){
                    $('#cell_img'+i).addClass('allborder') ;
                }
                else{
                    $('#cell_img'+i).removeClass('allborder');
                }
            }
            
            if(productSourcePrice != null){
                $('#cell_source_price'+i).html(productSourcePrice[n_page]);
            }
            
            if( productName != null){            
                $('#cell_name'+i).html(productName[n_page].substring(0,30)+'...');
                $('#cell_name_link'+i).attr({href:productLink[n_page],title:productName[n_page]});

            }

        }
    }

    $('#'+pageId).html(currentPage +'/'+PageNumber);
    $('#'+Prev).click(function()
    {    
        if(!activeClick) return false;
        updateProduct('pre');
        });
    $('#'+Next).click(function () {
        if(!activeClick) return false;
        updateProduct('next');
    })    
}


$(function(){

$('#productAttributes select').append('<option value="null" selected="selected">please select</option>');

$('#addcart').click(function(check){


$('#productAttributes select').each(function(){

if($(this).val()=='null')
{alert('please select');check.preventDefault(); }
})

});

})

$(function(){
     var len  = $(".luhui img").length;
     var index = 0;
     var adTimer;
     $(".luhui").mouseover(function(){
        index  =   $(".luhui").index(this);
        showImg1(index);
     }).eq(0).mouseover();    

    $('.luhui').hover(function(){
              if(adTimer){
                 clearInterval(adTimer);
              }
     },function(){
              adTimer = setInterval(function(){
                showImg1(index)
                index++;
                if(index==len){index=0;}
              } , 3000);
     });
	 if(len>0)
	 {
	   var adTimer = setInterval(function(){
		  showImg1(index)
		  index++;
		  if(index==len){index=0;}
	   } , 3000);
	 }
})
function showImg1(index){
       var temp= $(".luhui").eq(index).find('a').attr('middle');
       var temp1= $(".luhui").eq(index).find('a').attr('large');
        $("#productMainImage").find('img').attr('src',temp);
        $("#productMainImage").find('a').attr('href',temp1);
        $(".luhui")
            .eq(index).addClass("hover")
            .siblings().removeClass("hover");
      
}

