
	thunderLinker.TITLE="[$TITLE$]";											
	thunderLinker.LINK="[$LINK$]";
	thunderLinker.isDebug=(document.location.search.indexOf("thunderdbg=1")>0);
	thunderLinker.auto=true;
	


	function thunderLinker()
	{
		var pid=arguments[0];													
		var strPath=arguments[1];												
		var linkStyle=arguments[2]?arguments[2]:"";
		var append=typeof(arguments[3])!="undefined"?arguments[3]:null;		
		var convertSingle=false;
		var txtV=unescape("%u8FC5%u96F7%u4E13%u7528%u9AD8%u901F%u4E0B%u8F7D");
		var exceptPath="";
		var convertCount=0;
		var htmlB="";
		var linkModal=thunderLinker.LINK+"&nbsp;&nbsp;";

		try{htmlB=thunderHTMLInsert;}catch (e){htmlB="&nbsp;";}

		try{convertCount=thunderLinkCount;}catch(e){convertCount=0;}
		
		try{exceptPath=thunderExceptPath;}catch (e){exceptPath="";}

		try{linkModal=thunderLinkHTML}catch (e){}

		if(linkModal.indexOf(thunderLinker.LINK)<0) linkModal+=thunderLinker.LINK;


		//var objTag=typeof(arguments[4])!="undefined"?arguments[4]:null;
		/*
		if (!objTag)
		{
			try{objTag=thunderTagId;}catch(e){objTag=null;}			
		}

		if(objTag!=null)
		{
			objTag=document.getElementById(objTag);
		}
		*/

		if(append==null)
		{
			try{append=thunderAppend;}catch(e){append=false;}
		}

		if(thunderLinker.isDebug)	alert(append);
		
		if(linkStyle=="" || typeof(linkStyle)=="undefined")
		{
			try{ linkStyle=thunderLinkStyle; }catch(e){ linkStyle=""; }
		}

		if(linkStyle!=""){linkStyle=linkStyle.replace(/\\/g,"\\")}				


		
		
		var thunderSufix=".chm|.asf|.avi|.exe|.iso|.mp3|.mpeg|.mpg|.mpga|.ra|.rar|.rm|.rmvb|.tar|.wma|.wmv|.zip|.swf|.mp4|.3gp|.torrent|.txt|.jar|.mov|.wav|.eip";
		

		if(typeof(pid)=="undefined" || pid==null)
		{
			try{
				pid=thunderPid;
			}catch(e){
				pid="";
			}

			if(pid=="" || typeof(pid)==null || isNaN(pid)) 
			{
				if(thunderLinker.isDebug)
					alert("Pid is not provided!");
				return false;
			}
		}

		if(strPath==null || typeof(strPath)=="undefined")
		{
			try{strPath=thunderPath;}catch(e){strPath="";}
		}
			
		var a=document.links;
		var thunderSufix=thunderSufix.replace(/\./g,"\\.");
		
		
		var reg=eval("/^(http:\\/\\/|ftp:\\/\\/|mms:\\/\\/){1}[\\s\\S]*?("+thunderSufix+"){1}$/i");
		
		var aLength=a.length;
		var addL=0;

		var converted=0;
		
		if (convertCount<=0)
		{
			convertCount=aLength;
		}

		for(var i=0;i<aLength;i++)
		{

			
			
			if(a[i+addL].href)
			{
				

				if(exceptPath!="")
				{
					if(typeof(exceptPath)=="string")
					{
						if(a[i+addL].href.indexOf(exceptPath)>=0)
						{
							continue;
						}
					}else if(exceptPath.test){
						if(a[i+addL].href.match(exceptPath)!=null)
						{
							continue;
						}
					}
				}

				if(a[i+addL].href.substr(a[i+addL].href.length-1,1)=="#" && a[i+addL].thunderHref) 
				{
					
					if(thunderLinker.isDebug)
					{
						alert("ThunderHref:"+a[i+addL].thunderHref);
						alert("href:"+a[i+addL].href);
					}
					continue;	
				}

				var lk=a[i+addL].href;
				var href="";
				var thP="";
				var thSufix="thunder://";
				 
				
				if(lk.indexOf(thSufix)==0)
				{
					thP=lk;
					if (thunderLinker.isDebug)
					{
						alert("thunderLinker!["+thP+"]");
					}
				}
				else if(reg.test(lk))
				{
					href=lk;					
				}else{					
					
										
					if(strPath!="" && strPath!=null)
					{
						if(typeof(strPath)=="string")
						{
							if(lk.toLowerCase().indexOf("/"+strPath)>-1)
							{
								href=lk;
								if (thunderLinker.isDebug)
								{
									alert("other://String Path Valid!");
								}
							}
						}else
						{
							if(strPath.test)
							{

								var dddd=strPath.test(lk)
								
								//For dz6 debug
								if(lk.indexOf("attachment")>0 && thunderLinker.isDebug)
								{
									alert(String(strPath)+".test('"+lk+"')="+String(dddd));
								}
								///alert(dddd);
								if(lk.match(strPath)!=null)
								{
									href=lk;
									if (thunderLinker.isDebug)
									{
										alert("**********************RegEx*********************");
									}
								}else{
									if (thunderLinker.isDebug)
									{
										alert("other://Reg Path Invalid!\n["+strPath+"]"+lk+"||||<"+String(dddd)+">||||");
									}
								}
							}
						}
					}
				}
				
				if(href!="")
				{
					thP=ThunderEncode(href);
				}

				if(thP!="")
				{
					
					var tmpLk=a[i+addL];					
					
					//alert(thP);
					
					
					if(linkStyle!="")
					{	
						if(!append || href=="")
						{
							/*
							if(objTag)
							{

								objTag.innerHTML+=linkModal.replace(thunderLinker.LINK,"<a href='#' title='"+txtV+"' thunderHref='"+thP+"' thunderPid='"+pid+"' thunderType='' thunderResTitle='' onClick='return OnDownloadClick_Simple(this,2)' oncontextmenu='ThunderNetwork_SetHref(this)'>"+linkStyle.replace(thunderLinker.TITLE,tmpLk.innerHTML)+"</a>");
								tmpLk.parentNode.removeChild(tmpLk);
								

								converted++;
							}else
							{
								*/
								var s = document.createElement("anchor");
								s.innerHTML+=linkModal.replace(thunderLinker.LINK,"<a href='#' title='"+txtV+"' thunderHref='"+thP+"' thunderPid='"+pid+"' thunderType='' thunderResTitle='' onClick='return OnDownloadClick_Simple(this,2)' oncontextmenu='ThunderNetwork_SetHref(this)'>"+linkStyle.replace(thunderLinker.TITLE,tmpLk.innerHTML)+"</a>");
								tmpLk.replaceNode(s);
								

								converted++;
							//}
						}else{
							if(href!="")	
							{
								
								a[i+addL].insertAdjacentHTML("beforebegin",linkModal.replace(thunderLinker.LINK,"<a href='#' title='"+txtV+"' thunderHref='"+thP+"' thunderPid='"+pid+"' thunderType='' thunderResTitle='' onClick='return OnDownloadClick_Simple(this,2)' oncontextmenu='ThunderNetwork_SetHref(this)'>"+linkStyle.replace(thunderLinker.TITLE,tmpLk.innerHTML)+"</a>")+htmlB);
								
								
								if(thunderLinker.isDebug)  alert(s.innerHTML);
								addL++;

								converted++;
							}
						}
					}else
					{
						if(!append || href=="")
						{
							var s = document.createElement("anchor");
							s.innerHTML+=linkModal.replace(thunderLinker.LINK,"<a href='#' title='"+txtV+"' thunderHref='"+thP+"' thunderPid='"+pid+"' thunderType='' thunderResTitle='' onClick='return OnDownloadClick_Simple(this,2)' oncontextmenu='ThunderNetwork_SetHref(this)'>"+tmpLk.innerHTML+"</a>");
							tmpLk.replaceNode(s);

							converted++;
						}else
						{
							if(href!="")	
							{
								
								a[i+addL].insertAdjacentHTML("beforebegin",linkModal.replace(thunderLinker.LINK,"<a href='#' title='"+txtV+"' thunderHref='"+thP+"' thunderPid='"+pid+"' thunderType='' thunderResTitle='' onClick='return OnDownloadClick_Simple(this,2)' oncontextmenu='ThunderNetwork_SetHref(this)'><font color='red'>"+txtV+"</font></a>")+htmlB);
								
								
								if(thunderLinker.isDebug) alert(s.innerHTML);
								addL++;

								converted++;
							}
						}
					}
					
					if(thunderLinker.isDebug)
					{
						alert(converted);
					}
					if(converted>=convertCount) break;
					
					
				}
			}
		}
	}

	
	

	document.onreadystatechange=function ()
	{
		

		if(document.readyState=="complete")
		{
			try{
					thunderLinker.auto=thunderFuncType;
				}catch(e){
					thunderLinker.auto=true;
				}
			

			if(document.body && thunderLinker.auto)
			{
				var a=function(){};
				if(typeof(document.body.onload)=="function")
				{
					a=document.body.onload;
				}
				document.body.onload=function()
				{
					a();
					thunderLinker();
				}
			}else{

				if(thunderLinker.isDebug && !document.body)
				{
					for(a in document)
					{
						alert(a);
					}
				}
			}
		}
	}

	