//***********************预加载区******************************//
$(function(){
	$(".img_w85_h100").LoadImage(true,85,100);
});

/*图片预加载 等比例缩放 插件**********************/ 
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;   
}

/**==================================设为首页与加入收藏夹js================================**/

//监听网页的单击事件，主要监听设为首页与加入书签标签
document.onclick = function(e)
{
  var target = e ? e.target : window.event.srcElement;
  while (target && !/^(a|body)$/i.test(target.nodeName))
  {
    target = target.parentNode;
  }
  if (target && target.getAttribute('rel'))
  {
  	if (target.rel == 'external'){
	    var external = window.open(target.href);
	    return external.closed;
    } else if (target.rel == 'setAsHomepage'){
    	setAsHomepage(target,target.href);
    	return false;
    } else if (target.rel == 'addToBookmark'){
    	addToBookmark(target.title,target.href,"");
    	return false;
    }
  }
}
//设为首页
//<a href="" class="SetAsHomepage" rel="setAsHomepage">设为首页</a>
function setAsHomepage(element,Url)
{
	try
	{
		element.style.behavior='url(#default#homepage)';element.setHomePage(Url);
	}
	catch(e){
		if(window.netscape)
		{
			try
			{
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
			}  
			catch (e) 
			{ 
				alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将[signed.applets.codebase_principal_support]设置为'true'"); 
				return false;  
			}
			var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
			prefs.setCharPref('browser.startup.homepage',Url);
		}
	}
}
//加入收藏夹
//<a href="" title="" class="AddToBookmark" rel="addToBookmark">加入书签</a>
function addToBookmark(WebsiteName,Url,Description)   
{
	if (window.sidebar) {  
		window.sidebar.addPanel(WebsiteName,Url,Description); //Mozilla browser  
	} else if( document.all ) { //IE browser  
		window.external.AddFavorite(Url, WebsiteName);   
	} else if( window.opera && window.print ) { //Not Support Now  
		return true;  
	}  
}
