$(document).ready(function(){
						   
	$('body').addClass('js');
	$('.email').defuscate();
						   
	//set default easing					   
	jQuery.easing.def = "easeOutQuad";					   
	
	//decorative - add section name to footer
	var section = $('#site-nav .current a').text();
	$('<div class="site-name">' + section + '</div>').appendTo('#site-footer');
	
	//homethumbs
	$('.homethumbs a').hover(function(){
		$(this).stop().animate({height:'193px'});
	}, function(){
		$(this).stop().animate({height:'165px'});
	});
	
	//scroll read-about link
	$('.read-about').each(function(){
		var $target = $(this.hash), target = this.hash;
      	if (target) {
        	var targetOffset = $target.offset().top;
			
        	$(this).click(function(event) {
         	 	event.preventDefault();
          		$('html, body').animate({scrollTop: targetOffset}, 400);
        	});
      	}
    });
	
	//animate nav
	if ($('body').hasClass('portfolio-images') || $('body').hasClass('video')){
		var nav = $('#site-nav'),
			w = nav.outerWidth(),
			offset = w - 20;
		nav.css('left', '-' + offset + 'px').addClass('minimized');
		$('<div id="arrow"></div>').prependTo(nav);
		nav.hover (
			function() {
				setTimeout(function(){
					nav.stop(true).animate({ left: '0' +'px' }, 600);},200);
					$('#arrow').fadeOut(800);
			},
			function() {
				setTimeout(function(){
					nav.stop(true).animate({ left: '-' + offset + 'px' }, 
											500, 
											function(){ $('#arrow').fadeIn(700); }
											)
									},200);	
			}
			
		);
	}
	
	//give first thumb 'current' class
	$('.thumbnails li:first').addClass('current');
	
	//preloading images
	$('<div class="loader"></div>').appendTo('body').css('height','0').css('overflow','hidden');
	$('.thumbnails li').each(function(){
		var image = $(this).find('a').attr('href');
		$('<img src="' + image + '" />').prependTo('.loader');
	});
	
	//slideshows
	$('<div class="slide-nav"><div class="prev"></div><div class="next"></div></div>').appendTo('figure.main-image');
	
	function changeImage($_a){
		var dimensions = $_a.attr('class').split('x');
		$('.main-image img').fadeOut(700,function(){
												   $(this).attr({
														'src': $_a.attr('href'),
														'width':dimensions[0],
														'height':dimensions[1]
														});
												   }).fadeIn(600);
		$_a.parent('li').addClass('current').siblings().removeClass('current');
	}
	
	$('.thumbnails li a').mouseenter(function(){
		if (!($(this).parent().hasClass('current'))) {
			changeImage($(this));
		};
	}).click(function(e){
		e.preventDefault();
	});
	
	$('.next').click(function(){
		var $_current = $('.thumbnails li.current');
		$_current.next().length ? changeImage($_current.next().find('a')) : changeImage($('.thumbnails li:first a'));
	});
	
	$('.prev').click(function(){
		var $_current = $('.thumbnails li.current');
		$_current.prev().length ? changeImage($_current.prev().find('a')) : changeImage($('.thumbnails li:last a'));
	});

	
});

/*
 * Email Defuscator - jQuery plugin 1.0-beta2
 *
 * Copyright (c) 2007 Joakim Stai
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 *
 * Revision: $Id$
 *
 */

/**
 * Converts obfuscated email addresses into normal, working email addresses.
 *
 * @name defuscate
 * @param Boolean link If true, all defuscated email addresses will be turned into links, defaults to true (optional)
 * @param String find The regular expression used to search for obfuscated email addresses (optional)
 * @param String replace Replacement text for defuscating email addresses (optional)
 * @descr Converts obfuscated email addresses into normal, working email addresses
 */

jQuery.fn.defuscate = function( settings ) {
    settings = jQuery.extend({
        link: true,
        find: /\b([A-Z0-9._%-]+)\([^)]+\)((?:[A-Z0-9-]+\.)+[A-Z]{2,6})\b/gi,
        replace: '$1@$2'
    }, settings);
    return this.each(function() {
        if ( $(this).is('a[@href]') ) {
            $(this).attr('href', $(this).attr('href').replace(settings.find, settings.replace));
            var is_link = true;
        }
        $(this).html($(this).html().replace(settings.find, (settings.link && !is_link ? '<a href="mailto:' + settings.replace + '">' + settings.replace + '</a>' : settings.replace)));
    });
};
