// ***************************************************************************
// Copyright 2007 - 2008 Tavs Dokkedahl
// Contact: http://www.jslab.dk/contact.php
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//              
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
// ***************************************************************************

/*********************************************
*
*   Safari Search v. 1.0
*   More info at http://www.jslab.dk/scripts.safari.search.php
*
**********************************************/
if(!window.JSL)JSL={};JSL.SHOW_ON_LOAD=false;JSL.ROOT='document.documentElement.childNodes[1]';JSL.IGNORE_TAGS=['script','textarea','input'];JSL.MAX_RESULTS=100;JSL.OVERLAY_COLOR='#000';JSL.OVERLAY_OPACITY=0.35;JSL.Z_INDEX=100;JSL.DELAY=250;/*@cc_on @if (@_jscript_version <= 5.6) JSL.IE6 = true; /*@end @*/JSL.KW='';JSL.KW_RGX=new RegExp(JSL.KW,'im');JSL.bar=null;JSL.matches=[];JSL.nodes=[];HTMLElement.prototype.getPosition=function(scroll){var o;if(scroll){o=window.pageXOffset!=undefined?{x:window.pageXOffset,y:window.pageYOffset}:{x:document.documentElement.scrollLeft,y:document.documentElement.scrollTop};}else o={x:0,y:0};var n=this;do{o.x+=n.offsetLeft;o.y+=n.offsetTop;n=n.offsetParent;}while(n)return o;};HTMLElement.prototype.getTextNodes=function(){var a=[];var n=this;var tmp=/^\s*$/;while(n){if(n.v){n.v=false;if(n==this)break;if(n.nextSibling)n=n.nextSibling;else n=n.parentNode;}else{if(n.nodeType==3&&!/^\s*$/.test(n.nodeValue)&&JSL.KW_RGX.test(n.nodeValue)){a.push(n);}if(n.firstChild&&n!=JSL.bar&&!JSL.IGNORE_TAGS.test(n.nodeName)){n.v=true;n=n.firstChild;}else if(n.nextSibling)n=n.nextSibling;else n=n.parentNode;}}return a;};JSL.createToolbar=function(){JSL.bar=document.createElement('div');if(!JSL.IE6)JSL.bar.style.position='fixed';else{JSL.bar.style.position='absolute';window.onscroll=function(){JSL.bar.style.top=document.documentElement.scrollTop+'px';};}JSL.bar.style.minWidth='750px';JSL.bar.style.top=0;JSL.bar.style.width='100%';JSL.bar.style.zIndex=JSL.Z_INDEX+3;JSL.bar.style.fontSize='11px';JSL.bar.style.fontFamily='Tahoma,sans-serif';JSL.bar.style.padding='4px';JSL.bar.style.backgroundColor='#d4d0c8';JSL.bar.style.borderBottom='1px solid #404040';var conLeft=document.createElement('fieldset');conLeft.style.cssFloat='left';conLeft.style.width='90%';conLeft.style.fontSize='11px';conLeft.style.fontFamily='Tahoma,sans-serif';var input=document.createElement('input');input.type='button';input.value='Close';input.title='Close toolbar(Esc)';input.style.fontSize='11px';input.style.marginRight='8px';input.style.verticalAlign='middle';input.onclick=JSL.closeToolbar;conLeft.appendChild(input);conLeft.appendChild(document.createTextNode('Find on this page: '));JSL.bar.kw=document.createElement('input');JSL.bar.kw.style.fontSize='11px';JSL.bar.kw.style.margin='0 4px';JSL.bar.kw.style.verticalAlign='middle';JSL.bar.kw.onkeyup=JSL.getKW;conLeft.appendChild(JSL.bar.kw);JSL.bar.numResults=document.createElement('span');JSL.bar.numResults.appendChild(document.createTextNode('0 results'));conLeft.appendChild(JSL.bar.numResults);JSL.bar.prev=document.createElement('input');JSL.bar.prev.type='button';JSL.bar.prev.value='\xab';JSL.bar.prev.style.fontSize='11px';JSL.bar.prev.style.margin='0 4px';JSL.bar.prev.style.verticalAlign='middle';JSL.bar.prev.disabled=true;JSL.bar.prev.title='Previous result(Ctrl+Alt+p)';JSL.bar.prev.onclick=function(e){JSL.next(-1);};conLeft.appendChild(JSL.bar.prev);JSL.bar.next=document.createElement('input');JSL.bar.next.type='button';JSL.bar.next.value='\xbb';JSL.bar.next.style.fontSize='11px';JSL.bar.next.style.marginRight='4px';JSL.bar.next.style.verticalAlign='middle';JSL.bar.next.disabled=true;JSL.bar.next.title='Next result(Ctrl+Alt+n)';JSL.bar.next.onclick=function(e){JSL.next(1);};conLeft.appendChild(JSL.bar.next);JSL.bar.usecase=document.createElement('input');JSL.bar.usecase.type='checkbox';JSL.bar.usecase.style.marginRight='4px';JSL.bar.usecase.id='case';JSL.bar.usecase.title='Ctrl+Alt+c';JSL.bar.usecase.onclick=JSL.toggleCase;conLeft.appendChild(JSL.bar.usecase);var label=document.createElement('label');label.htmlFor='case';label.title='Toggle case sensitivity(Ctrl+Alt+c)';label.style.marginRight='4px';label.appendChild(document.createTextNode('Case-sensitive'));conLeft.appendChild(label);JSL.bar.rgx=document.createElement('input');JSL.bar.rgx.type='checkbox';JSL.bar.rgx.style.marginRight='4px';JSL.bar.rgx.id='regex';JSL.bar.rgx.title='Ctrl+Alt+r';JSL.bar.rgx.onclick=JSL.toggleRegex;conLeft.appendChild(JSL.bar.rgx);label=document.createElement('label');label.htmlFor='regex';label.title='Toggle regex(Ctrl+Alt+r)';label.appendChild(document.createTextNode('Regular expression'));conLeft.appendChild(label);JSL.bar.appendChild(conLeft);var conRight=document.createElement('div');conRight.style.cssFloat='right';conRight.style.marginRight='0.8em';var img = document.createElement('img');img.alt = 'Created by Tavs Dokkedahl @ JSLab.dk. Click for more info';img.title = 'Created by Tavs Dokkedahl @ JSLab.dk. Click for more info';img.src = 'http://www.jslab.dk/gfx/logo.jpg';img.style.borderTop = img.style.borderLeft = '1px solid #fff';img.style.borderBottom = img.style.borderRight = '1px solid #404040';img.style.cursor = 'pointer';img.onclick = function() {window.open('http://www.jslab.dk/scripts.safari.search.php','','');};conRight.appendChild(img);JSL.bar.appendChild(conRight);var clear=document.createElement('div');clear.style.clear='both';JSL.bar.appendChild(clear);};JSL.createOverlay=function(){JSL.overlay=document.createElement('div');if(JSL.ROOT==document.documentElement.childNodes[1]){JSL.overlay.style.height=JSL.ROOT.offsetHeight+JSL.bar.offsetHeight+'px';}else{JSL.overlay.style.height=JSL.ROOT.offsetHeight+'px';JSL.overlay.style.border='1px solid #000';}JSL.overlay.style.backgroundColor=JSL.OVERLAY_COLOR;JSL.overlay.style.position='absolute';var p=JSL.ROOT.getPosition();JSL.overlay.style.left=p.x+'px';JSL.overlay.style.top=p.y+'px';JSL.overlay.style.opacity=JSL.OVERLAY_OPACITY;JSL.overlay.style.zIndex=JSL.Z_INDEX;};JSL.resizeOverlay=function(e){JSL.overlay.style.width=0;if(JSL.ROOT==document.documentElement.childNodes[1])JSL.overlay.style.width=document.documentElement.scrollWidth+'px';else JSL.overlay.style.width=JSL.ROOT.scrollWidth+'px';};JSL.toggleOverlay=function(show){if(show){JSL.ROOT.insertBefore(JSL.overlay,JSL.ROOT.firstChild);if(JSL.ROOT==document.documentElement.childNodes[1])JSL.overlay.style.width=document.documentElement.scrollWidth+'px';else JSL.overlay.style.width=JSL.ROOT.scrollWidth+'px';window.addEventListener('resize',JSL.resizeOverlay,true);document.addEventListener('keydown',JSL.searchShortcuts,true);document.addEventListener('click',function(e){var p=e.target;while(p){if(p==JSL.bar)return;p=p.parentNode;}JSL.clear();JSL.toggleOverlay(false);document.removeEventListener('click',arguments.callee,true);},true);}else{try{window.removeEventListener('resize',JSL.resizeOverlay,true);document.removeEventListener('keydown',JSL.searchShortcuts,true);JSL.ROOT.removeChild(JSL.overlay);}catch(err){}}};JSL.toggleRegex=function(){if(JSL.bar.rgx.checked){try{JSL.KW_RGX=new RegExp('('+JSL.KW+')','m'+(!JSL.bar.usecase.checked?'i' : ''));}catch(err){try{var x=new RegExp(JSL.KW,'');}catch(err2){JSL.bar.rgx.nextSibling.style.color='#db1b1b';JSL.bar.rgx.nextSibling.firstChild.nodeValue='Regular expression('+err2.message+')';return;}}}else JSL.KW_RGX=new RegExp('('+JSL.KW.replace(/[\^\$\.\*\+\?\=\!\:\|\(\)\[\]\{\}\\\/]/g,function($0){return '\\'+$0;})+')','m'+(!JSL.bar.usecase.checked?'i' : ''));JSL.search();};JSL.toggleCase=function(e){JSL.KW_RGX=new RegExp(JSL.KW_RGX.source,'m'+(!e.target.checked?'i' : ''));JSL.search();};JSL.getKW=function(e){if(e.target.value==JSL.KW)return;JSL.KW=e.target.value;if(JSL.getKW.op)clearTimeout(JSL.getKW.op);JSL.getKW.op=setTimeout(JSL.toggleRegex,JSL.DELAY);};JSL.getKW.op=null;JSL.clear=function(){var a=JSL.matches;var l=a.length;if(l){for(var i=0;i<l;i++)a[i].r.parentNode.replaceChild(a[i].o,a[i].r);JSL.matches=[];JSL.nodes=[];}JSL.bar.next.disabled=true;JSL.bar.prev.disabled=true;};JSL.search=function(){JSL.clear();if(/^\s*$/.test(JSL.KW)){JSL.toggleOverlay(false);return;}JSL.bar.rgx.nextSibling.style.color='#000';JSL.bar.rgx.nextSibling.firstChild.nodeValue='Regular expression';var span,tmp,mNew,mL;var n=JSL.ROOT.getTextNodes();var l=n.length;var m=0;var rgx=new RegExp(JSL.KW_RGX.source,'gm'+(JSL.KW_RGX.ignoreCase?'i' : ''));for(var i=0;i<l;i++){if(document.createEventObject&&n[i].parentNode.nodeName.toLowerCase()=='pre'){var checkPRE=true;n[i].nodeValue=n[i].nodeValue.replace(/\r/gm,'\x07');}span=document.createElement('span');span.innerHTML=n[i].nodeValue.replace(rgx,'<span style="border: 1px solid #000;padding: 2px;background: #fff;color: #000;position: relative;margin:-2px;z-index: '+(JSL.Z_INDEX+1)+';">$1</span>');if(checkPRE){for(var j=0;j<span.childNodes.length;j++){if(span.childNodes[j].nodeType==3)span.childNodes[j].nodeValue=span.childNodes[j].nodeValue.replace(/\x07/gm,'\r');}}mNew=span.getElementsByTagName('span');mL=mNew.length;var j=0;while(j<mL&&m<JSL.MAX_RESULTS){if(checkPRE){mNew[j].firstChild.nodeValue=mNew[j].firstChild.nodeValue.replace(/\x07/gm,'\r');}JSL.nodes.push(mNew[j]);j++;m++;}if(checkPRE){n[i].nodeValue=n[i].nodeValue.replace(/\x07/gm,'\r');checkPRE=false;}while(mL>j){span.removeChild(mNew[mL-1]);mL--;}tmp={r:span};tmp.o=n[i].parentNode.replaceChild(span,n[i]);JSL.matches.push(tmp);if(m==JSL.MAX_RESULTS)break;}if(m>=JSL.MAX_RESULTS)JSL.bar.numResults.firstChild.nodeValue=JSL.MAX_RESULTS+' or more results';else JSL.bar.numResults.firstChild.nodeValue=m+' result'+(m!=1?'s' : '');if(m){if(!JSL.overlay)JSL.createOverlay();JSL.toggleOverlay(true);}if(m<2){JSL.bar.next.disabled=true;JSL.bar.prev.disabled=true;}else{JSL.bar.next.disabled=false;JSL.bar.prev.disabled=false;}if(m){JSL.nodes.index=JSL.nodes.length-1;JSL.next(1);}else JSL.toggleOverlay(false);};JSL.next=function(d){JSL.nodes[JSL.nodes.index].style.zIndex=JSL.Z_INDEX+1;JSL.nodes[JSL.nodes.index].style.background='#fff';JSL.nodes[JSL.nodes.index].style.padding='2px';if(JSL.nodes.index+d<0)JSL.nodes.index=JSL.nodes.length-1;else if(JSL.nodes.index+d==JSL.nodes.length)JSL.nodes.index=0;else JSL.nodes.index+=d;JSL.nodes[JSL.nodes.index].style.zIndex=JSL.Z_INDEX+2;JSL.nodes[JSL.nodes.index].style.background='#ff0';JSL.nodes[JSL.nodes.index].style.padding='4px 2px';JSL.scrollToCurrent();JSL.animateCurrent();};JSL.animateCurrent=function(){var o=JSL.nodes[JSL.nodes.index];var c=o.cloneNode(true);var p=o.getPosition();o.style.visibility='hidden';c.style.position='absolute';c.style.left=p.x+1+'px';c.style.top=p.y+4+'px';c.style.background='#ff0';c.style.zIndex=JSL.Z_INDEX+4;document.body.appendChild(c);var dir=1;var op=setInterval(function(){var fs=parseFloat(c.style.fontSize)||1.01;if(dir==1)fs+=0.1;else fs-=0.1;if(fs>1.5)dir=-1;if(fs<=1){c.style.fontSize='';clearInterval(op);document.body.removeChild(c);o.style.visibility='visible';}c.style.fontSize=fs+'em';},20);};JSL.scrollToCurrent=function(){var p=JSL.nodes[JSL.nodes.index].getPosition();window.scrollTo(p.x-100,p.y-100);};JSL.shortcuts=function(e){if(e.keyCode==27)JSL.closeToolbar();else if(e.ctrlKey&&e.altKey&&e.keyCode==67){if(document.createEventObject)JSL.bar.usecase.click();else{var evt=document.createEvent('MouseEvent');evt.initMouseEvent('click',true,true,window,1,0,0,0,0,0,false,false,false,0,null);JSL.bar.usecase.dispatchEvent(evt);}}else if(e.ctrlKey&&e.altKey&&e.keyCode==82){if(document.createEventObject)JSL.bar.rgx.click();else{var evt=document.createEvent('MouseEvent');evt.initMouseEvent('click',true,true,window,1,0,0,0,0,0,false,false,false,0,null);JSL.bar.rgx.dispatchEvent(evt);}}};JSL.searchShortcuts=function(e){if(e.ctrlKey&&e.altKey&&e.keyCode==78)JSL.next(1);else if(e.ctrlKey&&e.altKey&&e.keyCode==80)JSL.next(-1);};JSL.openToolbar=function(){var body=document.documentElement.childNodes[1];body.insertBefore(JSL.bar,body.firstChild);body.style.marginTop=JSL.bar.offsetHeight+'px';document.addEventListener('keydown',JSL.shortcuts,true);JSL.bar.kw.focus();};JSL.closeToolbar=function(){JSL.clear();JSL.toggleOverlay(false);var body=document.documentElement.childNodes[1];body.removeChild(JSL.bar);body.style.marginTop=0;document.removeEventListener('keydown',JSL.shortcuts,true);document.addEventListener('keydown',function(e){if(e.ctrlKey&&e.altKey&&e.keyCode==70){e.preventDefault();JSL.openToolbar();document.removeEventListener('keydown',arguments.callee,true);}},true);};JSL.main=function(){JSL.ROOT=eval(JSL.ROOT);if(!JSL.MAX_RESULTS)JSL.MAX_RESULTS=Number.POSITIVE_INFINITY;JSL.IGNORE_TAGS=new RegExp(JSL.IGNORE_TAGS.join('|'),'i');JSL.createToolbar();if(JSL.SHOW_ON_LOAD)JSL.openToolbar();else{document.addEventListener('keydown',function(e){if(e.ctrlKey&&e.altKey&&e.keyCode==70){e.preventDefault();JSL.openToolbar();document.removeEventListener('keydown',arguments.callee,true);}},true);}};window.addEventListener('load',JSL.main,false);

