function insertSiblingBefore(oldSibling, newSibling) {    oldSibling.parentNode.insertBefore(newSibling, oldSibling);}function getOffset(n) {    switch(Math.round(n*2)/2){        case 0:            return [-75, -110];        case 0.5:            return [-59, -126];        case 1:            return [-59, -110];        case 1.5:            return [-44, -126];        case 2:            return [-44, -110];        case 2.5:            return [-29, -126];        case 3:            return [-29, -110];        case 3.5:            return [-15, -126];        case 4:            return [-15, -110];        case 4.5:            return [0, -126];        case 5:            return [0, -110];    }}function formatnumber(num) {  if (isNaN(num)) { num = 0;}/*    var p = num.toFixed(2).split(".");    return  p[0].split("").reverse().reduce(function(acc, num, i, orig) {        return  num + (i && !(i % 3) ? "," : "") + acc;    }, "") ;//+ "." + p[1]; */	num += '';  x = num.split('.');	x1 = x[0];	x2 = x.length > 1 ? '.' + x[1] : '';	var rgx = /(\d+)(\d{3})/;	while (rgx.test(x1)) {		x1 = x1.replace(rgx, '$1' + ',' + '$2');	}	return x1 + x2;}function jsonCallBack(root, dom) {    var rating = 0;    var ratingCount = 0;    var viewCount = 0;    var strRatingHTML;    try {        rating = root.feed.entry[0].gd$rating.average;        ratingCount  = root.feed.entry[0].gd$rating.numRaters;    } catch(e) {        rating = 0;        ratingCount = -1;    }    try {        viewCount  = root.feed.entry[0].yt$statistics.viewCount;    } catch(e) {        viewCount  = 0;    }    if ( rating >= 0 ) {        rating = Math.round(rating*10)/10;        //-strRatingHTML = '<div><div style="float: left; background: transparent url(\'/images/youtube_rate.png\') no-repeat ' + getOffset(rating)[0] + 'px ' + getOffset(rating)[1] + 'px; width: 75px; height: 16px; margin: 3px 5px;"></div>';        //-strRatingHTML += ' <span style="color:#F00; font-size:12px; float:left; margin-left:20px; font-weight:bold; line-height:2em">&nbsp;</span><span style="color:#999; float:right; padding-right:10px; line-height:2em; text-align:right">เปิดดูแล้ว  '+formatnumber(parseFloat(viewCount))+' ครั้ง</span></div>';        strRatingHTML = '<div><span style="color:#F00; font-size:12px; float:left; margin-left:20px; font-weight:bold; line-height:2em">&nbsp;</span><span style="color:#999; float:right; padding-right:10px; line-height:2em; text-align:right">เปิดดูแล้ว  '+formatnumber(parseFloat(viewCount))+' ครั้ง</span></div>';    } else {        strRatingHTML = "unable to find rating";    }    //alert(dom, strRatingHTML);    $("#"+dom).html(strRatingHTML);}function youtube_rating(vid, dom) { //mAFpxEi4Rqg    $("#ajax-youtube-rate").html('<div><div style="float: left; background: transparent url(\'/images/youtube_rate.png\') no-repeat -75px -110px; width: 75px; height: 16px; margin: 3px 5px;"></div> <span style="color:#F00; font-size:12px; float:left; margin-left:20px; font-weight:bold; line-height:2em">&nbsp;</span><span style="color:#999; float:right; padding-right:10px; line-height:2em; text-align:right">เปิดดูแล้ว  0 ครั้ง</span></div>');    $.getJSON('http://gdata.youtube.com/feeds/api/videos?v=2&max-results=1&safeSearch=none&q='+vid+'&alt=json', function(data) {        jsonCallBack(data, dom);    });    //alert("strRatingHTML");}
