var w = proja_width;
var h = proja_height;
if( w == 180 ){
    var v_w = proja_vheight;
    var v_h = proja_vwidth;
} else{
    var v_w = proja_vwidth;
    var v_h = proja_vheight;
}
var css_link = 'http://cdn.main.nuffnang.com.my/sites/projectalpha/s2/widget/widget.css?' + proja_version;

var proja_div_id = 'PAwidget' + w + 'x' + h;
var btn_link = 'http://cdn.main.nuffnang.com.my/sites/projectalpha/s2/widget/img/' + w + 'x' + h + '_btn.png';
var widget_link = 'http://www.projectalpha.com.my/video-widget/';
var proja_link = 'http://www.projectalpha.com.my';

var feed_url = 'http://gdata.youtube.com/feeds/api/playlists/CC4AFC13C2792BEA?format=1&alt=json-in-script&max-results=1&orderby=position&callback=showVideo';

//create a JavaScript element that returns our JSON data.
document.write( '<link rel="stylesheet" href="' + css_link + '" type="text/css" media="screen" />');
document.write(
            '<div align="center">'
            + ' <div id="' + proja_div_id + '">Loading...'
            + ' </div>'
            + ' <div id="PAgetwidget">'
            + '  <div><a href="' + widget_link + '" target="_blank"><img src="' + btn_link + '" border="0"/></a></div>'
            + ' </div>'
            + '</div>');
var script = document.createElement('script');
script.setAttribute('id', 'jsonScript');
script.setAttribute('type', 'text/javascript');
script.setAttribute('src', feed_url );
//attach script to current page -  this will submit asynchronous
//search request, and when the results come back callback
//function showMyVideos(data) is called and the results passed to it
document.documentElement.firstChild.appendChild(script);

function showVideo(data){
    var feed = data.feed;
    var entries = feed.entry || [];
    var entry = entries[0];
    var youtube_id = entry.media$group.media$content[0].url;
    var youtube_link = youtube_id + '&hl=en_US&amp;fs=1';
    var html= '  <object type="application/x-shockwave-flash" data="' + youtube_link + '" width="' + v_w + '" height="' + v_h + '">'
            + '   <param name="movie" value="' + youtube_link + '" />'
            + '   <param name="allowFullScreen" value="true" />'
            + '   <param name="allowscriptaccess" value="always" />'
            + '  </object>'
            + '  <div id="PA-widget-txt"><a href="' + proja_link + '" target="_blank">Visit the Project Alpha website for more videos</a></div>';
     
   document.getElementById(proja_div_id).innerHTML = html;
}/*
document.write( '<link rel="stylesheet" href="' + css_link + '" type="text/css" media="screen" />');
document.write(
            '<div align="center">'
            + ' <div id="PAwidget' + w + 'x' + h + '">'
            + '  <object type="application/x-shockwave-flash" data="' + youtube_link + '" width="' + v_w + '" height="' + v_h + '">'
            + '   <param name="movie" value="' + youtube_link + '" />'
            + '   <param name="allowFullScreen" value="true" />'
            + '   <param name="allowscriptaccess" value="always" />'
            + '  </object>'
            + '  <div id="PA-widget-txt"><a href="' + proja_link + '" target="_blank">Visit the Project Alpha website for more videos</a></div>'
            + ' </div>'
            + ' <div id="PAgetwidget">'
            + '  <div><a href="' + widget_link + '" target="_blank"><img src="' + btn_link + '" border="0"/></a></div>'
            + ' </div>'
            + '</div>');*/