//onload
document.observe("dom:loaded", function() {
  nfq_onload();
});

function nfq_onload(){
  
  // swap contents
  var nfq_replace = $('nfq_replace');
  if ( null != nfq_replace){
    var nfq_replace_links = $$( 'a.nfq_replace_link');
    for (var i = 0; i < nfq_replace_links.length; ++i){
      nfq_replace_links[i].observe('click', function(event){
        Event.stop(event);
        nfq_replace.update( '<div style="margin: 10px 0 10px 0; text-align: center;"><img src="http://www.nfq-module.de/out/basic/img/loader.gif" alt="Loading" width="16" height="16" /></div>');
        
        var link = this.href;
        link = link.replace(/#more/, "");
        if ( -1 == link.indexOf('?')){
          link = link + '?popup2=1';
        }
        else{
          link = link + '&popup2=1';
        }
        
        if ( link){
          new Ajax.Request( link, {
            method:'get',
            onSuccess: function( transport){
              nfq_replace.update( transport.responseText);
            },
            onFailure: function(){ 
              nfq_replace.update( 'Error'); 
            }
          });
        }
        
        var nfq_replace_links2 = $$( 'a.nfq_replace_link');
        for (var j = 0; j < nfq_replace_links2.length; ++j){
          var other = Element.extend( nfq_replace_links2[j].parentNode);
          
		  if ( other.hasClassName('nfq_active')){
            other.removeClassName('nfq_active');
            other.addClassName('nfq_inactive');
          }
		}
		var parentel = Element.extend( this.parentNode);
		parentel.addClassName('nfq_active');
		parentel.removeClassName('nfq_inactive');
      });
    }
  }

}
