/****************************************************************
* バイト数を数える
*
* 引数 ： str 文字列
* 戻り値： バイト数 
*
****************************************************************/
function CountLength(str) {
    var r = 0;
    for (var i = 0; i < str.length; i++) {
        var c = str.charCodeAt(i);
        // Shift_JIS: 0x0 ～ 0x80, 0xa0 , 0xa1 ～ 0xdf , 0xfd ～ 0xff
        // Unicode : 0x0 ～ 0x80, 0xf8f0, 0xff61 ～ 0xff9f, 0xf8f1 ～ 0xf8f3
        if ( (c >= 0x0 && c < 0x81) || (c == 0xf8f0) || (c >= 0xff61 && c < 0xffa0) || (c >= 0xf8f1 && c < 0xf8f4)) {
            r += 1;
        } else {
            r += 2;
        }
    }
    return r;
}
$(function() {
var inum = -1;
var URL= '/sitehighlights.xml';
$.ajax({
  url: URL ,
  type: 'GET',
  dataType: 'xml',
  timeout: 10000,
  cache:false,
  error: function(){/*エラーが出た時の処理*/},
  success: function(xml){
  var node=new Array();
    $(xml).find("statuses").each(function(){
      var tagName = new Array();
      tagName.url = $("url",this).text();
      tagName.image = $("image",this).text();
      tagName.text = $("text",this).text();
      var textcnt = CountLength(tagName.text)
      if(textcnt>100){
        tagName.text = tagName.text.slice(0,55);
        tagName.text = tagName.text + '・・・';
      }
      node.push(tagName);
    })
    var num = Math.ceil(node.length/3);
    for (i = 0; i < node.length; i++){
      var jnum = i%3;
      if(jnum == 0){
        inum++;
        
        $('#sitehighlightsList').append('<div><ul></ul></div>')
      }
      $('#sitehighlightsList ul:eq('+inum+')').append('<li><div><a href="'+node[i].url+'"><img src="'+node[i].image+'" width="183" height="88" /></a></div><p class="sitehighlightsCopy txtfont10 txtheight14"><a href="'+node[i].url+'">'+node[i].text+'</a></p></li>');
    }
    if(node.length<=3){
      $(".browse").css("display","none");
    }
    $(".scrollable").scrollable();
  }

})
});

