var AddFav = {
  getCookie: function(n) {
    var dc = "; " + document.cookie + "; ";
    var coo = dc.indexOf("; " + n + "=");
    if (coo != -1) {
      var s = dc.substring(coo + n.length + 3, dc.length);
      return unescape(s.substring(0, s.indexOf("; ")));
    } else {
      return null;
    }
  },
  setCookie: function(name, value, expires, path, domain, secure) {
    var expDays = expires * 24 * 60 * 60 * 1000;
    var expDate = new Date();
    expDate.setTime(expDate.getTime() + expDays);
    var expString = expires ? "; expires=" + expDate.toGMTString() : "";
    var pathString = "; path=" + (path || "/");
    var domain = domain ? "; domain=" + domain: "";
    document.cookie = name + "=" + escape(value) + expString + domain + pathString + (secure ? "; secure": "");
  },
  setFav: function(sURL, infos) {
    try {
      window.external.addFavorite(sURL, infos);
    } catch(e) {
      try {
        window.sidebar.addPanel(infos, sURL, "");
      } catch(e) {
        alert("加入收藏失败，请使用Ctrl+D进行添加");
      }
    }
  },
  tmp: '<div class="pop"  id="addFav"><div class="popHead"><p>赶快把<a href="http://www.8090club.com" style="padding:0px;"><b>8090美女俱乐部</b></a>放入收藏夹哦，免费享受每日更新的近万美女图片资源!</p><a class="aLink"onclick="AddFav.collect()"><span>立即收藏</span></a><p style="float:right;"><a onclick="AddFav.hide()">不再显示</a><a onclick="AddFav.close()">关闭</a></p></div></div>',
  _$: function(str) {
    var div = document.createElement("div");
    div.innerHTML = str;
    return div.childNodes[0];
  },
  ini: function() {
    if (!this.getCookie("addFav")) {
      $("body").prepend(this._$(this.tmp));
      this.node = $("#addFav");
      this.node.fadeIn();
    }
  },
  close: function() {
    this.node.fadeOut();
  },
  hide: function() {
    this.setCookie("addFav", "true", 360);
    this.node.fadeOut();

  },
  collect: function() {
    this.setCookie("addFav", "true", 360);
    this.setFav('http://www.8090club.com/?fav', '8090美女俱乐部');
    this.node.fadeOut();

  }
};
$(function(){
  AddFav.ini();
});