function matchNode(xpath, root){
    var type = XPathResult.ORDERED_NODE_SNAPSHOT_TYPE;
    var doc = root ? root.evaluate ? root : root.ownerDocument : document;
    return doc.evaluate(xpath, root || doc, null, type, null);
}   

var fetch;



function watch_scroll(){

			var alltext = new Array();
			alltext[0]='>';
			alltext[1]='Next';
			alltext[2]='››';
			alltext[3]='下一页';
			alltext[4]='»';

			//alert(alltext.length)
			//checkLinks();
			if (!fetch) {
			var i,textlinks,link,xpathNext,text;

			for (i=0;i<alltext.length;i++)	{		
				text=alltext[i];

			//alert(text);
			xpathNext ='';
			xpathNext += '//a[(normalize-space(text())="' + text + '"' +
					 ' or normalize-space(@title)="' + text + '"' +
					 ' or font[normalize-space(text())="' + text + '"]' +
					 ' or img[normalize-space(@alt)="' + text + '"]' +
					 ' or img[normalize-space(@title)="' + text + '"]' +
					 ') and not(starts-with(@href,"javascript:"))] | ';
			xpathNext = xpathNext.substr(0,xpathNext.length-3);
			
			textLinks = matchNode(xpathNext);
			//alert(textLinks.snapshotLength)
			
			if (textLinks.snapshotLength>0) {
				link = textLinks.snapshotItem(0)
				//alert(link)
			
				var prefetchIframe = document.createElement('iframe');
				prefetchIframe.setAttribute('style', 'display: none;');
				prefetchIframe.setAttribute('src', link.href);
				document.body.appendChild(prefetchIframe);
			
				link.style.border = 'solid 3px yellow';	
				//if (i==alltext.length)
				fetch=true;
			}
			}
			}
					
}

    
window.load=watch_scroll();
