/*	 /)                          /)             /)         
	(/       _  _/_    _  _    _(/   _   _ _/_ (/   _  __ 
	/ )_(_(_/ )_(__  (_(_/ )_(_(_  (_/_(_(_(__/ )__(/_/ (_·
	                              .-/                     
	All rights reserved.         (_/      Copyright © 2009
 */

var t; /* For nav timeout */
var scrOfY = 0; /* For scroll-induced fades */
var op; /* For opacity state of thumbs */

jQuery(document).ready(function(){
		
	t = setTimeout("nav()",500);
	
	initRelateds();

	jQuery('dl.dropdown').hover(
		function(){ jQuery(this).find('dd').addClass('on'); },
		function(){ jQuery(this).find('dd').removeClass('on'); }
	);
	
	jQuery('input[type="text"], textarea').focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
	}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});
	
    fades(300); 
	
	jQuery('.work #header dl dd ul li.work dl dd ul li.industry').hover(
		function(){ jQuery('#header').addClass('industry'); jQuery(this).find('dt a').addClass('current'); },
		function(){ jQuery('#header').removeClass('industry');  jQuery(this).find('dt a').removeClass('current'); }
	);
	
	jQuery('.work #header dl dd ul li.work dl dd ul li.media').hover(
		function(){ jQuery('#header').addClass('media');  jQuery(this).find('dt a').addClass('current'); },
		function(){ jQuery('#header').removeClass('media'); jQuery(this).find('dt a').removeClass('current'); }
	);
	
	initGallery();

	jQuery('#header dl dd ul li dl dd ul li.media dd li:first').addClass('first');
	jQuery('#header dl dd ul li dl dd ul li.media dd li:last').addClass('last');
	jQuery('#header dl dd ul li dl dd ul li.industry dd li:first').addClass('first');
	jQuery('#header dl dd ul li dl dd ul li.industry dd li:last').addClass('last');
	

	var reasonNum = (Math.random()*(jQuery('.place .why dl dd ul li').length));
	jQuery('.place .why dl dd ul li').eq(reasonNum).addClass('current');
});

jQuery(window).scroll(function(){ fades(300); });

jQuery(window).resize(function(){ fades(1); });

function fades(timing){
	getScrollY();
	var h = jQuery(window).height();
	if (h < 700) { y = 420 } else { y = 580 }
	jQuery('.thumb').each(function(){
		var offset = jQuery(this).offset();
		var offset = offset.top - scrOfY;
		var shade = jQuery(this).find('img');
		shade.stop();
		if (offset < 180 || offset > y) {
			shade.animate({
				opacity: "0.1"
			}, timing);
		}
		else {
			shade.animate({
				opacity: "1"
			}, timing);
		}
	});
}

function nav() {
	if ( jQuery('body').hasClass('hg') ) {
		jQuery('#header li.work').animate({
			bottom: "102px"
		}, 1000 );
		jQuery('#header li.people').animate({
			bottom: "81px"
		}, 1000 );	
		jQuery('#header li.place').animate({
			bottom: "60px"
		}, 1000 );
		jQuery('#header li.hg').animate({
			bottom: "0"
		}, 1000, function(){
			jQuery('#header li.hg').animate({
				width: "720px"
			}, 1000);
		});
	} else if ( jQuery('body').hasClass('work') ) {
		jQuery('#header li.hg').animate({
			bottom: "102px"
		}, 1000 );
		jQuery('#header li.people').animate({
			bottom: "81px"
		}, 1000 );	
		jQuery('#header li.place').animate({
			bottom: "60px"
		}, 1000 );
		jQuery('#header li.work').animate({
			bottom: "0"
		}, 1000, function(){
			jQuery('#header li.work').animate({
				width: "736px"
			}, 1000);
		});
	} else if ( jQuery('body').hasClass('people') ) {
		jQuery('#header li.hg').animate({
			bottom: "102px"
		}, 1000 );
		jQuery('#header li.work').animate({
			bottom: "81px"
		}, 1000 );	
		jQuery('#header li.place').animate({
			bottom: "60px"
		}, 1000 );
		jQuery('#header li.people').animate({
			bottom: "0"
		}, 1000, function(){
			jQuery('#header li.people').animate({
				width: "695px"
			}, 1000);
		});	
	} else if ( jQuery('body').hasClass('place') ) {
		jQuery('#header li.hg').animate({
			bottom: "102px"
		}, 1000 );
		jQuery('#header li.work').animate({
			bottom: "81px"
		}, 1000 );	
		jQuery('#header li.people').animate({
			bottom: "60px"
		}, 1000 );
		jQuery('#header li.place').animate({
			bottom: "0"
		}, 1000, function(){
			jQuery('#header li.place').animate({
				width: "429px"
			}, 1000);
		});	
	}
}

function getScrollY() {
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
	}
}

function initGallery() {
	jQuery('.gallery-nav a').click(function(){
		var which = jQuery('.gallery-nav a').index(this);
		jQuery('.gallery-list li.current').fadeOut('medium',
			function(){
				jQuery('.gallery-list li').eq(which).fadeIn('medium', 
					function(){
						jQuery('.gallery-list li.current').removeClass('current');
						jQuery(this).addClass('current');
					});
		});
		jQuery('.gallery-nav a').removeClass('current');
		jQuery(this).addClass('current');
		return false;
	});
	
	jQuery('.gallery-nav li:eq(0)').addClass('one');
	jQuery('.gallery-nav li:eq(1)').addClass('two');
	jQuery('.gallery-nav li:eq(2)').addClass('three');
	jQuery('.gallery-nav li:eq(3)').addClass('four');
	jQuery('.gallery-nav li:eq(4)').addClass('five');
	jQuery('.gallery-nav li:eq(5)').addClass('six');
	jQuery('.gallery-nav li:eq(6)').addClass('seven');
	jQuery('.gallery-nav li:eq(7)').addClass('eight');
	jQuery('.gallery-nav li:eq(8)').addClass('nine');
	jQuery('.gallery-nav li:last').addClass('last');
	
}

function initRelateds() {
	jQuery('.thumb, .related').hover(
		function(){ jQuery(this).addClass('on'); },
		function(){ jQuery(this).removeClass('on'); }
	);
	
	jQuery('.related').each(function(){
		var shade = jQuery(this).find('img');
		shade.animate({
			opacity: "0.1"
		}, 1);
	});
	
}
