/* 1. $(document).ready()
===============================================================================================*/
$(document).ready(function(){
	 $("#inside-content").find("select, input, button, textarea").uniform();
	if ($('#slideshow').length){
		$("#slideshow").imagesLoaded(function(){
			initSlideshow();
		});
	}
});
/* 2. initSlideshow()
===============================================================================================*/
function initSlideshow(){
/* 2.1 setup
-----------------------------------------------------------------------------------------------*/
	var activeIndex = -1;
	$('#image-loading').fadeOut('fast');
/* 2.2 userInput()
-----------------------------------------------------------------------------------------------*/
	$('#button-box ul li').each(function(){
		if ($(this).hasClass('current_page_item')){
			goSlide($(this).index());
		}
		$(this).hover(function(){
			$(this).addClass('current_page_item');
		},function(){
			if ($(this).index() != activeIndex){
				$(this).removeClass('current_page_item');
			}
		});
		$(this).find('a').click(function(e){
			//e.preventDefault();
			$('#button-box ul li').each(function(){
				$(this).removeClass('current_page_item');
			});
			$(this).parent('li').addClass('current_page_item');
			goSlide($(this).parent('li').index());
		});
	});
	if (activeIndex == -1){
		$('#button-box ul li:eq(0)').find('a').click();
	}
/* 2.3 goSlide(index)
-----------------------------------------------------------------------------------------------*/
	function goSlide(index){
		if (index != activeIndex){
			activeIndex = index;
			$('#image-slides .slide').each(function(){
				$(this).stop(false,true).fadeOut(400,function(){
					$(this).find('.image-caption').css({height: '0px', marginTop:'250px'});
				});
			});
			$('#image-slides .slide:eq('+index+')').stop(false,true).fadeIn(400,function(){
				$(this).find('.image-caption').stop(false,false).animate({height: '80px', marginTop:'170px'},300);
			});
		}
	}
}
/* 2.4 imagesLoaded $('#my-container').imagesLoaded(myFunction)
------------------------------------------------------------------------------------------ */
	// original: mit license. paul irish. 2010.
	// contributors: Yiannis Chatzikonstantinou, David DeSandro
	//   Oren Solomianik, Adam J. Sontag
	$.fn.imagesLoaded = function( callback ) {
	  var $images = this.find('img'),
		  len = $images.length,
		  _this = this,
		  blank = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==';
	
	  function triggerCallback() {
		callback.call( _this, $images );
	  }
	
	  function imgLoaded() {
		if ( --len <= 0 && this.src !== blank ){
		  setTimeout( triggerCallback );
		  $images.unbind( 'load error', imgLoaded );
		}
	  }
	
	  if ( !len ) {
		triggerCallback();
	  }
	
	  $images.bind( 'load error',  imgLoaded ).each( function() {
		// cached images don't fire load sometimes, so we reset src.
		if (this.complete || this.complete === undefined){
		  var src = this.src;
		  // webkit hack from http://groups.google.com/group/jquery-dev/browse_thread/thread/eee6ab7b2da50e1f
		  // data uri bypasses webkit log warning (thx doug jones)
		  this.src = blank;
		  this.src = src;
		}
	  });
	
	  return this;
	};
/* 3. 
===============================================================================================*/

