﻿$(document).ready(function(){
    $("#m_topnav a").bind("mouseover", function(){
		var oldimg=$(this).children().attr("src");
        $(this).children().attr("src", oldimg.replace(/a____/g,"b____")); 
    });
    $("#m_topnav a").bind("mouseout", function(){
		var oldimg=$(this).children().attr("src");
        $(this).children().attr("src", oldimg.replace(/b____/g,"a____")); 
    });
});
//UL分类菜单
$(document).ready(function(){
    /*初始化分类列表样式*/
	$("ul[dis='0']").hide();
	$("#class_dir>ul").attr("dis","1").show();
	$("li[dis='1'],li[dis='2']").parents("ul").attr("dis","1").show();
	$("li[dis='2']>ul").attr("dis","1").show();
	$("#class_dir ul:visible>li[dis!='2']").attr("dis","1");
	$("#class_dir li").each(function(i){
        var cb=$(this).attr("code")
		var ca=cb.length/4;
		var cc=$(this).attr("dis");
		var objtmp=$("ul[code='"+cb+"']");
        if(cc=="2")$(this).addClass("classdir" + ca + "2");
        if(objtmp.attr("code")==undefined){
            $(this).addClass("classdir" + ca + "0");
        }else{
            if(objtmp.attr("dis")=="0"){
                $(this).addClass("classdir" + ca + "1");
            }else{
                $(this).addClass("classdir" + ca + "0");
            }
        }
	});

    /*绑定列表上的单击事件，阻止事件冒泡*/
	$("#class_dir li").bind("click",function(event){
		//if($(this).attr("notc")=="1")return;
		var icode=$(this).attr("code");
		var lcode=icode.length/4;
		//alert(icode);
		var objtmp=$("ul[code='"+icode+"']");		
        	if(objtmp.attr("code")!=undefined){
            		if(objtmp.attr("dis")=="0"){
                		$(this).removeClass("classdir" + lcode + "1").addClass("classdir" + lcode + "0");
                		objtmp.attr("dis","1").show()
            		}else{
                		$(this).removeClass("classdir" + lcode + "0").addClass("classdir" + lcode + "1");
                		objtmp.attr("dis","0").hide()
            		}
        	}
		event.stopPropagation();
	});
	$("#class_dir").show();
});

//只显示指定长度的字符，<a href="aa.htm" cut="6">这是一个很长的标题我只想让它显示6个字符</a>
$(document).ready(function(){
    $("*[cut]").each(function(i){
        var a_title=$(this).html();
        if (a_title.length>0){
            var a_len=$(this).attr("cut")*2;
            $(this).attr("title",a_title);
            var j=0;
            var k=0;
            var jstr1="";
            for (var i=0;i<a_title.length;i++) {
                if (a_title.charCodeAt(i)>255)j++;
                j++;k=i;
                if(j>a_len){jstr1="...";break;}
            }
            $(this).html(a_title.substr(0,k) + jstr1);
        }
    });
});

//按会员等级获取产品的价格,给<span pid="11"></span>
$(document).ready(function(){
	var pids="",joinstr="";
	$("span[pid]").each(function(i){
		pids=pids + joinstr + $(this).attr("pid");
		joinstr=",";
	});
	if(pids!=""){$.ajax({
		url: "../product/getrmb.asp?id=" + pids,
		cache: false,
		async: false,
		success: function(html){
			var pa=html.split(",");
			for(var i=0;i<pa.length-1;i=i+2){
				$("span[pid="+pa[i]+"]").html(pa[i+1]);
			};
		},
		error: function(oajax,errinfo){
			alert("获取会员价格出错");
		}
	});}
});

//按钮样式
$(document).ready(function(){
	$(".button").each(function(i){
		$(this).before("<span class=\"btnout"+(this.disabled?"2":"")+"\" >" + $(this).attr("value") + "</span>"); 
	}); 
	$(".button").prev().bind("click", function(){
  		if(!$(this).next()[0].disabled)$(this).next().click();
	});
 	$(".button").prev().bind("mouseover",function(){
		if(!$(this).next()[0].disabled)$(this).removeClass("btnout").addClass("btnover");
	});
 	$(".button").prev().bind("mouseout",function(){
		if(!$(this).next()[0].disabled)$(this).removeClass("btnover").addClass("btnout");
	});
}); 