(function($){
$.fn.cycle = function() {
	$container 				= $(this);
	$imageContainers 		= $container.children();
	$imageContainerWidth	= 250;
	$imageContainerSpace 	= 50;
	
	
	$container.wrap("<div class=\"xslideshow\" style=\"overflow:hidden; position: relative;\"></div>");
	
	$container.css("width", ( $imageContainers.length * $imageContainerWidth ) + ( $imageContainers.length  * $imageContainerSpace ) + "px" );
	
	$containerWidth = parseInt( $container.css("width") );

	$imageContainers.each(function( $i ) {
		$($imageContainers[$i]).css({
			"float":"left",
			"list-style":"none",
			"margin-left": $imageContainerSpace + "px",
			"width":"250px",
			"text-align":"center"
		});
	});
	
	
	$leftPos = ( ( $imageContainerWidth + $imageContainerSpace ) / 2 ) + ( $imageContainerSpace / 2 );
	$leftPos += $imageContainerWidth + $imageContainerSpace;
	$container.css( {
		"left": "-" + $leftPos + "px",
		"position": "relative"
	});
	
	setTimeout(go, 3000 );
};
 
function go() {
	$container.animate(
		{ left: "-=300px" }, 
		2500,
		null,
		function(){
			if(parseInt( $container.css("width") ) - ( parseInt( $container.css("left") ) * -1 ) <= 1325 ) {
				$leftPos = ( ( $imageContainerWidth + $imageContainerSpace ) / 2 ) + ( $imageContainerSpace / 2 );
				$leftPos += $imageContainerWidth + $imageContainerSpace;
				$container.css( {
					"left": "-" + $leftPos + "px",
					"position": "relative"
				});
			}
			setTimeout(go, 2000);
		} 
	);
};
 
})(jQuery);


$(document).ready( function() {
	$('#slideshow').cycle();
});
