var Image_Carousel = function( container, items ){
		/* CONSTRUCTOR VARS */
		this.itemsId = items;
		this.containerId = container;

		this.itemsArray = new Array();
		this.containerObject;

		/* INSTANCE VARS */
		this.started = false;
		this.currentIndex = 0;
		var image_animating = false;

		/* CONSTANTS */
		this.ITEM_WIDTH = 940;
		this.ANIMATION_LENGTH = 1000;

		/* INIT FUNCTION */
		this.init = function(){
			var itemArray = new Array();
			$("#"+this.itemsId+" ul li").each(function( index, item ){
				itemArray.push( $(item).html() );
			});
			this.itemsArray = itemArray;
			this.containerObject = $("#"+this.containerId);
		};

		/* NAV FUNCTIONS */
		this.next = function(){
			if(image_animating == false){
				this.currentIndex++;
				this.moveItems( true );
				$('#right_arrow').hide();
				$('#left_arrow').hide();
				carouselControl(this.currentIndex);
				image_animating = true;
			}else{
				return false;
			}
			
		};

		this.previous = function(){
			
			if(image_animating == false){
				this.currentIndex--;
				this.moveItems( false );
				$('#left_arrow').hide();
				$('#right_arrow').hide();
				carouselControl(this.currentIndex);
				image_animating = true;
			}else{
				return false;
			}
		};

		this.moveItems = function( next ){
			if( this.currentIndex < 0 ){
				this.currentIndex = this.itemsArray.length - 1;
			}

			if( this.currentIndex > this.itemsArray.length -1 ){
				this.currentIndex = 0;
			}

			var nextItem, previousItem, nextStart, previousTarget = null;
				
			if( next ){
				previousItem = $('#'+this.containerId+" div:nth-child(1)");
				this.containerObject.append( this.itemsArray[this.currentIndex] );
				nextItem = $('#'+this.containerId+" div:nth-child(2)");
				nextStart = this.ITEM_WIDTH * 2;
				previousTarget = 0;
			}else{
				previousItem = $('#'+this.containerId+" div:nth-child(1)");
				this.containerObject.prepend( this.itemsArray[this.currentIndex] );
				nextItem = $('#'+this.containerId+" div:nth-child(1)");
				nextStart = 0;
				previousTarget = this.ITEM_WIDTH * 2;
			}

			nextItem.css('left',nextStart);
			nextItem.css('opacity',"0");
			previousItem.animate( {'left': previousTarget, opacity : "0" }, this.ANIMATION_LENGTH, function(){
				previousItem.remove();
				$('#right_arrow').fadeIn(500);
				$('#left_arrow').fadeIn(500);
				image_animating = false;
			});
			nextItem.animate( {'left': this.ITEM_WIDTH, opacity : "1" }, this.ANIMATION_LENGTH );
		};
	};
	
var Text_Carousel = function( container, items ){
		/* CONSTRUCTOR VARS */
		this.itemsId = items;
		this.containerId = container;

		this.itemsArray = new Array();
		this.containerObject;

		/* INSTANCE VARS */
		this.started = false;
		this.currentIndex = 0;
		var text_animating = false;

		/* CONSTANTS */
		this.ITEM_WIDTH = 940;
		this.ANIMATION_LENGTH = 500;

		/* INIT FUNCTION */
		this.init = function(){
			var itemArray = new Array();
			$("#"+this.itemsId+" ul li").each(function( index, item ){
				itemArray.push( $(item).html() );
			});
			this.itemsArray = itemArray;
			this.containerObject = $("#"+this.containerId);
		};

		/* NAV FUNCTIONS */
		this.next = function(){
			if(text_animating == false){
				this.currentIndex++;
				this.moveItems( true );
				text_animating = true;
			}else{
				return false;
			}
		};

		this.previous = function(){
			if(text_animating == false){
				this.currentIndex--;
				this.moveItems( false );
				text_animating = true;
			}else{
				return false;	
			}
		};

		this.moveItems = function( next ){
			if( this.currentIndex < 0 ){
				this.currentIndex = this.itemsArray.length - 1;
			}

			if( this.currentIndex > this.itemsArray.length -1 ){
				this.currentIndex = 0;
			}

			var nextItem, previousItem, nextStart, previousTarget = null;
				
				previousItem = $('#'+this.containerId+" div:nth-child(1)");
				this.containerObject.append( this.itemsArray[this.currentIndex] );
				nextItem = $('#'+this.containerId+" div:nth-child(2)");
				previousTarget = 0;

				nextItem.css('opacity',"0");
				previousItem.animate( {'left': previousTarget, opacity : "0" }, this.ANIMATION_LENGTH, function(){
					previousItem.remove();
					nextItem.animate( {'left': this.ITEM_WIDTH, opacity : "1" }, this.ANIMATION_LENGTH );
					text_animating = false;
				});
		};
	};	


	var purpleDot;
	var whiteDot;
	
	function carouselControl(carId){
		dotId = carId;
		if( !purpleDot && !whiteDot ){
			purpleDot = $('#dots .inactive').attr("src");
			whiteDot = $('#dots .active').attr("src");
		}
		
		$("#dots img").each(function(index, item){
			if( index == carId ){
				$(item).removeClass('inactive');
				$(item).addClass('active');
				$(item).attr("src", whiteDot );
			}else{
				$(item).removeClass('active');
				$(item).addClass('inactive');
				$(item).attr("src", purpleDot );
			}
		});
	}
