//FANCYBOX

$(document).ready(function() {
	
	/* Apply fancybox to multiple items */
	
	$("a[rel=design-2-print]").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	true
	});
	
	$("a[rel=hellyeah]").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	true
	});
	
	$("a[rel=pocket-schedule]").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	true
	});
	
	$("a[rel=metric-convention]").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	true
	});

	$("a[rel=blind]").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	true
	});

	$("a[rel=acbu]").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	true
	});

	$("a[rel=thinker-maker]").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	true
	});
	
});

//SCROLLING LINKS

$(document).ready(function() {
  function filterPath(string) {
  return string
	.replace(/^\//,'')
	.replace(/(index|default).[a-zA-Z]{3,4}$/,'')
	.replace(/\/$/,'');
  }
  var locationPath = filterPath(location.pathname);
  var scrollElem = scrollableElement('html', 'body');

  $('a[href*=#]').each(function() {
	var thisPath = filterPath(this.pathname) || locationPath;
	if (  locationPath == thisPath
	&& (location.hostname == this.hostname || !this.hostname)
	&& this.hash.replace(/#/,'') ) {
	  var $target = $(this.hash), target = this.hash;
	  if (target) {
		var targetOffset = $target.offset().top;
		$(this).click(function(event) {
		  event.preventDefault();
		  $(scrollElem).animate({scrollTop: targetOffset}, 400, function() {
			location.hash = target;
		  });
		});
	  }
	}
  });

  // use the first element that is "scrollable"
  function scrollableElement(els) {
	for (var i = 0, argLength = arguments.length; i <argLength; i++) {
	  var el = arguments[i],
		  $scrollElement = $(el);
	  if ($scrollElement.scrollTop()> 0) {
		return el;
	  } else {
		$scrollElement.scrollTop(1);
		var isScrollable = $scrollElement.scrollTop()> 0;
		$scrollElement.scrollTop(0);
		if (isScrollable) {
		  return el;
		}
	  }
	}
	return [];
  }

});

//GALLERY
$(document).ready(function() {
	
	$(".main_image .desc").show(); //Show Banner
	$(".main_image .block").animate({ opacity: 1 }, 1 ); //Set Opacity
	$(".image_thumb ul li:first").addClass('active'); //Add the active class (highlights the very first list item by default)
	$(".full_view-buttons ul li:first").css('display', 'block');
	
	$(".image_thumb ul li").click(function(){
		//Set Variables
		var imgAlt = $(this).find('img').attr("alt"); //Get Alt Tag of Image
		var imgTitle = $(this).find('a').attr("href"); //Get Main Image URL
		var imgDesc = $(this).find('.block').html();  //Get HTML of the "block" container
		var imgDescHeight = $(".main_image").find('.block').height(); //Find the height of the "block"
		var currentThumb = $(this).find('a').attr("name");

		if ($(this).is(".active")) {  //If the list item is active/selected, then...			
			return false; // Don't click through - Prevents repetitive animations on active/selected list-item
		} else { //If not active then...
			//Animate the Description
			$(".main_image img").animate({ opacity: 0 }, 250 , function() { //Pull the block down (negative bottom margin of its own height)
				$(".main_image img").animate({ opacity: 1 }, 250 ); //swap the html of the block, then pull the block container back up and set opacity
				$(".main_image img").attr({ src: imgTitle , alt: imgAlt}); //Switch the main image (URL + alt tag)			
			});
			
			$(".main_image .block").animate({ opacity: 0 }, 250 , function() { //Pull the block down (negative bottom margin of its own height)
				$(".main_image .block").html(imgDesc).animate({ opacity: 1 }, 250 ); //swap the html of the block, then pull the block container back up and set opacity
			});
			
			$(".full_view-buttons ul li").css('display', 'none'); //hide all of the full view buttons
			currentThumb = "." + currentThumb; //turn the current thumbnail name into a css class selector (i.e. .design-2-print)
			$(currentThumb).css('display', 'block'); //display the button which corresponds with the selected thumbnail	
		}
		//Show active list-item
		$(".image_thumb ul li").removeClass('active'); //Remove class of 'active' on all list-items
		$(this).addClass('active');  //Add class of 'active' on the selected list
		return false;
	
	}) .hover(function(){ //Hover effects on list-item 
		$(this).addClass('hover'); //Add class "hover" on hover 
		}, function() {
		$(this).removeClass('hover'); //Remove class "hover" on hover out
	});
});

//SET VERTICAL BARS HEIGHT

function load() {	
	window.setTimeout(function () {

		$(document).ready(function () {

			var ResizeTarget = $('#details_height');

			ResizeTarget.resize(function () {

				var target = $('.section-line_details');

				target.css('height', ResizeTarget.height());

			}).trigger('resize');

		}); }, 100);
		
	window.setTimeout(function () {

		$(document).ready(function () {

			var ResizeTarget = $('#about_height');

			ResizeTarget.resize(function () {

				var target = $('.section-line_about');

				target.css('height', ResizeTarget.height());

			}).trigger('resize');

		}); }, 100);

	window.setTimeout(function () {

		$(document).ready(function () {

			var ResizeTarget = $('#thinker_height');

			ResizeTarget.resize(function () {

				var target = $('.section-line_thinker-maker');

				target.css('height', ResizeTarget.height());

			}).trigger('resize');

		}); }, 100);

	window.setTimeout(function () {

		$(document).ready(function () {

			var ResizeTarget = $('#thanks_height');

			ResizeTarget.resize(function () {

				var target = $('.section-line_thanks');

				target.css('height', ResizeTarget.height());

			}).trigger('resize');

		}); }, 100);
}
