/*
created by alexander shurkayev <alshur@narod.ru> | http://htmlcoder.visions.ru
modified by ilya lebedev (ilya@lebedev.net)

!!! requires DOMextensions.js !!!
*/

 /**
 *  Script is used to show rollover and active state of the images
 *
 *  To enable rollover for certain image you should
 *  - put it into the 'img_path/img_menu_dir' folder
 *  - put 2 additinal images with the same name and a_img_suffix and r_img_fuffix (ex: a.gif, a_.gif, a__.gif)
 **/

window.onerror = null;

rollmenu = {
  attr_name    : "id",        // name of the attribute, which contains regex that matches desired URIs
  regs         : {            // place to put the regs due to attribute contents restrictions (only alphanumeric symbols allowed)
                  m1_home:"forgotpass|^/$",
                  m1_member:"member|login"
                 },
  img_path     : "/images/",  // path to the images from the site root
  img_menu_dir : "menu",      // folder with the images (should contain no slashes!)
  img_ext      : ".jpg",      // default extension. all images should have the same extension
  r_img_suffix : "__",        // rollover image suffix (ex. "/i/kak/1__.jpg")
  a_img_suffix : "_",         // active image suffix (ex. "/i/kak/1_.jpg")
  rexp         : "",          // regex for default image
  r_rexp       : "",          // regex for rollover image
  oninit       : "",          // user function to call on init
  preload : function (file) {
    var image = new Image();
    image.src = rollmenu.img_path + rollmenu.img_menu_dir + "/" + file + rollmenu.img_ext;
  },
  s : function (e) {
    var el = window.event ? window.event.srcElement : e.currentTarget;
    el.src = el.rollsrc;
  },
  h : function (e){
    var el = window.event ? window.event.srcElement : e.currentTarget;
    if (!el.stopOut) el.src = el.defsrc;
  },
  init : function (){
    if (document.images){
      if (rollmenu.oninit) rollmenu.oninit();
      rollmenu.rexp   = new RegExp (rollmenu.img_ext + "$","");
      rollmenu.r_rexp = new RegExp (rollmenu.r_img_suffix + rollmenu.img_ext + "$","");
      var img_item = img_item_src = r = null;
      var str = rollmenu.img_menu_dir + "\\/(\\w+)\\" + rollmenu.img_ext;
      var re = new RegExp(str, "i");
      for (var i = 0; (img_item = document.getElementsByTagName("img").item(i)); i++){
		r = img_item.src.match(re);
        if (!r) continue; // !!!
        var l = String(img_item.getAttribute(rollmenu.attr_name));
        if (rollmenu.regs[l]) l=rollmenu.regs[l];
        if (""!=l && document.location.pathname.match(new RegExp(l, "i"))) {
          img_item.src = img_item.src.replace(new RegExp(rollmenu.img_ext),rollmenu.a_img_suffix+rollmenu.img_ext);
        } else {
          rollmenu.preload(r[1] + rollmenu.a_img_suffix);
          rollmenu.preload(r[1] + rollmenu.r_img_suffix);
          img_item.rollsrc = img_item.src.replace(rollmenu.rexp,rollmenu.r_img_suffix+rollmenu.img_ext);
		  img_item.actsrc = img_item.src.replace(rollmenu.rexp,rollmenu.a_img_suffix+rollmenu.img_ext); // Added by Vic
          img_item.defsrc = img_item.src;
          img_item.attachEvent("onmouseover",rollmenu.s);
          img_item.attachEvent("onmouseout",rollmenu.h);
          if (img_item.stopOut) img_item.src = img_item.rollsrc;
        }
      }
	  /* Added by Vic 
	  Initialising tab menu's 
	  Howewer they better be initialized on demand when tabs are really used ... !!!!!
	  */

	  packages_menu=new tab_menu('pdiv_', 'pimg_', 'pack_menu');
	  packages_menu.init(function(e) {packages_menu.c(e);});
	  reports_menu=new tab_menu('div_', 'tab_', 'tabmenu') 
	  reports_menu.init(function(e) {reports_menu.c(e);}); 
	
	/* End of addition */
	}
  }
}

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

