jQuery.fn.carousel = function(options) {

	var count;

	jQuery.fn.prepareDOM = function() {
		jQuery(this).wrapInner('<div class="offers" />');
		jQuery(this).wrapInner('<div class="offers-wrap" />');


		jQuery(this).append('<div class="prev control">&lsaquo;</div>');
		jQuery(this).append('<div class="next control">&rsaquo;</div>');
		jQuery(this).append('<div class="learnmore"><a class="resortchoice" href=""><img src="image/learn-more.png" /></a></div>');
		
		jQuery(this).find(".offer:last").remove().prependTo( jQuery(this).find(".offers") );
		
		jQuery(this).find('.offer:eq(0)').addClass("left");
		jQuery(this).find('.offer:eq(1)').addClass("middle");
		jQuery(this).find('.offer:eq(2)').addClass("right");
		
		jQuery(this).find('.offer img').animate( {opacity: '.5', width: '141px', height: '139px', marginTop: '20px'}, 0);
		jQuery(this).find('.middle img').animate( {opacity: '1', width: '202px', height: '196px', marginTop: '0px'}, 0);
		jQuery(this).find('.right img').animate( {marginTop: '20px', marginLeft: '40px'}, 0);
		jQuery(this).find('.left img').animate( {marginTop: '20px', marginLeft: '20px'}, 0);
		
		jQuery(this).find(".learnmore a").attr( "href", jQuery(this).find(".middle a").attr("href") );
		jQuery(this).find(".learnmore a").attr( "target", jQuery(this).find(".middle a").attr("target") );

		
		jQuery(this).find(".offers").cleanWhitespace();



		count = jQuery(this).find(".offer").size();
	};
	
	jQuery.fn.slideNext = function() {
		
		jQuery(this).width( jQuery(this).width() + 202 );
		jQuery(this).append( jQuery(this).find(".offer.left").clone() );
		
		jQuery(this).find(".right + .offer").addClass("ondeck");
		
		
		jQuery(this).animate({	left : '-=202px' }, 500);
		$(this).find('.middle img').stop() 
		.animate({
			width: '141px', /* Set new width */
			height: '139px', /* Set new height */
			opacity: '.5',
			marginTop: '20px',
			marginLeft: '20px'
		}, 500);	
		
		$(this).find('.right img').stop() 
		.animate({
			width: '202px', /* Set new width */
			height: '196px', /* Set new height */
			opacity: '1',
			marginTop: '0px',
			marginLeft: '0px'
		}, 500);
		
		$(this).find('.ondeck img').stop() 
		.animate({
			marginTop: '20px',
			marginLeft: '40px'
		}, 0);
		
			
		jQuery(this).find(".left").removeClass("left");
		jQuery(this).find(".middle").removeClass("middle").addClass("left");
		jQuery(this).find(".right").removeClass("right").addClass("middle");
		jQuery(this).find(".ondeck").removeClass("ondeck").addClass("right");
		
		main.find(".learnmore a").attr( "href", jQuery(this).find(".middle a").attr("href") );
		main.find(".learnmore a").attr( "target", jQuery(this).find(".middle a").attr("target") );
		if (! jQuery(this).find(".middle a").hasClass("resortchoice")) { main.find(".learnmore a").unbind('click.fb') }
		else { 
			main.find(".learnmore a").fancybox({
					'width'				: 380,
					'height'			: 375,
					'overlayShow'		: true,
					'hideOnContentClick': true,
					'padding'			: 30,
					'autoDimensions'	: false,
					'showCloseButton'	: false
			});
			main.find(".middle a").fancybox({
					'width'				: 380,
					'height'			: 375,
					'overlayShow'		: true,
					'hideOnContentClick': true,
					'padding'			: 30,
					'autoDimensions'	: false,
					'showCloseButton'	: false
			});
		}
		

	}
	
	jQuery.fn.slidePrev = function() {
		var addition =  jQuery(this).find(".left").index() + count - 1;
		if (jQuery(this).find(".left").prev().length == 0) { 
			jQuery(this).width( jQuery(this).width() + 202 );
			jQuery(this).prepend( jQuery(this).find(".offer:eq(" + addition + ")").clone() ).animate( {left: '-=202px' }, 0);
		}
		
		jQuery(this).find(".left").prev().addClass("ondeck");
		
		
		jQuery(this).animate({	left : '+=202px' }, 500, function() {} );
		$(this).find('.middle img').stop() 
		.animate({
			width: '141px', /* Set new width */
			height: '139px', /* Set new height */
			opacity: '.5',
			marginTop: '20px',
			marginLeft: '40px'
		}, 500);	
		
		$(this).find('.left img').stop() 
		.animate({
			width: '202px', /* Set new width */
			height: '196px', /* Set new height */
			opacity: '1',
			marginTop: '0px',
			marginLeft: '0px'
		}, 500);
		
		$(this).find('.ondeck img').stop() 
		.animate({
			marginTop: '20px',
			marginLeft: '20px'
		}, 0);
				
		jQuery(this).find(".right").removeClass("right");
		jQuery(this).find(".middle").removeClass("middle").addClass("right");
		jQuery(this).find(".left").removeClass("left").addClass("middle");
		jQuery(this).find(".ondeck").removeClass("ondeck").addClass("left");
		
		main.find(".learnmore a").attr( "href", jQuery(this).find(".middle a").attr("href") );
		main.find(".learnmore a").attr( "target", jQuery(this).find(".middle a").attr("target") );
		if (! jQuery(this).find(".middle a").hasClass("resortchoice")) { main.find(".learnmore a").unbind('click.fb') }
		else { 
			main.find(".learnmore a").fancybox({
					'width'				: 380,
					'height'			: 375,
					'overlayShow'		: true,
					'hideOnContentClick': true,
					'padding'			: 30,
					'autoDimensions'	: false,
					'showCloseButton'	: false
			});	
			main.find(".middle a").fancybox({
					'width'				: 380,
					'height'			: 375,
					'overlayShow'		: true,
					'hideOnContentClick': true,
					'padding'			: 30,
					'autoDimensions'	: false,
					'showCloseButton'	: false
			});	
		}

	}
	
	jQuery.fn.cleanWhitespace = function() {
	    textNodes = this.contents().filter(
	        function() { return (this.nodeType == 3 && !/\S/.test(this.nodeValue)); })
	        .remove();
	}


	
	//MAIN PLUGIN CODE
	
	var main = jQuery(this);
	
	jQuery(this).prepareDOM();
	
	jQuery(this).children(".next").click( function() {
		main.find(".offers").slideNext();
	});
	
	jQuery(this).children(".prev").click( function() {
		main.find(".offers").slidePrev();
	});
	


};
