﻿//window.onerror = function() { return true; }
/// <reference path="jquery-1.3.1-vsdoc.js" />
var lazySwitch = null;

//切换热点推荐
function switchCommend(obj, langs) {
    if (lazySwitch != null) clearTimeout(lazySwitch);
    lazySwitch = setTimeout(
    function()
    {
        $("#focus_switch ul li").removeClass("current");
        $(obj).addClass("current");
        $("#focus_main div").hide();
        document.getElementById("focus_" + langs).style.display = "block";
        hidePopMenu();
     },300);
}

//取消热点切换
function cancelSwitch() {
    if (lazySwitch != null)
        clearTimeout(lazySwitch);
}

function getBestIng(xid) {
  $(document).ready(function() {

  var url = "http://bulo.hjenglish.com/service/getbestIng.aspx";
    var moreHref = "http://bulo.hjenglish.com/app/redirect?source=eng2009&type=1&";
          moreHref += "returnurl=http://bulo.hjenglish.com/app/search/ing/%E6%B2%AA%E6%B1%9F";
    var format = "{0}<div id='best_ing_more'><a target='_blank' href='{1}'>上千万沪友眼中的沪江>></a></div>";

    $.getScript(url, function() {
      var text = format.replace(/\{0\}/g, __ing).replace(/\{1\}/g, moreHref);
      $(xid).append(text);
    });

  });
}
function Index() { }
//分享
Index.prototype.shareTo = function(type) {
    _isActive = true;
    var title = document.title.substring(0, document.title.indexOf("_"));
    var url = location.href;
    var articlepage_inbox = document.getElementById("articlepage_inbox");
    //点评
    var summary = $.trim($("#sharebox_summary").text());
    var topicUrl = $.trim($("#sharebox_topicurl").text());

    url = url.indexOf("#") > 0 ? url.toString().substring(0, url.toString().indexOf("#")) : url;
    title = encodeURIComponent(title);
    var shareName = "";
    switch (type) {
        case "renren":                           //人人网
            shareName = "人人";
            window.open('http://share.renren.com/share/buttonshare.do?link=' + url + '&title=' + title);
            break;
        case "kaixin":                          //开心
            shareName = "开心";
            d = document; t = d.selection ? (d.selection.type != 'None' ? d.selection.createRange().text : '') : (d.getSelection ? d.getSelection() : '');
            void (kaixin = window.open('http://www.kaixin001.com/~repaste/repaste.php?&rurl=' + url + '&rtitle=' + title + '&rcontent=' + title, 'kaixin')); kaixin.focus();
            break;
        case "douban":                       //豆瓣
            shareName = "豆瓣";
            window.open('http://www.douban.com/recommend/?url=' + url + '&title=' + title + '');
            break;
        case "xinlangweibo":               //新浪微博
            shareName = "新浪微博";
            var newTitle = '《' + decodeURIComponent(title) + '》（' + url + '）：' + summary + '';
            newTitle = newTitle.cutString(280);
            newTitle = encodeURIComponent(newTitle);
            var features = "height=565, width=603,toolbar= no, menubar=no, scrollbars=no, resizable=yes, location=no, status=no,top=100,left=300";
            window.open('http://v.t.sina.com.cn/share/share.php?appkey=1763324258&content=utf-8&pic=' + topicUrl + '&title=' + newTitle, "share2", features);
            break;
        case "sohu":               //搜狐微博
            shareName = "搜狐微博";
            var newTitle = '《' + decodeURIComponent(title) + '》' + summary + '';
            newTitle = newTitle.cutString(280);
            newTitle = encodeURIComponent(newTitle);
            var features = "height=600, width=650, toolbar= no, menubar=no, scrollbars=no, resizable=yes, location=no, status=no,top=100,left=300";
            window.open('http://t.sohu.com/third/post.jsp?url=' + url + '&content=utf-8&pic=' + topicUrl + '&title=' + newTitle, "share2", features);
            break;
        case "baidu":                          //百度搜藏
            shareName = "百度搜藏";
            window.open('http://cang.baidu.com/do/add?it=' + title + '&iu=' + url + '&dc=&fr=ien#nw=1');
            break;
        case "QQ":                              //QQ
            shareName = "QQ";
            window.open('http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=' + url);
            break;
        case "ruolin":                          //若林
            shareName = "若林"
            window.open("http://share.wealink.com/share/add/?title=" + title + "&content=" + encodeURIComponent("找到了好东西，和大家分享一下，大家都来看看吧。") + "&url=" + url);
            break;
        default:
            shareName = "_error";
            alert("发生错误！请到网站小组反馈错误！");
            break;

            DoRecord(this, "其他_分享到" + shareName);
    }
}

//增加String方法
String.prototype.getByteCount = function() {
    return this.replace(/[^\u0000-\u00ff]/g, "12").length;
}
String.prototype.cutString = function(count) {
    var newstr = this;
    var length = newstr.getByteCount();
    if (length <= count) {
        return newstr;
    }
    while (length > count - 3 && length > 0) {
        newstr = newstr.substring(0, newstr.length - 1);
        length = newstr.getByteCount();
    }
    return newstr + "...";
  }

  //首页菜单浮动层 杨正祎
  var lazyShowMenu = null;
  function showSubMenu(p_obj, p_strTarget) {
      if (lazyShowMenu != null) clearTimeout(lazyShowMenu);

      lazyShowMenu = setTimeout(function () {
          $(".menu_title").css("background", "");
          p_obj.style.background = "transparent  url('/2010/images/bg_menu_h2.gif') no-repeat 0px 0px";
          $("#expand").children().hide();
          $("#" + p_strTarget).show();
          lazyShowMenu = null;
      }, 300);
  }

  function cancelPopMenu() {
      if (lazyShowMenu != null) {
          clearTimeout(lazyShowMenu);
          $("#expand").children().hide();
          $(".menu_title").css("background", "");
      }
  }

  function hidePopMenu(p_obj) {
      if (lazyShowMenu != null) clearTimeout(lazyShowMenu);

      lazyShowMenu = setTimeout(function() {
          $("#expand").children().hide();
          $(".menu_title").css("background", "");
          if (arguments.length > 0) p_obj.style.background = "transparent  url('/2010/images/bg_menu_h2.gif') no-repeat 0px 0px";
      }, 500);
  }
