function mycarousel_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;

    jQuery.get('imgvid.txt', function(data) {
        mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, data);
    });
};

function mycarousel_itemAddCallback(carousel, first, last, data)
{
    // Simply add all items at once and set the size accordingly.
    var items = data.split('|');

    for (i = 0; i < items.length; i++) {
        carousel.add(i+1, mycarousel_getItemHTML(items[i]));
    }

    carousel.size(items.length);
};

/**
 * Item html creation helper.
 */
function mycarousel_getItemHTML(url)
{
    var str = url.split(',');
    
    return '<img src="jcarousel/invvest/images/' + str[0] + '.jpg" width="75" height="75" style="border:0;z-index:0;" alt="" onclick="swapvideo(' + "'" + str[1] + "'" +')" onmouseover="this.style.cursor=\'pointer\'" />';
};

function swapvideo(vidurl)
{
  var divHTML = "<div style=\"margin:2px auto;\"><object style=\"z-index:0;\" width=\"600\" height=\"475\"><param name=\"movie\" value=\"http://www.youtube.com/v/" + vidurl + "&hl=en&fs=1&rel=0&&border=1\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"http://www.youtube.com/v/" + vidurl + "&hl=en&fs=1&rel=0&border=1\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" wmode=\"transparent\" width=\"600\" height=\"475\"></embed></object></div>";
  document.getElementById("invvideo").innerHTML = divHTML;

};

jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({
        itemLoadCallback: mycarousel_itemLoadCallback
    });
});
