function videocarousel_itemLoadCallback(carousel, state)
{
    // Since we get all URLs in one file, we simply add all items
    // at once and set the size accordingly.
	
    if (state != 'init')
        return;
	 $.ajax({
    type: "GET",
    url: "data/videos.xml",
	contentType:"application/xml;charset=utf-8",
    dataType: "xml",
    success: function(data){videocarousel_itemAddCallback(carousel, carousel.first, carousel.last, data);}
  });
    //jQuery.get('dynamic_ajax.txt', function(data) {
       // videocarousel_itemAddCallback(carousel, carousel.first, carousel.last, data);
    //});
};
function videocarousel_itemAddCallback(carousel, first, last, data)
{
    // Simply add all items at once and set the size accordingly.
    //var items = data.split('|');
	var items = new Array();
	
  $(data).find("show").each(function()
  {
	var pItems = new Array();	
	pItems[0] = $(this).find("name").text();
	pItems[1] = $(this).find("image").text();
	pItems[2] = $(this).find("videoid").text();
	pItems[3] = $(this).find("desc").text();
	items.push(pItems);

  });

    for (i = 0; i < items.length; i++) {
        carousel.add(i+1, videocarousel_getItemHTML(items[i]));
    }

    carousel.size(items.length);
};

/**
 * Item html creation helper.
 */
function videocarousel_getItemHTML(item)
{
 var str = '<a href="#" onClick="javascript:ChangeVideo(\''+ item[2] +'\');"><table width="155" border="0" cellspacing="0" cellpadding="0" class="videoTd"><tr>' +
		   '<td width="39" height="37" align="left" valign="middle" style="padding-left:9px;"><img src="'+ item[1] +'" width="30" height="30" border="0" /></td>'+
           '<td width="116" height="37" align="left" valign="middle"><span>' + item[0]  + '</span><br />'+
            item[3] +'</td></tr></table></a>';
    return str;
};

jQuery(document).ready(function() {
    jQuery('#videocarousel').jcarousel({
		 visible: 3,scroll:3,
        itemLoadCallback: videocarousel_itemLoadCallback
    });
 $("#youVideo").append(getItemHTML('VAGX99Mr_I8'));
});
function getItemHTML(id)
{
 var str = '<object width="405" height="324"><param name="movie" value="http://www.youtube.com/v/'+id +'&hl=en_US&fs=1&rel=0"></param>' +
		   '<param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param>'+
           '<embed src="http://www.youtube.com/v/'+ id +'&hl=en_US&fs=1&rel=0" type="application/x-shockwave-flash" '+
           'allowscriptaccess="always" allowfullscreen="true" width="405" height="324"></embed></object>';
    return str;
};
function ChangeVideo(id)
{	
	var divID = document.getElementById("youVideo");
	divID.innerHTML = getItemHTML(id);	
}