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.getJSON("#", 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.data;
	
    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(item)
{
    return '<table class="itemLink"><tr><td><a href="#"><img src="index-Dateien/blind.gif" alt="" /></a></td></tr></table>' + 
			'<p class="title">' + item.title + '</p>' + 
			'<p>Gesamtflaeche : ' + item.square + ' m&#178;</p>' +
			'<p>' + (item.type == "miete" ? "Kaltmiete" : "Kaufpreis") + ' : ' + item.price + ' EUR</p>'
			+'<p>Ort: ' + item.ort + '</p>';
};

var scroll_timer, carousel_g;
function mycarousel_init(carousel, state) {
	var auto = carousel.options.auto2 == undefined ? 3 : carousel.options.auto2;
	if ("init" == state) {
		carousel_g = carousel;
		$(".jcarousel-next,.jcarousel-prev").bind("mouseout mouseleave", function(){clearTimeout(scroll_timer);});
		$(".jcarousel-next").bind("click mouseover", function(){ mycarousel_next(carousel, auto, 'next'); } );
		$(".jcarousel-prev").bind("click mouseover", function(){ mycarousel_next(carousel, auto, 'prev'); } );
	}
}
function mycarousel_next(carousel, auto, way) {
	if ("next" == way) {
		clearTimeout(scroll_timer); carousel.next(); scroll_timer = setTimeout(function(){ mycarousel_next(carousel, auto, way); }, auto*1000);
	} else {
		clearTimeout(scroll_timer); carousel.prev(); scroll_timer = setTimeout(function(){ mycarousel_next(carousel, auto, way); }, auto*1000);
	}
}
