	
	window.mstools = (function(mstools, window, document, $, undefined ){
		
		var	me = mstools.carousel = mstools.carousel || {};
		me.vars = {
				backgroundImages : {"image": [        
        	{"src": "DSC_0259.jpg", "alt": "Image 2", "desc": "Image 2 description goes here"},
					{"src": "DSC_0193.jpg", "alt": "Image 1", "desc": "Image 1 description goes here"},
        	{"src": "DSC_0449.jpg", "alt": "Image 3", "desc": "Image 3 description goes here"} ]
				},
				currentImage : 0, // counter for image array
				pageCounter : 0, // logs how many pages have been appended to load page
				currentPageIndex : 0
		}
		
		
		me.init = function(){
			console.log("mstools.carousel init");
		
		
		// set up image json - this can be moved to a separate file
		 

			
		/* $switchersArray.each(function(){
					$this = $(this);
					$this.bind("click", me.swapContent );
					//$this.on("click", me.swapContent);
				});
			*/	
			
				
			var switchButtonClass = "backgroundnavbutton",
			$switchersArray = $("." + switchButtonClass);
				
			
			$switchersArray.each(function(){
					$this = $(this);
					$this.bind("click", me.swapContent );
					//$this.on("click", me.swapContent);
				});
				
				
			
		}
		
		
		
		
		me.swapContent = function(e){
				console.log(e.currentTarget);
				var $this = $(e.currentTarget);
				e.preventDefault();
				
				
				var currentImage = me.vars.currentImage;
				var	newImageSrc = "/assets/images/" + me.vars.backgroundImages.image[currentImage].src;
				var newImageBackground = ' url(/assets/images/' + me.vars.backgroundImages.image[currentImage].src + ')';
				
				// create new background and scroll in
				
										
				// no need to do this - we need to swap out the main content div, update main nav and url		
		 		/*
				var currentBody = $('body').css("width", screen.width * 2); 				
				var currentPage = $(this).parents().find('.bgWrapper'),
				currentPageClass = "contentPage" +  me.vars.pageCounter; 
						if(!currentPage.hasClass(currentPageClass)){
							currentPage.addClass(currentPageClass);
						}						
				var newPage = $(currentPage).css("width", screen.width).addClass("wrapFloat").clone();
						me.vars.pageCounter++;
		
					newPage.addClass("contentPage" + me.vars.pageCounter);
					$(currentPage).after(newPage);
				
				*/
				
				
				$('.bgWrapper').css("background-image", newImageBackground);
				var ctaImage = document.getElementById('ctaImage');
						ctaImage.src = newImageSrc;				
			
				if ($this.hasClass("next")){
						/* this needs to be built into content swap function */
						if((currentImage) == me.objlength(me.vars.backgroundImages.image)-1){
							me.vars.currentImage = 0;
						} else {
							me.vars.currentImage++;
						}
						
						me.getContent('next');
				}
				else if ($this.hasClass("prev")) {
						if((currentImage) == 0){
							me.vars.currentImage = me.objlength(me.vars.backgroundImages.image)-1;
						} else {
							me.vars.currentImage--;
						}
					}	
		}
		
		
		
		me.objlength = function(obj){
			//return{
						
						 var size = 0, key;
    					for (key in obj) {
       				 	if (obj.hasOwnProperty(key)) size++;
   						}
    				console.log("size of object = " , size);	
						return size;
							
		}
		
		me.getContent = function(direction){
			if(direction == "next"){
				
				var request = $.ajax({
						url: "/ajax-content",
						cache: false,
						success: function(html){
							//$(".mainContent").append(html);
						}
					});
					
				request.done(function(msg) {
  				$(".mainContent").html( msg );
				});
					
				request.fail(function(jqXHR, textStatus) {
  				console.log( "Request failed: " + textStatus );
				});
				
			} else if (direction == "previous"){
					
			}
		}
		
		me.swapBackground = function(e){
				var backgroundImageObject = {
						
						
						//'src' : 'DSC_0193.jpg',
						
					} 
		}
		
		/*
		me.swapContent = function(e){
				console.log(e.currentTarget);
				var $this = $(e.currentTarget);
				e.preventDefault();
				if ($this.hasClass("next")){
						console.log("next button pressed");
						
					}
				else {
						console.log("previous button pressed");
					}	
		}*/
		
		
		me.carouselNext = function(){
			console.log("Carousel Next called");	
		}
		
		me.carouselPrev = function(){
		 console.log("Carousel Previous called");
		}
		
		
		return mstools;
		
			
		})(window.mstools || {}, this, this.document, jQuery);







