﻿$(function() {
  var scrtime;
  /*定时刷新新的数据*/
  $("div.now").hover(function() {
    clearInterval(scrtime);
  }, function() {
    scrtime = setInterval(function() {
      var $ul = $("div.now ul");
      var liHeight = $ul.find("li:last").height();
      if ($.browser.msie && ($.browser.version == "6.0") && !$.support.style) {
        $ul.animate({
          marginTop : liHeight + 13 + "px"
        }, 600, function() {
          $ul.find("li:last").prependTo($ul);
          $ul.find("li").eq(4).remove();
          $ul.find("li:first").hide();
          $ul.css({
            marginTop : 0
          });
          $ul.find("li:first").fadeIn("slow");
          $ul.find("li").eq(3).children("a").addClass("bordernone").end().siblings().children("a").removeClass("bordernone");
        });
      } else {
        $ul.animate({
          marginTop : liHeight + 20 + "px"
        }, 600, function() {
          $ul.find("li:last").prependTo($ul);
          $ul.find("li").eq(4).remove();
          $ul.find("li:first").hide();
          $ul.css({
            marginTop : 0
          });
          $ul.find("li:first").fadeIn("slow");
          $ul.find("li").eq(3).children("a").addClass("bordernone").end().siblings().children("a").removeClass("bordernone");
        });
      }
    }, 2000);
  }).trigger("mouseleave");
});

var jsSendData = function(jsId, path){
    var js = window.document.createElement("script");
    js.id = jsId;
    js.setAttribute("type", "text/javascript");
    js.setAttribute("src", path);
    
    var obj = document.getElementById(jsId);
    var nextObj =  obj.nextSibling;
    nextObj.parentNode.removeChild(obj);
    nextObj.parentNode.insertBefore(js, nextObj);
}

function getJsonData() {
  var url = "indexData.aspx";
  $.getJSON(url, function(data) {  });
}

function downItem(name, url, image, time)
{
    var obj = new Object();
    obj.toNode = function(){
    //<li><a href="#" title="标题">
    //<img src="/android/new/game/90/1490/icon.png" />
    //<span>#:bv(number):#秒前<strong>愤怒的小鸟愤怒的小鸟愤怒的小鸟vv愤怒的小鸟愤怒的小鸟愤怒的小鸟v</strong></span>
    //</a>
    //</li>
        var li = window.document.createElement("li");
        
        var link = window.document.createElement("a");
        link.href = url;
        link.title = name;
            var imgview = window.document.createElement("img");
            imgview.src = image;
        link.appendChild(imgview, null);
        
        var nameSpan =  window.document.createElement("span");
        nameSpan.appendChild(window.document.createTextNode(time + "前"), null);
            var nameStrong =  window.document.createElement("strong");
            nameStrong.appendChild(window.document.createTextNode(name), null);
        nameSpan.appendChild(nameStrong, null);
        link.appendChild(nameSpan, null);
        
        li.appendChild(link, null);
        
        return li;
    }
    return obj;
}

var nowDownList = {
    show:function(dataList)
    {
        var view = window.document.getElementById("oNowDownList");
        this.removeLine(view);
        
        var list = window.document.createDocumentFragment();
        for(var x=0; x<dataList.length; x++)
        {
            list.appendChild(dataList[x].toNode(), null);
        }
        view.appendChild(list, null);
    },
    removeLine:function(startObj){
        var obj = startObj.firstChild;
        while(obj != null)
        {
            var nextObj = obj.nextSibling;
            obj.parentNode.removeChild(obj);
            obj  = nextObj;
        }
    }
}
