//***********************预加载区******************************//
$(function(){
	//--图片大小限制
	$(".text2 img").LoadImage(true,605,0);
	$(".text3 img").LoadImage(true,605,0);
	$("img.img140_117").LoadImage(true,140,117);
	$("img.img550").LoadImage(true,550,0);
	$("img.img98").LoadImage(true,98,0)
	
	/*艺术家字母检索效果*/
	$(".nseacher > li").bind("mouseenter", function(){
		$("a.na", $(this)).addClass('ahover');
		if($(".nlist", $(this)).css("display")=="none"){
			$(".nlist", $(this)).show();
		}
	}).bind("mouseleave",function(){
		if(!$("a.na", $(this)).hasClass('yes')){
			$("a.na", $(this)).removeClass('ahover');
		}
		$(".nlist", $(this)).hide();
	});
	
	/*左栏产品类别效果*/
	$("#nav .lm").each(function(i){
		var nav = $(this);
		nav.find("div.banbg5").click(function(i){
			if(nav.find("div.protype").css('display')=='block'){
				nav.find('div.protype').slideUp();
				$(this).removeClass('banbg2_1');
			}else{
				$("#nav .lm div.protype").slideUp();
				$("#nav .lm div.banbg5").removeClass('banbg2_1');
				nav.find("div.protype").slideDown();
				$(this).addClass('banbg2_1');
			}
		});
		nav.find('div.protype .lm2').each(function(i){
			var pro = $(this);
			pro.find("div.zprobanbg").click(function(i){
				if(pro.find("ul.zprobg").css('display')=='block'){
					pro.find('ul.zprobg').slideUp();
					$(this).removeClass('zprobanbg2');
				}else{
					nav.find("div.protype .lm2 ul.zprobg").slideUp();
					nav.find("div.protype .lm2 div.zprobanbg").removeClass('zprobanbg2');
					pro.find('ul.zprobg').slideDown();
					$(this).addClass('zprobanbg2');
				}										 
			});
		});
	});
});

/*图片预加载 等比例缩放 插件**********************/ 
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!") 
		}); 
	
	}); 
} 

/*验证字符串长度范围*/
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;   
}
