function mycarousel_itemLoadCallback(carousel, state)
{
    // Check if the requested items already exist
    if (carousel.has(carousel.first, carousel.last)) {
        return;
    }

    jQuery.get(
        '/carousel.php',
        {
            first: carousel.first,
            last: carousel.last
        },
        function(xml) {
            mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, xml);
        },
        'xml'
    );
};

function mycarousel_itemAddCallback(carousel, first, last, xml)
{

    // Set the size of the carousel
    carousel.size(parseInt(jQuery('total', xml).text()));

    jQuery('image', xml).each(function(i) {
        carousel.add(first + i, mycarousel_getItemHTML(jQuery(this).text(),jQuery(this).attr("url")));
    });
};

/**
 * Item html creation helper.
 */
function mycarousel_getItemHTML(imgurl,linkurl)
{
	strReturn ='<a href="' + linkurl + '" ><img src="' + imgurl + '" border="0" width="121" height="121" alt="" /></a>';
    return strReturn;
}

jQuery(document).ready(function() {
if($("#CSSGalleries").length>0)
	{
        $("#CSSGalleries").tablesorter({sortList: [[7,1]]}); 
		$(".t").simpletooltip();
	}
   jQuery('#mycarousel ul').html("");
    jQuery('#mycarousel').jcarousel({ 
    itemLoadCallback: mycarousel_itemLoadCallback,
    scroll:5,
    visible:5    
    });
});

