function mycarousel_itemLoadCallback(carousel, state)
{
    // Check if the requested items already exist
    if (carousel.has(carousel.first, carousel.last)) {
        return;
    }

    jQuery.get(
        '/jcarousel/home_galleries_ajax.php',
        {
            first: carousel.first,
            last: carousel.last
        },
        function(xml) {
            mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, xml);
        },
        'xml'
    );
};
function mycarousel_itemLoadCallbackNews(carousel, state)
{
    // Check if the requested items already exist
    if (carousel.has(carousel.first, carousel.last)) {
        return;
    }

    jQuery.get(
        '/jcarousel/home_news_ajax.php',
        {
            first: carousel.first,
            last: carousel.last
        },
        function(xml) {
            mycarousel_itemAddCallbackNews(carousel, carousel.first, carousel.last, xml);
        },
        'xml'
    );
};


function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
		
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

var imagepath;
var link;
var title;

function mycarousel_itemAddCallback(carousel, first, last, xml)
{
    // Set the size of the carousel
    carousel.size(parseInt(jQuery('total', xml).text()));

    jQuery('item', xml).each(function(i) {
    	imagepath = $(this).find("image").text();
    	link = $(this).find("link").text();
    	title = $(this).find("title").text();
        carousel.add(first + i, mycarousel_getItemHTML(imagepath,link,title));
    });

};
function mycarousel_itemAddCallbackNews(carousel, first, last, xml)
{
    // Set the size of the carousel
    carousel.size(parseInt(jQuery('total', xml).text()));

    jQuery('item', xml).each(function(i) {
    	imagepath = $(this).find("image").text();
    	link = $(this).find("link").text();
    	title = $(this).find("title").text();
        carousel.add(first + i, mycarousel_getItemHTMLNews(imagepath,link,title));
    });

};



/**
 * Item html creation helper.
 */
function mycarousel_getItemHTML(tempimagepath,templink,title)
{
    return '<a href=\''+templink+'\'><img src="' + tempimagepath + '" width="255" height="143" style="border:1px solid black ;" border="0" height="143" alt="" /><br>'+title+'</a>';
};
function mycarousel_getItemHTMLNews(tempimagepath,templink,title)
{
    return '<a href=\''+templink+'\'><img src="' + tempimagepath + '" width="255" height="143" style="border:1px solid black ;" border="0"  alt="" /><br>'+title+'</a>';
};



jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({
    auto: 8,
	        wrap: 'last',
			scroll:1,

        // Uncomment the following option if you want items
        // which are outside the visible range to be removed
        // from the DOM.
        // Useful for carousels with MANY items.

        //itemVisibleOutCallback: {onAfterAnimation: function(carousel, item, i, state, evt) { carousel.remove(i); }},
        itemLoadCallback: mycarousel_itemLoadCallback,
        initCallback: mycarousel_initCallback

    });
	
	 jQuery('#mycarouselnews').jcarousel({
    auto: 8,
	        wrap: 'last',
			scroll:1,

        // Uncomment the following option if you want items
        // which are outside the visible range to be removed
        // from the DOM.
        // Useful for carousels with MANY items.

        //itemVisibleOutCallback: {onAfterAnimation: function(carousel, item, i, state, evt) { carousel.remove(i); }},
        itemLoadCallback: mycarousel_itemLoadCallbackNews,
        initCallback: mycarousel_initCallback

    });
	
	 
});