function updateButtons() {
  jQuery("#gallery-arrow-prev").attr("disabled", !jQuerySlider.hasPrevious());
  jQuery("#gallery-arrow-next").attr("disabled", !jQuerySlider.hasNext());
}

var jQuerySlider = {
  next : function() {
    if (this.hasNext()) {
      var width = this.current().innerWidth();
      this.changeCurrent(this.current(), this.current().next());
      this.strip().animate({ left:"-=" + width + "px" }, this.speed(), this.ease())
    }
  },
  
  previous : function() {
    if (this.hasPrevious()) {
      var width = this.current().innerWidth();
      this.changeCurrent(this.current(), this.current().prev());
      this.strip().animate({ left:"+=" + width + "px" }, this.speed(), this.ease())
    }
  },
  
  hasNext : function() {
    var next = this.current().next();
    return next[0] != undefined;
  },
  
  hasPrevious : function() {
    var prev = this.current().prev();
    return prev[0] != undefined;
  },
  
  changeCurrent : function(oldObj, newObj) {
    oldObj.removeClass(this.currentClass());
    newObj.addClass(this.currentClass());
  },
  
  current : function() {
    return $(this.strip().children("." + this.currentClass())[0]);
  },
  
  speed : function() {
    // You can use either 'slow', 'normal', 'fast', or number of milliseconds
    return 1000;
  },
  
  ease : function() {
    return "easeInOutSine";
  },
  
  currentClass : function() {
    // Class for the currently selected element
    return "current";
  },
  
  strip : function() {
    // Id of the strip itself
    return $("#strip");
  }
};


/* reset all slider attributes */
function reset_slider_navigation(){
	
	// move 'current' class to first image in strip
	$("#strip li").removeClass('current').eq(0).addClass('current');
	
	// disable and enable the prev and next buttons
	$("#gallery-arrow-prev").addClass('disabled');
	$("#gallery-arrow-next").removeClass('disabled');
	updateButtons();
}

/* switch between the customer showcase and defaul layout galleries */
function toggleGallery(){
	
	// IF: clicked gallery title isn't the active gallery
	if (!($(this).hasClass('active'))) {
	
		// store html of the active and the storage strips in variables
		var old_strip = $('#strip').html();
		var new_strip = $('#holder').html();
		
		// toggle active class on Gallery titles
		$('#gallery-buttons h1 a').removeClass('active');
		$(this).addClass('active');
		
		// fadeOut active strip
		$('#strip').fadeTo(600, 0, function(){
			
			// add stored html to active strip, resets the strip position, and shows new content
			$('#strip').html(new_strip).css('left', '-250px').fadeTo(600, 1);
			
			reset_slider_navigation();
		
			// put current html in storage
			$('#holder').html(old_strip);
		});
		
		// switch the blurb content
		$('#blurb').fadeTo(600, 0, function(){
			$('#blurb span').toggleClass('show');
			$('#blurb').fadeTo(600, 1);
		});
	
	// IF: clicked gallery title is the active gallery
	} else {
		return false;
	}
}

jQuery(document).ready(function(){
	
	// CLICK: switch between galleries when the gallery titles are clicked
	jQuery('#gallery-buttons h1 a').click(function(){
		this_button = $(this);
		customer_gallery_warning = 'Our customer gallery is intended to show what is possible using Wordpress and the ProPhoto theme.  However, these sites may use a combination of ProPhoto features, Wordpress plugins, or advanced code modification to acheive the final look and functionality of their blog.  Be inspired, but refer to our default layout gallery to see which features are provided by the ProPhoto theme.';
		customer_gallery_warning = 'ProPhoto3 was just released, so we will have a few customer examples up within a few days.';
		if (this_button.hasClass('warning')){
			alert(customer_gallery_warning);
			this_button.removeClass('warning');
		}
		return false;
		toggleGallery();
	});
	
	// HOVER: add hover class for prev and next arrow buttons
	jQuery('#gallery-buttons a.gallery-arrow').mouseover(function(){
		jQuery(this).addClass('hover');
	}).mouseout(function(){
		jQuery(this).removeClass('hover');
	});
	
	// CLICK: arrow buttons
	jQuery('#gallery-arrow-next').live('click', function(){
		jQuerySlider.next();
		updateButtons();
		if ( !jQuerySlider.hasNext() ) {
			jQuery(this).addClass('disabled');
		}
		jQuery('#gallery-arrow-prev').removeClass('disabled');
	});
	jQuery('#gallery-arrow-prev').live('click', function(){
		jQuerySlider.previous();
		updateButtons();
		if ( !jQuerySlider.hasPrevious() ) {
			jQuery(this).addClass('disabled');
		}
		jQuery('#gallery-arrow-next').removeClass('disabled');
	});
});