//***********************预加载区******************************//
$(function(){
	//产品列表图
	$("img.img_w640").LoadImage(true,640,0);
	$(".navcon li.sh img").LoadImage(true,620,0);
	//首页品牌鼠标效果
	$(function() {
		$(".ppbox ul li").bind("mouseenter", function(){
			if($(".tooltip", $(this)).css("display")=="none") 
				$("div", $(this)).fadeIn();
		}).bind("mouseleave",function(){
			$(".tooltip", $(this)).hide();
		});
	});
});

//选项卡函数
function showhide(n){
	var t1=$('.navright li a');
	var t2=$('.navcon li.sh');
	for(i=0;i<t1.length;i++){
		if(i==n){
			$(t1[i]).addClass('ahover');
			$(t2[i]).show();
		}
		else{
			$(t1[i]).removeClass('ahover');
			$(t2[i]).hide();
		}
	}
}

/* ************图片预加载 等比例缩放 插件*******************/ 
jQuery.fn.LoadImage=function(scaling,width,height,loadpic){ 
	if(loadpic==null) loadpic="images/imgload.gif";
	return this.each(function(){
		var t=$(this); 
		var src=$(this).attr("src") 
		var img=new Image(); 
		//alert("Loading") 
		img.src=src; 
		//自动缩放图片 
		var autoScaling=function(){ 
			if(scaling){ 
				if(img.width>0 && img.height>0){ 
					if(width<=0){
						if(height<img.height){
							t.height(height);
							t.width((img.width/img.height)*height);
						}
						else{
							t.height(img.height);
							t.width(img.width);
						}
					}
					else if(height<=0){
						if(width<img.width){
							t.width(width);
							t.height((img.height/img.width)*width); 
						}
						else{
							t.height(img.height);
							t.width(img.width);
						}
					}
					else if(img.width/img.height>=width/height){ 
						if(img.width>width){ 
							t.width(width); 
							t.height((img.height*width)/img.width); 
						}else{ 
							t.width(img.width); 
							t.height(img.height); 
						} 
					} 
					else{ 
						if(img.height>height){ 
							t.height(height); 
							t.width((img.width*height)/img.height); 
						}
						else{ 
							t.width(img.width); 
							t.height(img.height); 
						} 
					} 
				} 
			} 
			else{
				t.width(width);
				t.height(height);	
			}
		} 
		//处理ff下会自动读取缓存图片 
		if(img.complete){ 
			//alert("getToCache!"); 
			autoScaling(); 
			return; 
		} 
		$(this).attr("src",""); 
		var loading=$("<img alt=\"加载中\" title=\"图片加载中\" src=\""+loadpic+"\" />"); 
		
		t.hide(); 
		t.after(loading); 
		$(img).load(function(){ 
			autoScaling(); 
			loading.remove(); 
			t.attr("src",this.src); 
			t.show(); 
			//alert("finally!") 
		}); 
	
	}); 
} 
/*
使用说明：
1.$("div img").LoadImage(true,100,100); 
2.onload="$(this).LoadImage(true,100,100)"
*/

/*验证字符串长度范围*/
function betweenLength(str,_min,_max){
	return (str.length>=_min&&str.length<=_max);
}

//去掉字符串左右空格方法   
function trim(m){
	 while((m.length>0)&&(m.charAt(0)==''))   
		m = m.substring(1, m.length);   
	 while((m.length>0)&&(m.charAt(m.length-1)==''))   
		m = m.substring(0, m.length-1);   
	 return m;   
}
