(function(){
  var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
  this.FXClass = function(){};
  FXClass.extend = function(prop) {
    var _super = this.prototype;
    initializing = true;
    var prototype = new this();
    initializing = false;
    for (var name in prop) {
      prototype[name] = typeof prop[name] == "function" &&
        typeof _super[name] == "function" && fnTest.test(prop[name]) ?
        (function(name, fn){
          return function() {
            var tmp = this._super;
            this._super = _super[name];
            var ret = fn.apply(this, arguments);       
            this._super = tmp;
            return ret;
          };
        })(name, prop[name]) :
        prop[name];
    }
    function FXClass() {
      if (!initializing && this.init)
        this.init.apply(this, arguments);
    }
    FXClass.prototype = prototype;
    FXClass.constructor = FXClass;
    FXClass.extend = arguments.callee;
    return FXClass;
  };
})();

var Flixn = FXClass.extend({

  init: function() {}

});

var FlixnIframe = Flixn.extend({

  iframeId: 'flixnwc_iframe',

  containerWidth: '100%',
  containerHeight: '662px',
  containerPadding: '10px',
  containerBorder: 'solid 1px #ccc',

  f_location: null,
  prefixUrl: 'http://cisco.flixn.com/widgets/comment/16/index.php',

  init: function() {},
  
  showIframe: function(ident, group, cont, uri) {
    this._buildIframe(ident, group, cont, uri);
  },

  _buildIframe: function(ident, group, cont, uri) {
    var container = document.getElementById(cont);
    
/*    container.style.width = this.containerWidth; */
    container.style.height = this.containerHeight;
    container.style.padding = '10px';
    container.style.border = this.containerBorder;
    container.style.zIndex = 99;
    container.style.position = 'relative';

/* XXX: IE6 */
if (!window.XMLHttpRequest) {
//  container.style.width = (container.offsetWidth - 22) + 'px';
}

    var iframe = document.createElement('iframe');
    iframe.setAttribute('frameBorder', '0');
    iframe.setAttribute('scrolling', 'no');

/*    iframe.style.marginRight = '10px'; */


    iframe.style.marginBottom = '10px';
    iframe.style.width = '100%';
    iframe.style.height = '100%';

/* XXX */
    var iframe_src = this.prefixUrl + '?id=' + ident + '&uri=' + uri + '&group=' + encodeURIComponent(group);

    iframe.src = iframe_src
    container.appendChild(iframe);
  }
  
});
var FlixnIframeInstance = new FlixnIframe();


var FlixnInlineComments = Flixn.extend({

  ident: null,
  group: null,
  elementId: null,
  
  init: function() {},

  setIdent: function(identifier) {
    ident = identifier;
  },
  
  setGroup: function(groupname) {
    group = groupname;
  },
  
  setElementId: function(id) {
    elementId = id;
  },

  checkElement: function(elementId, cl) {
    if (document.getElementById(elementId) != null)
      cl();
    else
      setTimeout(function(){ this.checkElement(elementId, cl) }, 100);
  },
  
  show: function() {
      var f_location = document.location.protocol + '//';
      if (document.location.hostname == 'cisco.com')
          f_location = f_location + 'www.cisco.com';
      else
          f_location = f_location + document.location.hostname;
      f_location = f_location + document.location.pathname;

      this.checkElement(elementId, function(){
          FlixnIframeInstance.showIframe(ident, group, elementId, f_location);  
      });

  }
});