// ü utf-8 marker for editors
/**
 * @namespace  GHF8_Debug
 */ 
 
/**
 * Javascript helper functions for development
 * 
 * $Id: debug.js 15 2008-09-04 08:35:13Z raber $
 * @license    <a href="http://www.opensource.org/licenses/lgpl-license.php">LGPL</a>
 * @author     (C) 2008 Dieter Raber <me@dieterraber.net>
 * 
 */

// cross browser add event, borrowed from John Resig
var debugAddEvent = function (obj, type, fn) {
  if (obj.addEventListener) {
    obj.addEventListener( type, fn, false );
  }
  else if (obj.attachEvent) {
    obj['e' + type + fn] = fn;
    obj[type + fn] = function(){
      obj['e'+type+fn](window.event);
    }
    obj.attachEvent( 'on'+type, obj[type+fn] );
  }
}

  
var ghf8 = function() {

  // self reference
  var selfRef = this;
  
  // iterator
  var i = 0;
  
  // debugger for downloads
  this.debugDwl = function() {
    this.dwlLinks = document.getElementsByTagName('a');
    var dwl = false;
    for(i = 0; i < this.dwlLinks.length; i++) {
      if(this.dwlLinks[i].className.indexOf('dwl') > -1) {
        dwl = true;
        break;
      }
    }
    if(dwl) { 
      dwl = document.getElementById('dwl'); 
    }
    
    if(dwl == null) {    
      throw new Error('You have links marked as download but an iframe with the id dwl is missing'); 
      return false;
    }
    
    debugAddEvent(dwl, 'load', function() {
      this.doc = this.contentDocument ? this.contentDocument : this.document;
      if(this.doc.body.innerHTML) {
        this.style.width    = '90%';
        this.style.height   = '300px';
        this.style.position = 'static';
        this.style.border   = '1px red solid'; 
        this.style.margin   = 'auto'; 
        this.style.display  = 'block';
      }
    })
  }   
  // fire on load
  this.debugDwl(); 
};

debugAddEvent(window, 'load', function() { new ghf8(); })

