HtmlTable = Class.refactor(HtmlTable, {
    options: {
        classEven:  'table-tr-even'
    },

    zebra: function(row, i){
        row[((i % 2) ? 'add' : 'remove')+'Class'](this.options.classEven);
        row[((i % 2) ? 'remove' : 'add')+'Class'](this.options.classZebra);
    }
});

function erfcmsDomready()
{
  $$('table').each(function(table) {
    new HtmlTable(table, { classZebra: 'erfcms_odd', classEven: 'erfcms_even' } );
  });

  $$("ul").filter(function(el) { return el.getAttribute('data-erfcms-menu') }).each(
    function(ul) {
      ul.getElements('li').each(
        function(li) {
          var ul=li.getElement('ul'), r=li.getElement('a').href.replace(/#.*$/,''), s=self.location.href.replace(/#.*$/,'');
          if (ul)
          {
            li.addClass('erfcms_node').removeClass('erfcms_open').getElement('a').addEvent('click',function(e) { this.slide('toggle'); e.stop(); }.bindWithEvent(ul)).setStyle('outline',0);
            ul.get('slide').hide().addEvent('complete',function(e) { if (this.get('slide').open) { this.getParent('li').addClass('erfcms_open'); } else {  this.getParent('li').removeClass('erfcms_open'); } }.bindWithEvent(ul));
          }
          else if (r==s || r==s+'index.php' || li.hasClass('erfcms_current'))
          {
            li.getParents('ul').filter(function(el) { return !el.getAttribute('data-erfcms-menu') }).slide('show').getParent('li').addClass('erfcms_open');
            li.addClass('erfcms_current').getParents('li').addClass('erfcms_current');
          }
        }
      )
    }
  )

  $$("p").filter(function(el) { return el.getAttribute('data-erfcms-alert') }).each(function(el)
  { 
    el.style.display='none';
    alert (el.get('text')); 
  });

  $$("a[rel=external]").addEvent('click',function(e) { if (window.open(this.getAttribute('href'),'_blank')) e.stop(); });

  $$("div").filter(function(el) { return el.getAttribute('data-erfcms-toggleslide') }).each(function(el)
  {
    el.set('slide', { onComplete: function() { el.getElements('input, select, textarea').set('disabled', (this.get('slide').open ? '' : 'disabled')); }.bindWithEvent(el) } );
    el.slide('hide');
    el.getElements('input, select, textarea').set('disabled','disabled');
    eval(el.getAttribute('data-erfcms-toggleslide')).addEvent('click',function(e) { this.slide('toggle'); e.stop(); }.bindWithEvent(el));
  });

  if ($$("a[rel^=lightbox]").length>0)
  {
    new Asset.javascript('/erfmodules/erfcms3/js/plugins/slimbox.js', { 'onload': function(e) { $$("a[rel^=lightbox]").slimbox({},null,function(el) { return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel)); }); } } );
  }

  if ($$("a[rel^=zoom]").length>0)
  {
    new Asset.javascript('/erfmodules/erfcms3/js/plugins/zoom.js');
  }

  if ($$("form").filter(function(el) { return el.getAttribute('data-erfcms-form') }).length>0)
  {
    new Asset.javascript('/erfmodules/erfcms3/js/plugins/form.js');
  }

  if ($$("form").filter(function(el) { return el.getAttribute('data-erfcms-article') }).length>0)
  {
    new Asset.javascript('/erfmodules/erfcms3/js/plugins/article.js');
  }

  if ($$("ul").filter(function(el) { return el.getAttribute('data-erfcms-mooflow') }).setStyle('display','none').length>0)
  {
    new Asset.javascript('/erfmodules/erfcms3/js/plugins/mooflow.js');
  }

  if ($$("a").filter(function(el) { return el.getAttribute('data-erfcms-print') }).length>0)
  {
    new Asset.javascript('/erfmodules/erfcms3/js/plugins/print.js');
  }

  $$("table").filter(function(el) { return el.getAttribute('data-erfcms-sortable') }).each(
    function(table) {
      table.retrieve('HtmlTable').enableSort();
    }
  )

  if (Browser.Engine.trident)
  {
    $$("iframe[seamless=1]").each(function(el) {
      el.clone().set('frameBorder',0).replaces(el);
    });
  }
}

var erfcmsLog = new Log;
document.createElement("abbr");

var erfImooManager,erfMsgQueue=new Array;
window.alert=function(msg) {
  erfMsgQueue.push(msg);
  new Asset.javascript('/erfmodules/erfcms3/js/plugins/notimoo/notimoo.js',{ 'onload': function(e) { 
    if (!erfImooManager)
    {
      erfImooManager = new Notimoo({
        notificationOpacity:1,
        height:80,
        width:320,
        locationVType: 'top',
        locationHType: 'left',
        locationHBase: window.getSize().x/2-160,
        locationVBase: window.getSize().y/2-40
      });
    }
    if (erfMsgQueue.length>0)
    {
      erfImooManager.show({
        message: erfMsgQueue.pop()
      });
    }
  } });
}

function erfcmsLoad()
{
  new Asset.javascript('/erfmodules/erfcms3/js/plugins/awstats.js');
}

window.addEvents( { 'domready': erfcmsDomready, 'load': erfcmsLoad } );

