function PeersHelp(options) {
  if(options){
    this._logo_url = options['logo'];
    this._site_places = options['places'];
    this._css_url = options['css']
  };
  this._peers_places = { 'General' : 'http://free.aboutpeers.com/address/support-en/faq_general','Groups' : 'http://free.aboutpeers.com/address/support-en/faq_groups','Inbox' : 'http://free.aboutpeers.com/address/support-en/faq_inbox','Profile' : 'http://free.aboutpeers.com/address/support-en/faq_profile','Wave' : 'http://free.aboutpeers.com/address/support-en/faq_wave' };
  this._build_help_div();
};

PeersHelp.prototype = {
  _print_options : function() {
    if(window.console) {
      console.log('logo = ',this._logo_url);
      console.log('site places = ',this._site_places);
      console.log('peers places = ',this._peers_places);
      console.log('css = ',this._css_url);
    };
  },
  _button_div : function(name,source){
    var a_elm = $("<a>");
    a_elm.text(name);
    a_elm.attr('href','javascript:void(0)').attr('id',"peers_help_"+name+"_link").addClass('peers_help_place_link');
    var self = this;
    a_elm.click(function(){
      var iframe_source = source+"?&format=iframe";
      if(self._css_url){
        iframe_source += "&css=" + self._css_url;
      };
      var iframe_elm = $("iframe#peers_help_place_iframe");
      iframe_elm.attr('src',iframe_source);
      iframe_elm.get(0).contentWindow.focus();
      return false;
    });
    return a_elm;
  },
  _build_link_divs : function(div_str){
    ul_div = $("<ul>");
    if(this._peers_places) { this._append_place_links(div_str,this._peers_places); };
    if(this._site_places) { this._append_place_links(div_str,this._site_places); };
  },
  _append_place_links : function(div_str,places){
    for(index in places){
      div_str.append(this._button_div(index,places[index]));
    };
  },
  _build_iframe : function(div_str) {
    var iframe_elm = $("<iframe>").attr({
      'id' : 'peers_help_place_iframe',
      'name' : 'peers_help_place_iframe_name',
      'scrolling' : 'auto',
      'frameBorder' : 0,
      'allowtransparency' : true
    });
    iframe_elm.css({
      width : '100%'
    });
    div_str.append(iframe_elm);
  },
  _build_help_div : function() {
    var div_str = $("<div>").attr('id','peers_help_dialog_div');
    if(this._logo_url){ div_str.append($("<img>").attr('src',this._logo_url)); };
    this._build_link_divs(div_str);
    var main_div = $("<div>").attr('id','peers_help_main_dialog_div');
    main_div.append(div_str);
    this._build_iframe(main_div);
    this.dialog = main_div.dialog({
      modal : true,
      height : this._innerHeight()*0.8,
      width : 850,
      resizable : false,
      draggable: true,
      title: "Peers Support"
    });
    this._fix_help_div();
    div_str.find("a:first").trigger('click');
  },
  _fix_help_div : function(){
   $(".ui-dialog").css({
      'position':'fixed'
    });
    $("iframe#peers_help_place_iframe").css( {
      'height' : this._innerHeight()*0.8 - $("div#peers_help_dialog_div").innerHeight() - 65
    });
  },
  _innerHeight : function() {
    if(typeof(window.innerHeight) !== 'undefined') {
      return window.innerHeight;
    } else {
      return document.documentElement.clientHeight;
    }
  },
  _innerWidth : function() {
    if(typeof(window.innerWidth) !== 'undefined') {
      window.innerWidth;
    } else {
      document.documentElement.clientWidth;
    }
  },
  reopen_dialog : function(){
    $("div#peers_help_main_dialog_div").dialog('open');
    this._fix_help_div();
  }
}
