/**
* @author ilya lebedev (ilya@lebedev.net)
*/

 /**
 *  Script is used to remove cyclic (recursive) links.
 *  It leaves link content on it's place
 *
 *  Usage:
 *  1. Include <script type="text/javascript" src="/path_to_file/crefs.js"></script>
 *     it into the page.
 *  2. Set appropriate styles for replace ids like
 *     Ex.: style : [["b","",""], ["u","",""]] sets the replaces for ancors with empty ID
 *     and ID="menu:1"
 **/

window.onerror = null;

crefs = {
  styles : [["u","",""], // replace objects. Tag name, class name, title.
            ["b","",""],
           ],
  init : function (){
    var a = document.getElementsByTagName("a");
    var aL = a.length;
    var dl = document.location.href.replace(/(\/(\?)|()\/$)/,"$2");
    for (var i=aL-1;i>=0;i--) {
      var hr = a[i].toString().replace(/(\/(\?)|\/$())/,"$2");
      if (dl==hr) {// && hr.indexOf('#')<0) {
		var id=String(a[i].getAttribute('id'));
        var idd=id.replace(/menu:/,"");
        if (id.match(/^menu:\d+$/) && crefs.styles[idd][0]) {
          var s = a[i].innerHTML;
          var n = document.createElement(crefs.styles[idd][0]);
          n.setAttribute('className',crefs.styles[idd][1]==""?a[i].getAttribute('className'):crefs.styles[idd][1]);
          n.setAttribute('class',crefs.styles[idd][1]==""?a[i].getAttribute('class'):crefs.styles[idd][1]);
          n.setAttribute('style',a[i].getAttribute('style'));
          n.setAttribute('alt',a[i].getAttribute('alt'));
          n.setAttribute('title',a[i].getAttribute('title'));
          a[i].replaceNode(n);
          n.innerHTML = s;
        } else a[i].removeNode();
      }
    }
  }
}

if (window.attachEvent) window.attachEvent("onload",crefs.init);
else document.attachEvent("onload",crefs.init)

