jQuery.fn.carousel = function(options){
	options = jQuery.extend({
		'speed' : 100,
		'mainWidth' : 650,
		'mainHeight' : 320
	},options);

	return this.each(function(){
		var imgCount = jQuery('#cImagaes').find('img').length;
		jQuery('#cImagaes').width(imgCount * 650);
		jQuery('#carouselContent').css('position', 'relative');
		//format images
		ew = jQuery('#carouselContent').width();
		eh = jQuery('#carouselContent').height();
		
		var loader = jQuery('#loader');
			loader.hide();
		loaded = 0;

		jQuery('#cImagaes img').each(function(){
			jQuery(this).css('opacity','0.5');
			var inde = jQuery(this).index();
			jQuery('<img/>')
				.attr('src',jQuery(this).attr('src'));
			var dif = 650 * 100 / jQuery(this).width();
			var nhe = Math.ceil(jQuery(this).height() * dif / 100);
			//alert(dif + " " + nhe);
			jQuery(this).width('650');
			jQuery(this).height(nhe);
			jQuery(this).css({
				'position' : 'relative',
				'top' : '50%',
				'margin-top' : Math.ceil((320 / 2) - nhe / 2) + 'px'
			});
				jQuery('#cImagaes img').fadeTo(1,600);
				
				var step = 650;
				var start = 0;
					lim = imgCount * options.mainWidth - options.mainWidth;
				jQuery('#rightArrow').bind('click',function(){
					start += step;
					if(start > lim){
						start = 0;
					}
					jQuery('#cImagaes').animate({
						marginLeft : -start
					},options.speed);
				});

				jQuery('#leftArrow').bind('click',function(){
					start -= step;
					if(start < 0){
						start = lim;
					}
					jQuery('#cImagaes').animate({
						marginLeft : -start
					},options.speed);
				});
		});
	});
}

