if('undefined' == typeof(Ethnio)) {
  Ethnio = {};
}

Ethnio.head = function(element) {
  document.getElementsByTagName('head')[0].appendChild(element);
}

Ethnio.load_css = function(file) {
  var link = document.createElement('link');
      link.href = file;
      link.rel  = 'stylesheet';
      link.type = 'text/css';
  Ethnio.head(link);
}

Ethnio.observe = function(element, eventName, handler) {
  if (element.addEventListener) {
    element.addEventListener(eventName, handler, false);
  }
  else {
    element.attachEvent("on" + eventName, handler);
  }
}


  Ethnio.should_display = function() {
    return true;
  }


// Ethnio.base_url = location.protocol + '//192.168.1.107:3000';
Ethnio.base_url = location.protocol + '//ethnio.com';

Ethnio.show = function() {
  if(Ethnio.should_display()) {
    Ethnio.load_css(Ethnio.base_url + "/stylesheets/static/remote_reset.css");

    Ethnio.screener = document.createElement('div');
    Ethnio.screener.setAttribute('id', 'ethnio-screener');
    Ethnio.screener.style.top      = "149px";
    Ethnio.screener.style.left     = "184px";

    var close_button = document.createElement('a');
        close_button.innerHTML = '<img style="border: 0px" alt="close" src="' + Ethnio.base_url + '/images/screener-header.gif" />';
        close_button.href      = "javascript:Ethnio.close()";
    Ethnio.screener.appendChild(close_button);

    var iframe = document.createElement('iframe');
        iframe.id     = 'ethnio-screener-id-' + Math.random(); // browsers suck
        iframe.src    = Ethnio.base_url + '/remotes/70478/edit?';
        iframe.style.border = 0;
        iframe.frameBorder  = 0;
        iframe.setAttribute('allowTransparency', 'true');
        iframe.setAttribute('scrolling', 'no');
    Ethnio.screener.appendChild(iframe);

    document.body.appendChild(Ethnio.screener);

    

  }
}

Ethnio.close = function() {
  document.body.removeChild(Ethnio.screener);
}

Ethnio.observe(window, 'load', function() { Ethnio.show(); });
