//<!--
function mycarousel_initCallback(carousel, state)
{
    carousel.lock();

    jQuery.get(
        'rss.php',
		
        function(xml) {
            mycarousel_itemAddCallback(carousel, xml);
        },
        'xml'
    );
};

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 '<p align="left"><span style="float:right; color: #FFF; FONT: 10px Tahoma; background: rgb(0, 105, 165); padding:0px 4px 0px 4px; margin:4px 0px 0px 2px;">'+$('pubDate', item).text()+'</span> <b><a href="'+$('link', item).text()+'" class="title_rss">'+$('title', item).text()+'</a></b></p><span>'+mycarousel_truncate($('description', item).text(), 900)+'<span style="float:right; color: #000; FONT: 10px Tahoma; padding:4px 4px 0px 4px; margin:4px 0px 0px 2px;">источник: <b><a href="http://media.club4x4.ru">журнал 4x4Club</a></b></span></span>';
};

/**
 * Utility function for truncating a string without breaking words.
 */
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;
};

// Credits: Robert Penners easing equations (http://www.robertpenner.com/easing/).
jQuery.easing['BounceEaseOut'] = function(p, t, b, c, d) {
	if ((t/=d) < (1/2.75)) {
		return c*(7.5625*t*t) + b;
	} else if (t < (2/2.75)) {
		return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
	} else if (t < (2.5/2.75)) {
		return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
	} else {
		return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
	}
};

jQuery(document).ready(function() {

    jQuery().ajaxStart(function() {
        jQuery(".jcarousel-clip-vertical").addClass('loading');
    });

    jQuery().ajaxStop(function() {
        jQuery(".jcarousel-clip-vertical").removeClass('loading');
    });
		
    jQuery('#mycarousel').jcarousel({
        vertical: true,
		scroll: 1,
        size: 0,
		easing: 'BounceEaseOut',
        animation: 1000,
        initCallback: mycarousel_initCallback
    });
});
//-->