//jQuery(function( $ ){
//	/**
//	 * Most jQuery.localScroll's settings, actually belong to jQuery.ScrollTo, check it's demo for an example of each option.
//	 * @see http://flesler.demos.com/jquery/scrollTo/
//	 * You can use EVERY single setting of jQuery.ScrollTo, in the settings hash you send to jQuery.LocalScroll.
//	 */
//	
//	// The default axis is 'y', but in this demo, I want to scroll both
//	// You can modify any default like this
//	$.localScroll.defaults.axis = 'xy';
//	
//	// Scroll initially if there's a hash (#something) in the url 
//	$.localScroll.hash({
//		target: '#container', // Could be a selector or a jQuery object too.
//		queue:true,
//		duration:1500
//	});
//	
//	/**
//	 * NOTE: I use $.localScroll instead of $('#navigation').localScroll() so I
//	 * also affect the >> and << links. I want every link in the page to scroll.
//	 */
//	$.localScroll({
//		target: '#container', // could be a selector or a jQuery object too.
//		queue:true,
//		duration:1000,
//		hash:true,
//		onBefore:function( e, anchor, $target ){
//			// The 'this' is the settings object, can be modified
//		},
//		onAfter:function( anchor, settings ){
//			// The 'this' contains the scrolled element (#content)
//		}
//	});
//});
$(document).ready(function() {

//load functions	
	
	//hide featured work nav items until needed
	//$('#featuredWork').hide();
	
	//fade in the body
	$('.item').hide();
	$('.item').fadeIn(500);
	
	//fade in the nav
	$('#nav-container').hide();
	$('#nav-container').delay(1000).fadeIn(2500);
	
	//fade in the homepage content
	$('.contentText').hide();
	$('.contentText').delay(1000).fadeIn(2500);
	
	//show the nav for a few secs then slide it down
	$('#nav-container').delay(1500).animate({
		  bottom: -36,
		}, 1000, function() {
			// Animation complete.
		})/*end toggle off */
	
	$.localScroll.defaults.axis = 'xy';
	$.localScroll.hash({
		target: '#container', // Could be a selector or a jQuery object too.
		queue:true,
		duration:3500
	});
	
	$.localScroll({
		target: '#container', // could be a selector or a jQuery object too.
		queue:true,
		duration:1000,
		hash:true,
		onBefore:function( e, anchor, $target ){
			// The 'this' is the settings object, can be modified
		},
		onAfter:function( target ){
			// The 'this' contains the scrolled element (#content)
			location = '#' + ( target.id || target.name );
		}
	});

//event functions
	
	//click event to add selected class and send tracking
	$('a.panel').click(function () {
		$('a.panel').removeClass('selected');
		$(this).addClass('selected');
		current = $(this);
		var anchorName = $(this).attr('href');
		//send data to goggle on the click
		_gaq.push(['_trackEvent', 'Portfolio Events', 'Page Clicks', anchorName]);
		return false;
	});
	
	//window resize
	$(window).resize(function () {
		resizePanel();
	});
	
	//featured work hover to display
	/*$('a.featuredWork').hover(function () {
		$('#featuredWork').fadeIn();
	});
	
	//featured work mouse leave to hide
	$('#featuredWork').mouseleave(function () {
		$('#featuredWork').fadeOut();
	});*/
	
	//main navigation toggle animation
	$('a#navToggle').toggle(function() {
		$('#nav-container').animate({
		  bottom: 0
		}, 1000, function() {
			// Animation complete.
		  $('#featuredWork').fadeIn();
		  _gaq.push(['_trackEvent', 'Portfolio Events', 'Nav Toggle', 'Toggle On']);
		});
	  }, /*end toggle on */ function() {
		$('#featuredWork').fadeOut();
		$('#nav-container').animate({
		  bottom: -36,
		}, 1000, function() {
			// Animation complete.
			_gaq.push(['_trackEvent', 'Portfolio Events', 'Nav Toggle', 'Toggle Off']);
		});/*end toggle off */
	});//end main navigation toggle animation
	
}); // end document ready

function resizePanel() {
	width = $(window).width();
	height = $(window).height();

	mask_width = width * $('.item').length;
		
	$('#debug').html(width  + ' ' + height + ' ' + mask_width);
		
	$('#container, .item').css({width: width, height: height});
	$('#mask').css({width: mask_width, height: height});
	$('#container').scrollTo($('a.selected').attr('href'), 0);
}// end resizePanel



//set current hash index
var current_hash = window.location.hash;//

//set current hash
function check_hash() {
	//if the page doesn't have a has like the homepage - set the hash to #home
	if (current_hash == "" || current_hash == null) {
		window.location.hash = '#home'
	}
    if ( window.location.hash != current_hash ) {
        current_hash = window.location.hash;
        page_change( current_hash.substr( 1,  current_hash.length) );
    }
}

//run the hash check every 50ms
hashCheck = setInterval( "check_hash()", 50 );

//run the hash check every 50ms
function set_hash( new_hash ) {
    current_hash = new_hash
    window.location.hash = new_hash;
}

//change the page now that the window location has doesn't match the current hash index
function page_change() {
	$('#container').scrollTo(current_hash, 800);
}
