/**
 * jQuery.ScrollTo - Easy element scrolling using jQuery.
 * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 5/25/2009
 * @author Ariel Flesler
 * @version 1.4.2
 *
 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
 */
;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);


jQuery(function() {
	
	/* Move user to correct home orientation */
	
	jQuery.scrollTo( {top: 80, left: 600-jQuery(window).width()/2+480 }, {duration: 1500});
	
	/* Brainspill */
	
	jQuery("#menu-item-20, #brainspill-home-button").click(function() {
		jQuery.scrollTo( {top: 3940, left: 3820-jQuery(window).width()/2+480 }, {duration: 1500});
		return false;
	});
	
	/* Front Room */
	
	jQuery("#menu-item-21, #frontroom-home-button").click(function() {
		jQuery.scrollTo( {top: 3940, left: 2020-jQuery(window).width()/2+480 }, {duration: 1500});
		return false;
	});
	
	/* Blog */
	
	jQuery("#menu-item-22, #blog-home-button").click(function() {
		jQuery.scrollTo( {top: 3940, left: 680-jQuery(window).width()/2+480 }, {duration: 1500});
		return false;
	});
	
	/* The Team */
	
	jQuery("#menu-item-23, #team-home-button").click(function() {
		jQuery.scrollTo( {top: 1440, left: 580-jQuery(window).width()/2+480 }, {duration: 1500});
		return false;
	});
	
	/* Contact Us */
	
	jQuery("#menu-item-24").click(function() {
		jQuery.scrollTo( {top: 0, left: 2160-jQuery(window).width()/2+480 }, {duration: 1500});
		return false;
	});
	
	/* The Work */
	
	jQuery("#menu-item-25, #thework-home-button").click(function() {
		jQuery.scrollTo( {top: 80, left: 4550-jQuery(window).width()/2+480 }, {duration: 1500});
		return false;
	});
	
	/* Home */
	
	jQuery("#menu-item-26").click(function() {
		jQuery.scrollTo( {top: 80, left: 600-jQuery(window).width()/2+480 }, {duration: 1500});
		return false;
	});
	
	
	/* The Team Code */
	
	jQuery('.paul-team-link a').click(function() {
		jQuery("#team-member-names a").removeClass("active-staff");
		jQuery(this).addClass('active-staff');
		  jQuery('#theteam-heads').animate({
		    left: '-1800'
		  }, 2000, function() {
		    // Animation complete.
	  });
	
	  jQuery('#theteam-middles').animate({
		    left: '-1782'
		  }, 1500, function() {
		    // Animation complete.
	  });
	
	  jQuery('#theteam-bottoms').animate({
		    left: '-1800'
		  }, 2500, function() {
		   	jQuery(".bio").hide();
			jQuery(".paul-bio").show();
	  });

	return false;
	
	});
	
	jQuery('.debbie-team-link a').click(function() {
		jQuery("#team-member-names a").removeClass("active-staff");
		jQuery(this).addClass('active-staff');
		  jQuery('#theteam-heads').animate({
		    left: '-1542'
		  }, 2000, function() {
		    // Animation complete.
	  });
	
	  jQuery('#theteam-middles').animate({
		    left: '-1526'
		  }, 1500, function() {
		    // Animation complete.
	  });
	
	  jQuery('#theteam-bottoms').animate({
		    left: '-1534'
		  }, 2500, function() {
		    jQuery(".bio").hide();
			jQuery(".debbie-bio").show();
	  });

	return false;
	
	});
	
	jQuery('.annika-team-link a').click(function() {
		jQuery("#team-member-names a").removeClass("active-staff");
		jQuery(this).addClass('active-staff');
		  jQuery('#theteam-heads').animate({
		    left: '-509'
		  }, 2000, function() {
		    // Animation complete.
	  });
	
	  jQuery('#theteam-middles').animate({
		    left: '-503'
		  }, 1500, function() {
		    // Animation complete.
	  });
	
	  jQuery('#theteam-bottoms').animate({
		    left: '-508'
		  }, 2500, function() {
		    jQuery(".bio").hide();
			jQuery(".annika-bio").show();
	  });

	return false;
	
	});
	
	jQuery('.chris-team-link a').click(function() {
		jQuery("#team-member-names a").removeClass("active-staff");
		jQuery(this).addClass('active-staff');
		  jQuery('#theteam-heads').animate({
		    left: '-1015'
		  }, 2000, function() {
		    // Animation complete.
	  });
	
	  jQuery('#theteam-middles').animate({
		    left: '-1006'
		  }, 1500, function() {
		    // Animation complete.
	  });
	
	  jQuery('#theteam-bottoms').animate({
		    left: '-1015'
		  }, 2500, function() {
		    jQuery(".bio").hide();
			jQuery(".chris-bio").show();
	  });

	return false;
	
	});
	
	jQuery('.lou-team-link a').click(function() {
		jQuery("#team-member-names a").removeClass("active-staff");
		jQuery(this).addClass('active-staff');
		  jQuery('#theteam-heads').animate({
		    left: '-2040'
		  }, 2000, function() {
		    // Animation complete.
	  });
	
	  jQuery('#theteam-middles').animate({
		    left: '-2052'
		  }, 1500, function() {
		    // Animation complete.
	  });
	
	  jQuery('#theteam-bottoms').animate({
		    left: '-2056'
		  }, 2500, function() {
		    jQuery(".bio").hide();
			jQuery(".lou-bio").show();
	  });
	
	return false;
	
	});
	
	jQuery('.leigh-team-link a').click(function() {
		jQuery("#team-member-names a").removeClass("active-staff");
		jQuery(this).addClass('active-staff');
		  jQuery('#theteam-heads').animate({
		    left: '-793'
		  }, 2000, function() {
		    // Animation complete.
	  });
	
	  jQuery('#theteam-middles').animate({
		    left: '-787'
		  }, 1500, function() {
		    // Animation complete.
	  });
	
	  jQuery('#theteam-bottoms').animate({
		    left: '-793'
		  }, 2500, function() {
		    jQuery(".bio").hide();
			jQuery(".leigh-bio").show();
	  });
	
	return false;
	
	});
	
	jQuery('.tim-team-link a').click(function() {
		jQuery("#team-member-names a").removeClass("active-staff");
		jQuery(this).addClass('active-staff');
		  jQuery('#theteam-heads').animate({
		    left: '-245'
		  }, 2000, function() {
		    // Animation complete.
	  });
	
	  jQuery('#theteam-middles').animate({
		    left: '-244'
		  }, 1500, function() {
		    // Animation complete.
	  });
	
	  jQuery('#theteam-bottoms').animate({
		    left: '-248'
		  }, 2500, function() {
		    jQuery(".bio").hide();
			jQuery(".tim-bio").show();
	  });
	
	return false;
	
	});
	
	jQuery('.nick-team-link a').click(function() {
		jQuery("#team-member-names a").removeClass("active-staff");
		jQuery(this).addClass('active-staff');
		  jQuery('#theteam-heads').animate({
		    left: '-1295'
		  }, 2000, function() {
		    // Animation complete.
	  });
	
	  jQuery('#theteam-middles').animate({
		    left: '-1285'
		  }, 1500, function() {
		    // Animation complete.
	  });
	
	  jQuery('#theteam-bottoms').animate({
		    left: '-1295'
		  }, 2500, function() {
		    jQuery(".bio").hide();
			jQuery(".nick-bio").show();
	  });
	
	return false;
	
	});
	
	jQuery('.sam-team-link a').click(function() {
		jQuery("#team-member-names a").removeClass("active-staff");
		jQuery(this).addClass('active-staff');
		  jQuery('#theteam-heads').animate({
		    left: '0'
		  }, 2000, function() {
		    // Animation complete.
	  });
	
	  jQuery('#theteam-middles').animate({
		    left: '0'
		  }, 1500, function() {
		    // Animation complete.
	  });
	
	  jQuery('#theteam-bottoms').animate({
		    left: '0'
		  }, 2500, function() {
		    jQuery(".bio").hide();
			jQuery(".sam-bio").show();
			
	  });
	
	return false;
	
	});
	
	/* The Work Section Fancy Stuff */
	
	jQuery('#web-work-button').click(function() {
		jQuery("#brand-work-button").removeClass("brand-active");
		jQuery("#print-work-button").removeClass("print-active");
		jQuery(this).addClass('web-active');
		
		jQuery("#thumbs-1, #thumbs-3").hide()
		jQuery("#thumbs-2").show()
		
		if(parseInt(jQuery(".album-wrapper:visible").position().left) == 0) {
			jQuery(".left-arrow").hide();
		} else {
			jQuery(".left-arrow").show();
		}
		
		$currentwidth = jQuery(".ngg-album").width() * jQuery(".ngg-album:visible").size()*-1;
		if(parseInt(jQuery(".album-wrapper:visible").position().left) > $currentwidth) {
			jQuery(".right-arrow").show();
		} else {
			jQuery(".right-arrow").hide();
		}
		
		return false;
	});
	
	jQuery('#print-work-button').click(function() {
		jQuery("#web-work-button").removeClass("web-active");
		jQuery("#brand-work-button").removeClass("brand-active");
		jQuery(this).addClass('print-active');
		
		jQuery("#thumbs-1, #thumbs-2").hide()
		jQuery("#thumbs-3").show()
		
		if(parseInt(jQuery(".album-wrapper:visible").position().left) == 0) {
			jQuery(".left-arrow").hide();
		} else {
			jQuery(".left-arrow").show();
		}
		
		$currentwidth = jQuery(".ngg-album").width() * jQuery(".ngg-album:visible").size()*-1;
		if(parseInt(jQuery(".album-wrapper:visible").position().left) > $currentwidth) {
			jQuery(".right-arrow").show();
		} else {
			jQuery(".right-arrow").hide();
		}
		
		return false;
	});
	
	jQuery('#brand-work-button').click(function() {
		jQuery("#web-work-button").removeClass("web-active");
		jQuery("#print-work-button").removeClass("print-active");
		jQuery(this).addClass('brand-active');
		
		jQuery("#thumbs-2, #thumbs-3").hide()
		jQuery("#thumbs-1").show()
		
		if(parseInt(jQuery(".album-wrapper:visible").position().left) == 0) {
			jQuery(".left-arrow").hide();
		} else {
			jQuery(".left-arrow").show();
		}
		
		$currentwidth = jQuery(".ngg-album").width() * jQuery(".ngg-album:visible").size()*-1;
		if(parseInt(jQuery(".album-wrapper:visible").position().left) > $currentwidth) {
			jQuery(".right-arrow").show();
		} else {
			jQuery(".right-arrow").hide();
		}
		
		return false;
	});
	
	/* onLoad for "The Work" - Set up first gallery */
	
	jQuery(function(){
		jQuery.ajax({
		url:"/wp-admin/admin-ajax.php",
		type:'POST',
		data: "id=" + 14 + "&action=ajax_a_gallery",
		 	success:function(response) {
				jQuery("#gallery").replaceWith("<div id='gallery'>" + response + "</div");
				
				/* Set up sub-image links based on number of images in the set */
				
				$imagecount = jQuery(".ngg-gallery-thumbnail-box");
				var holder = "";
				jQuery.each($imagecount, function() {
				holder = holder + "<a href='#' class='sub-image-link' rel='" + this['id'] + "'><img src='/wp-content/themes/fluid/images/thework/sub-image.png' alt='View another image'></a>";	
				});
				jQuery("#sub-image-countainer").replaceWith("<div id='sub-image-countainer'>" + holder + "</div");
				
			}
		});
	});
	
	/* Fancy hover effect when you roll over work thumbnails */
	
	jQuery(".ngg-thumbnail a").mouseenter(function(){
		$element = jQuery(this).parent().parent();
		$height = $element.height(); /* animate() won't play nice with an animation height of 100%. */
		$element.parent().animate({ height: $height}, 500) }).mouseleave(function() {
			$element.parent().animate({ height: '62' }) }); 
	
	/* Actions after you click on a thumbnail */
	
	jQuery(".ngg-thumbnail a").click(function(){
		$id = jQuery(this).attr('class');
		jQuery(function(){
			jQuery.ajax({
			url:"/wp-admin/admin-ajax.php",
			type:'POST',
			data: "id=" + $id + "&action=ajax_a_gallery",
			 	success:function(response) {
					jQuery("#gallery").replaceWith("<div id='gallery'>" + response + "</div");
					/* Set up sub-image links based on number of images in the set */
					
					$imagecount = jQuery(".ngg-gallery-thumbnail-box");
					var holder = "";
					jQuery.each($imagecount, function() {
					holder = holder + "<a href='#' class='sub-image-link' rel='" + this['id'] + "'><img src='/wp-content/themes/fluid/images/thework/sub-image.png' alt='View another image'></a>";	
					});
					jQuery("#sub-image-countainer").replaceWith("<div id='sub-image-countainer'>" + holder + "</div");
					
					/* Set up description text on thumbnail click */
					
					jQuery("#the-work-text").html(jQuery("#" + (jQuery(".sub-image-link:first").attr('rel') + " a")).attr('title'));
					
				}
			});
		});

		return false;
	});
	
	/* Change the image when you click on a 'sub-image' box */
	
	jQuery("#sub-image-countainer a").live("click", function(ev){
		jQuery(".ngg-gallery-thumbnail-box").css("z-index", "0");
		jQuery("#"+jQuery(this).attr('rel')).css("z-index", "2");
		/* Add description for this image! */

		jQuery("#the-work-text").html(jQuery("#" + jQuery(this).attr('rel') + " a").attr('title'));
		
		return false;
	});
	
	/* Right and left thumbnail switching buttons */
	
	if(parseInt(jQuery(".album-wrapper:visible").position().left) == 0) {
		jQuery(".left-arrow").hide();
	};
	
	$currentwidth = jQuery(".ngg-album").width() * jQuery(".ngg-album:visible").size()*-1;
	if(parseInt(jQuery(".album-wrapper:visible").position().left) > $currentwidth) {
		jQuery(".right-arrow").show();
	} else {
		jQuery(".right-arrow").hide();
	}


	
	jQuery(".left-arrow").click(function(e){
		e.preventDefault();
		if(parseInt(jQuery(".album-wrapper:visible").position().left) < 0) {
			jQuery(".album-wrapper:visible").animate({
				left: '+=525'
				}, 500, function() {
					if(parseInt(jQuery(".album-wrapper:visible").position().left) == 0) {
						jQuery(".left-arrow").hide();
					} else {
						jQuery(".left-arrow").show();
					}
					
					$currentwidth = jQuery(".ngg-album").width() * jQuery(".ngg-album:visible").size()*-1;
					if(parseInt(jQuery(".album-wrapper:visible").position().left) > $currentwidth) {
						jQuery(".right-arrow").show();
					} else {
						jQuery(".right-arrow").hide();
					}
					
			});
		}
	});
	
	jQuery(".right-arrow").click(function(e){
		e.preventDefault();
		$currentwidth = jQuery(".ngg-album").width() * jQuery(".ngg-album:visible").size()*-1;
		if(parseInt(jQuery(".album-wrapper:visible").position().left) > $currentwidth) {
			jQuery(".album-wrapper:visible").animate({
				left: '-=525'
				}, 500, function() {
					if(parseInt(jQuery(".album-wrapper:visible").position().left) == 0) {
						jQuery(".left-arrow").hide();
					} else {
						jQuery(".left-arrow").show();
					}
					
					$currentwidth = jQuery(".ngg-album").width() * jQuery(".ngg-album:visible").size()*-1;
					if(parseInt(jQuery(".album-wrapper:visible").position().left) > $currentwidth) {
						jQuery(".right-arrow").show();
					} else {
						jQuery(".right-arrow").hide();
					}
					
			});
		}
	});
	
	/* Homepage stuff */
	
	jQuery('#brainspill-home-button').mouseover(function() {
		jQuery(this).css("background-position", "0px -135px");
	});
	
	jQuery('#blog-home-button').mouseover(function() {
		jQuery(this).css("background-position", "0px -112px");
	});
	
	jQuery('#thework-home-button').mouseover(function() {
		jQuery(this).css("background-position", "0px -189px");
	});
	
	jQuery('#frontroom-home-button').mouseover(function() {
		jQuery(this).css("background-position", "0px -153px");
	});
	
	jQuery('#team-home-button').mouseover(function() {
		jQuery(this).css("background-position", "0px -157px");
	});
	
	/* Homepage movie */
	
	window.setTimeout("jQuery('#projector-off').hide(), jQuery('#projector-on').show()", 2300);
	
	window.setTimeout("jQuery('#home-bubble').show()", 3100);
	
	window.setTimeout("jQuery('#home-bubble').hide()", 3200);
	
	window.setTimeout("jQuery('#home-bubble').show()", 4000);
	
	window.setTimeout("jQuery('#home-bubble').hide()", 4100);
	
	window.setTimeout("jQuery('#home-bubble').show()", 4300);
	
	window.setTimeout("jQuery('#brainspill-home-button').fadeIn('fast')", 5200);
	
	window.setTimeout("jQuery('#blog-home-button').fadeIn('fast')", 5500);
	
	window.setTimeout("jQuery('#thework-home-button').fadeIn('fast')", 5800);
	
	window.setTimeout("jQuery('#frontroom-home-button').fadeIn('fast')", 6100);
	
	window.setTimeout("jQuery('#team-home-button').fadeIn('fast')", 6400);
	
	window.setTimeout("jQuery('#diving-lady').fadeIn(5000)", 7000);
	
	window.setTimeout("jQuery('#fluid-logo').fadeIn(3000)", 7000);
	
	window.setTimeout("jQuery('#the-pool').fadeIn(3000)", 7000);
	
	window.setTimeout("jQuery('#fluid-cam').fadeIn(3000)", 7000);
	
	window.setTimeout("jQuery('#homepage-copy').fadeIn(3000)", 7000);
	
	window.setTimeout("jQuery('.welcome-to-fluid').fadeIn(2000)", 7000);
	
	window.setTimeout("jQuery('#fluid-sweeper').fadeIn(3000)", 7000);
	
	/* Frontroom code */
	
	jQuery('#frontroom-home').click(function() {
		jQuery("#frontroom-about, #frontroom-contact").removeClass("frontroom-active");
		jQuery(this).addClass('frontroom-active');
		jQuery("#frontroom-about-copy, #frontroom-contact-copy").hide();
		jQuery("#frontroom-home-copy").show();
		return false;
	});
	
	jQuery('#frontroom-about').click(function() {
		jQuery("#frontroom-home, #frontroom-contact").removeClass("frontroom-active");
		jQuery(this).addClass('frontroom-active');
		jQuery("#frontroom-home-copy, #frontroom-contact-copy").hide();
		jQuery("#frontroom-about-copy").show();
		return false;
	});
	
	jQuery('#frontroom-contact').click(function() {
		jQuery("#frontroom-about, #frontroom-home").removeClass("frontroom-active");
		jQuery(this).addClass('frontroom-active');
		jQuery("#frontroom-about-copy, #frontroom-home-copy").hide();
		jQuery("#frontroom-contact-copy").show();
		return false;
	});
	
	
	/* Blog */
	
	jQuery('#older a').live('click', function(e){
		jQuery.scrollTo( {top: 3940, left: 680-jQuery(window).width()/2+480 }, {duration: 1500});
		e.preventDefault();
		var link = jQuery(this).attr('href');
		var pagenumber = parseInt(jQuery("#blog-content").attr('class'));
		pagenumber++;
		jQuery("#blog-content").attr('class', pagenumber);
		jQuery('#blog-content').load(link + pagenumber +' #blog #bubble-middle');			
	});
	
	jQuery('#newer a').live('click', function(e){
		jQuery.scrollTo( {top: 3940, left: 680-jQuery(window).width()/2+480 }, {duration: 1500});
		e.preventDefault();
		var link = jQuery(this).attr('href');
		var pagenumber = parseInt(jQuery("#blog-content").attr('class'));
		if(jQuery("#blog-content").attr('class') > 1) {
			pagenumber--;
		}
		jQuery("#blog-content").attr('class', pagenumber);
		jQuery('#blog-content').load(link + pagenumber +' #blog #bubble-middle');			
	});
	
	if(jQuery("#blog-content").attr('class') < 2) {
		jQuery("#newer").hide();
	} else {
		jQuery("#newer").show();
	}
	
});
