if( (!window.opera) && (location.href.indexOf("edit") == -1))
    window.onload=function() {injectLinks();};

function injectLinks() {

    var replacements, regex, key, textnodes, node, s;

    replacements = {
        "FS#([0-9]+)": "<a class='autolink' href='http://www.matse.org.uk/flyspray/index.php?do=details&task_id=$1'>FS#$1</a>",
        "REV#([0-9]+)": "<a class='autolink' href='http://viewvc.matse.org.uk/viewvc?view=rev&revision=$1'>REV#$1</a>",
        "(href=\"/content/page/patterns/op/pattern/patternid)/([0-9]+)\"": "$1/$2\" "+
        "onMouseover=\"showimgtip('/binary/icon/'+$2)\"; onMouseout=\"hideimgtip()\"",
        "(href=\"/content/page/people/op/person/peopleid)/([0-9]+)\"": "$1/$2\" "+
        "onMouseover=\"showimgtip('/binary/photo/'+$2)\"; onMouseout=\"hideimgtip()\"",
        "(href=\".*&amp;area=users&amp;[user_]*id)=([0-9]+)\"": "$1=$2\" "+
        "onMouseover=\"showimgtip('/binary/photo/'+$2)\"; onMouseout=\"hideimgtip()\""
        };
    regex = {};
    for (key in replacements) {
        regex[key] = new RegExp(key, 'g');
    }

//    node = document.getElementById("Content");

    node = document.body;
    if(node!=null) {
        s = node.innerHTML;
        for (key in replacements) {
    	    s = s.replace(regex[key], replacements[key]);
        }

        node.innerHTML = s;

    }

    // for imgtip
    tipon=false;
    tipobj = document.createElement('img');
    tipobj.setAttribute('id', 'imgtip');
//    tipobj.setAttribute('onload', 'if(tipon) this.style.visibility="visible";');
    node.appendChild(tipobj);
    document.onmousemove=positiontip
}

// --- imgtip ---
var imgtipx=-90;
var imgtipy=10;
var ie=document.all
var ns6=document.getElementById && !document.all
var timeout=null;

function ietruebody(){
    return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function showimgtip(url){
    tipobj.src=url;
    tipon=true

    if(timeout!=null) { clearTimeout(timeout);timeout==null; }
    timeout=setTimeout("if(tipon) tipobj.style.visibility='visible'",1000);
}

function positiontip(e){
    if (tipon){
        var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
        var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;

        var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-imgtipx : window.innerWidth-e.clientX-imgtipx-20
        var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-imgtipy : window.innerHeight-e.clientY-imgtipy-20

        var leftedge=(imgtipx<0)? imgtipx*(-1) : -1000

        if (rightedge<tipobj.offsetWidth)
            tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px"
        else if (curX<leftedge)
            tipobj.style.left="5px"
        else
            tipobj.style.left=curX+imgtipx+"px"

        if (bottomedge<tipobj.offsetHeight)
            tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-imgtipy+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-imgtipy+"px"
        else
            tipobj.style.top=curY+imgtipy+"px"
    }
}

function hideimgtip(){
        tipon=false
        if(timeout!=null) { clearTimeout(timeout);timeout==null; }
        tipobj.style.visibility="hidden"
}

