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();
    });
    
};

function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt)
{
    // The index() method calculates the index from a
    // given index who is out of the actual item range.
    
	var idx = carousel.index(i, mycarousel_itemList.length-1);	
    carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[idx - 1]));
};

function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt)
{
    carousel.remove(i);
};

/**
 * Item html creation helper.
 */
function mycarousel_getItemHTML(item)
{
	var tag = '<a href="view_listing_details.php?listing_id=' + item.id + '">';
    var tag = tag + '<img src="' + item.url + '" width="130" height="98" alt="' + item.ititle + '" > </a>';
    var tag = tag + '<center>' + item.tooltip + '</center>';
    return tag;
};



jQuery(document).ready(function() {
    jQuery('#hotProperty').jcarousel({
        auto: 6,
        wrap: 'last',
        initCallback: mycarousel_initCallback,
        itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback},
        itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback}
    });
    
    jQuery('#openHouse').jcarousel({
        auto: 7,
        wrap: 'last',
        initCallback: mycarousel_initCallback,
        itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback_1},
        itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback_1}
    });
})

function mycarousel_itemVisibleInCallback_1(carousel, item, i, state, evt)
{
    // The index() method calculates the index from a
    // given index who is out of the actual item range.
    
	var idx = carousel.index(i, mycarousel_openHouseList.length-1);
    carousel.add(i, mycarousel_getItemHTML_1(mycarousel_openHouseList[idx - 1]));
};

function mycarousel_itemVisibleOutCallback_1(carousel, item, i, state, evt)
{
    carousel.remove(i);
};

/**
 * Item html creation helper.
 */
function mycarousel_getItemHTML_1(item)
{
	var tag = '<a href="view_listing_details.php?listing_id=' + item.id + '">';
    var tag = tag + '<img src="' + item.url + '" width="130" height="98" alt="' + item.ititle + '" > </a>';
    var tag = tag + '<center>' + item.tooltip + '</center>';
    return tag;
};;