function mycarousel_initCallback(carousel, state)
{
    // Lock until all items are loaded. That prevents jCarousel from
    // setup correctly and we have to do that in the ajax callback
    // function with carousel.setup().
    // We're doing that because we don't know the exact height of each
    // items until they are added to the list.base_url+
    carousel.lock();

    jQuery.get(
        'controller/featuredjobs.php',
        {
            'feed': 'http://www.axishcl.com/rss/featuredjobs.php'
        },
        function(xml) {
            mycarousel_itemAddCallback(carousel, xml);
        },
        'xml'
    );
	
	 // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });

};

function mycarousel_itemAddCallback(carousel, xml)
{
    var $items = jQuery('item', xml);

    $items.each(function(i) {
        carousel.add(i + 1, mycarousel_getItemHTML(this));
    });

    carousel.size($items.size());

    // Unlock and setup.
    carousel.unlock();
    carousel.setup();
};

/**
 * Item html creation helper.
 */
function mycarousel_getItemHTML(item)
{
    return '<a href="'+$('link', item).text()+'" title="'+$('title', item).text()+'" >'+mycarousel_truncate($('title', item).text(), 34)+'</a><small>'+mycarousel_truncate($('description', item).text(), 90)+'</small>';
};

/**
 * Utility function for truncating a string without breaking words.Executive Assistant to CEO/Public 
 */
function mycarousel_truncate(str, length, suffix) {
    if (str.length <= length) {
        return str;
    }

    if (suffix == undefined) {
        suffix = '...';
    }

    return str.substr(0, length).replace(/\s+?(\S+)?$/g, '') + suffix;
};

jQuery(document).ready(function() {
    /**
     * We show a simple loading indicator
     * using the jQuery ajax events
     */
    jQuery().ajaxStart(function() {
        jQuery(".jcarousel-clip-vertical").addClass('loading');
    });

    jQuery().ajaxStop(function() {
        jQuery(".jcarousel-clip-vertical").removeClass('loading');
    });

    jQuery('#featured-jobs-list','#f-jobs').jcarousel({
		auto: 1,
        vertical: true,
        size: 10,
		scroll: 1,
		animation: 3000,
		visible: 4,
		wrap: 'first',
        initCallback: mycarousel_initCallback
    });
});
