function SlidePanel(containerID, panelClass, defaultWidth, activeWidth, duration, openIndex) {

	this.init = function(){
        this.openIndex = openIndex;
		this.containerID = containerID;
		this.container = jQuery("#"+containerID);
        this.containerWidth = this.container.width();
		this.panels = this.container.children("." + panelClass);
		this.panelClass = panelClass;
		this.panelsLength = this.panels.length;
		this.defaultWidth = defaultWidth;
		this.activeWidth = activeWidth
		//this.inactiveWidth = (this.panelsLength * this.defaultWidth) - ((this.activeWidth) / (this.panelsLength-1)); //((this.panelsLength * this.defaultWidth) - (this.activeWidth)) / (this.panelsLength - 1);
        this.inactiveWidth = (this.containerWidth - this.activeWidth) / (this.panelsLength-1);
        this.maxContainerWidth = this.panelsLength * this.activeWidth;
		this.duration = duration;
		this.holdAnimation = false;
		this.heldIndex = false;
		this.setWidth();
        this.defaultState();
		this.setEventHandlers();
	}

	this.setWidth = function(){
        this.container.css("width", this.maxContainerWidth+"px");
	}

	this.animateIt = function(panel, width, override, callback) {
		if(!this.holdAnimation || override){
			panel.animate(
				{
					width: width+"px"
				},
				{
					queue: false,
					duration: this.duration
				}
			);
		}
	}

	this.defaultState = function(){
		var that = this;

		that.panels.each(function(i){
			var panel = jQuery(this);
            if(!that.openIndex){
                that.animateIt(panel, that.defaultWidth);
            }else{				
                if(i==that.openIndex){					
                    that.animateIt(panel, that.activeWidth);
                }else{
                    that.animateIt(panel, that.inactiveWidth);
					if(that.panelClass == 'caseStudy'){
						jQuery(this).find('.liner').css('background-position','left -66px');
						jQuery(this).find('h4').css('margin','22px 0 0 60px');
					}
                }
            }
		});
	}

	this.resetState = function(){
		this.heldIndex = false;
		this.holdAnimation = false;
	}

	this.animateToActive = function(index, override){
		var that = this;
		that.panels.each(function(indexToCompare){
			var panel = jQuery(this);
			
			if(indexToCompare == index){
				that.animateIt(panel, that.activeWidth, override);
				if(that.panelClass == 'caseStudy'){
					panel.find('.liner').css('background-position','left top');
					panel.find('h4').css('margin','22px 0 0 215px');
				}
			}else{
				that.animateIt(panel, that.inactiveWidth, override);
				if(that.panelClass == 'caseStudy'){
					panel.find('.liner').css('background-position','left -66px');
					panel.find('h4').css('margin','22px 0 0 60px');
				}
			}
		});
	}

	this.setEventHandlers = function() {
		var that = this;
		/*jQuery(document).click(function(event) {
			var target = jQuery(event.target);
			var parents = target.parents();
			if(!parents.filter("#"+that.containerID).length){
				that.resetState();
				that.defaultState();
			}
		});*/
		that.container.bind("mouseleave", function(){
			that.defaultState();
			if(that.panelClass == 'caseStudy'){
				that.panels.each(function(index){
					if(index == 0){
						jQuery(this).find('.liner').css('background-position','left top');
						jQuery(this).find('h4').css('margin','22px 0 0 215px');
					}else{
						jQuery(this).find('.liner').css('background-position','left -66');
						jQuery(this).find('h4').css('margin','22px 0 0 60px');
					}
				});
			}
		});
		that.panels.each(function(index){
			/*jQuery(this).click(function(event){
				event.preventDefault();
				if(index !== that.heldIndex){
					that.holdAnimation = true;
					that.heldIndex = index;
					that.animateToActive(index, true);
				} else {
					that.resetState();
				}
			});*/
			jQuery(this).hover(
				function(){
					that.animateToActive(index);
				},
				function(){
					
				}
			);
		});
	}

	this.init();
}
