/**
 * MiniBar Site jQuery actions
 *
 */
$(document).ready(function() {

// ================================================================================================
/*
	 d888b  d88888b d8b   db d88888b d8888b.  .d8b.  db      
	88' Y8b 88'     888o  88 88'     88  `8D d8' `8b 88      
	88      88ooooo 88V8o 88 88ooooo 88oobY' 88ooo88 88      
	88  ooo 88~~~~~ 88 V8o88 88~~~~~ 88`8b   88~~~88 88      
	88. ~8~ 88.     88  V888 88.     88 `88. 88   88 88booo. 
	 Y888P  Y88888P VP   V8P Y88888P 88   YD YP   YP Y88888P 
*/
// ================================================================================================
	
	// get hash in case we want to directly link to item
	var hash = window.location.hash.replace("#","");

	// vimeo video id array
	var vimeoVideos = [
		"30915818",
		"30915107",
		"30914391",
		"30913977",
		"30913644",
		"30913424",
		"30912892",
		"30911375",
		"30911049",
		"30910667",
		"30909690",
		"30909190",
		"30908756",
		"30908504",
		"30876839"
	];
	
	// initial positions
	var initialPositions = [
		"0",
		"159",
		"318",
		"477",
		"635",
		"793"
	];
	
	// open all external links in new window
	$('html a:not(.popupwindow)').filter(function(){
		var theHref = this;
		if (theHref.hostname && theHref.hostname !== location.hostname) {
			$(theHref).not(".noAutoIcon").addClass("offSite");
			$(theHref).not(".noAutoLink").attr('target','_blank').bind('click keypress', function(event) {
				var code=event.charCode || event.keyCode;
				if (!code || (code && code == 13)){

					// Build tracking url
					var fixedLink = this.href;
					fixedLink = fixedLink.replace(/https?:\/\/(.*)/,"$1");
					fixedLink = '/outgoing/' + fixedLink;

					// Track
					//pageTracker._trackPageview(fixedLink);
				};
			});
		};
	});
	
	// vertical align text
	$('.vertical-align').vAlign();
	
	// faqs
	$('.faqs .right div').hide();
	$('.faqs .right div[rel=1]').show();
	
	$('.faqs .left a').click(function() {
		
		// get rel
		var faqsRel = $(this).attr('rel');
		
		// remove all active
		$('.faqs .left a').removeClass('active');
		
		// add active class
		$('.faqs .left a[rel='+faqsRel+']').addClass('active');
		
		// hide all others
		$('.faqs .right div').hide();
		
		// show clicked
		$('.faqs .right div[rel='+faqsRel+']').show();
		
	});

// ================================================================================================
/*
	 .d8888. db    db d8888b. d8888b.  .d88b.  d8888b. d888888b 
	 88'  YP 88    88 88  `8D 88  `8D .8P  Y8. 88  `8D `~~88~~' 
	 `8bo.   88    88 88oodD' 88oodD' 88    88 88oobY'    88    
	   `Y8b. 88    88 88~~~   88~~~   88    88 88`8b      88    
	 db   8D 88b  d88 88      88      `8b  d8' 88 `88.    88    
	 `8888Y' ~Y8888P' 88      88       `Y88P'  88   YD    YP    
*/
// ================================================================================================
	

	// fade all images out
	$.fn.images_fade_out = function()
	{
		$("#photos img").fadeOut();
	};
	
	// fade in all images
	$.fn.images_fade_in = function()
	{
		// remove all dark classes
		$("#photos img").removeClass("dark");
		
		// fade in all photos
		$("#photos img").fadeIn();
	};
	
	// hide all content
	$.fn.content_hide = function()
	{
		$('.content').hide();
	};
	
	// reset positions
	$.fn.reset_positions = function()
	{
		// loop through inital positions
		$.each(initialPositions, function(k,v){
			var relToSet = parseInt(k) + parseInt(1);
			$('#photos img[rel='+relToSet+']').css({"left":v+'px'});
		});
		
	};
	
	// reset all
	$.fn.reset_all = function()
	{
		// hide all content
		$.fn.content_hide();
		
		// reset positions of everything
		$.fn.reset_positions();
		
		// fade all images back in
		$.fn.images_fade_in();
	};
	

// ================================================================================================
/*
	  .d8b.  d8b   db d888888b .88b  d88.  .d8b.  d888888b d888888b  .d88b.  d8b   db 
	 d8' `8b 888o  88   `88'   88'YbdP`88 d8' `8b `~~88~~'   `88'   .8P  Y8. 888o  88 
	 88ooo88 88V8o 88    88    88  88  88 88ooo88    88       88    88    88 88V8o 88 
	 88~~~88 88 V8o88    88    88  88  88 88~~~88    88       88    88    88 88 V8o88 
	 88   88 88  V888   .88.   88  88  88 88   88    88      .88.   `8b  d8' 88  V888 
	 YP   YP VP   V8P Y888888P YP  YP  YP YP   YP    YP    Y888888P  `Y88P'  VP   V8P 
*/
// ================================================================================================

	// Initialize
	$("#copy p").hide();
	$(".content").hide();
	
	// random vimeo
	var randomvimeoVideoId = vimeoVideos[Math.floor(Math.random() * vimeoVideos.length)];

	// build vimeo embed url
	var embedUrl = "http://vimeo.com/moogaloop.swf?clip_id="+randomvimeoVideoId+"&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1&amp;autoplay=0&amp;loop=0";

	// set embed url on page
	$("#vimeo-player embed").attr('src', embedUrl);
	$("#vimeo-player param[name=movie]").attr('value', embedUrl);

// ==================================================================================
	
	
	// mouseover images
	$("#photos img, #navigation a").hover(function() {
		
		// OVER
		
		// get rel
		var rel = $(this).attr('rel');
		
		// darken image
		$("#photos img[rel="+rel+"]").addClass("dark");
		
		// show copy
		$("#copy p[rel="+rel+"]").show();
		
		
	}, function() {
		
		// OUT
	
		// get rel
		var rel = $(this).attr('rel');
	
		// remove all dark classes
		$("#photos img").removeClass("dark");
	
		// hide all copy
		$("#copy p").hide();
		
	});
	
	// click image or nav element
	$(".link").click(function() {

		$.fn.reset_all();
		
		var this_rel = $(this).attr('rel');
		
		// animate left
		if(this_rel != '7')
		{
			$('#photos img[rel='+this_rel+']').animate({
				left: '0px'
			}, 500, 'easeInOutBack', function() {
	
				// Animation complete.
				
				// remove dark for this image
				$("#photos img[rel="+this_rel+"]").removeClass("dark");
				
				// fade all other photos out
				$('#photos img[rel!='+this_rel+']').fadeOut();
				
				// fade in content div
				$('.content[rel='+this_rel+']').fadeIn();
				
				// hide leftover copy
				$("#copy p").hide();
			});
		}
		
		if(this_rel == '7')
		{
			// fade all other photos out
			$('#photos img').hide();
			
			// fade in content div
			$('.content[rel='+this_rel+']').fadeIn();
			
			// hide leftover copy
			$("#copy p").hide();
		}
		
	});
	
	// close
	$(".close, .logo").click(function() {
		
		$.fn.reset_all();
		
	});

	// direct links
	if(hash == 'faqs') {
		$('.faq-button').triggerHandler('click');
	}
	
	if(hash == 'location') {
		$('.photo-2').triggerHandler('click');
	}
	
	if(hash == 'creations') {
		$('.photo-4').triggerHandler('click');
	}

// ================================================================================================
/*
	d88888b d8b   db d8888b. 
	88'     888o  88 88  `8D 
	88ooooo 88V8o 88 88   88 
	88~~~~~ 88 V8o88 88   88 
	88.     88  V888 88  .8D 
	Y88888P VP   V8P Y8888D' 
*/
// ================================================================================================

});
