var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-2507606-14']);
_gaq.push(['_setAllowAnchor', true]);
_gaq.push(['_trackPageview']);
	(function() {
		var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
		ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
		(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
	})();


/* jQuery.noConflict();   */
jQuery(document).ready(function($) {


	// IF BROWSER < IE7 :
	if (jQuery.browser.msie) {
		var ver = $.browser.version;
		if(ver < 8) {
			var msg = '<b>You are using an old web browser!</b><br><br>To view the site properly you might need to upgrade <br>Internet Explorer or use Firefox or Safari instead.<br><br><a href="http://www.getfirefox.com">Download Firefox</a> (free)<br><a href="http://www.apple.com/safari/download/">Download Safari</a> (free)<br><a href="http://www.microsoft.com/windows/internet-explorer/default.aspx">Download the latest Internet Explorer</a> (free)';
			$('body').append('<div style="position: fixed; top: 20px; left: 20px; width: 300px; height: 150px; background: white; padding: 10px;">'+msg+'</div>');
		}
	}

	function read_hash(str) 
	{
		var url = document.location.toString();
		if (url.match('#')) { // the URL contains an anchor
		  var theHash = '#' + url.split('#')[1];
			if(str == 'pages') {
				theHash = theHash.split('/pages/')[1];
			}
		};
		return theHash;
	}


	$('#shop-link').hover(function(){
		$('#shop-flat').hide();
		$('#shop-rollover').show();
	}, function(){
		$('#shop-flat').show();
		$('#shop-rollover').hide();	
	}).click(function(){
		//document.location = 'http://fat4.swappler.com/';
		document.location = 'http://fatstores.bigcartel.com/';
	});


	// incentive to move page
	function welcome() {
		var wT = ($(window).height()) - ($('#welcome').outerHeight() * 2);
		var wL = ($(window).width() / 2) -  ($('#welcome').outerWidth() / 2);
		$('#welcome').css({ 'top': wT, 'left': wL });	
		window.setTimeout(function(){
			$('#welcome').css({'opacity':0, 'display':'block'}).animate({'opacity':0.5},700);
			window.setTimeout(function(){
				$('#welcome').fadeOut(1000);
			}, 2000);
		}, 2000);
	}
	
	
	
	// append + and x to modal windows
	$('.h')
		.prepend('<span style="float: left; font-size: 13px; cursor: pointer; padding-left: 5px;" class="zoom">+</span>')
		.append('<span style="float: right; font-size: 10px; cursor: pointer; padding-right: 5px; margin-top: 2px;" class="close">x</span>');
	$('.close, .zoom').hover(function(){
		$(this).css({ 'color': 'black' });
	},function(){
		$(this).css({ 'color': 'white' });
	});


	// UI
	$('#designers p').wrapInner('<span/>');
	
	
	function toggleCurtain(speed, close) 
	{
		if(typeof(speed) == 'undefined') var speed = 600;
		
		// hide it
		if($('#curtain').is(':visible') == true) {
			$('#curtain').animate({ 'opacity': 0 }, { 
				duration: speed, 
				complete: function(){
					// hide it 4realz not just invisible
					$(this).css({ 'display': 'none' });
				}
			});
		}
		
		// show it
		else if(close !== 'close') {
			$('#curtain').css({ 'opacity': 0, 'display': 'block', 'z-index': z }).animate({ 'opacity': 0.6 }, 600);
		}
	}
		
	$('.close').click(function(){ 
		// toggle window (same as menu click)
		var t = $(this).closest('.entry-wrapper');
		toggleWindow(t, 'window');
		window.setTimeout(function(){
			toggleCurtain(600, 'close');
		},600);
	});
	
	$('.zoom').toggle(function(){
		//change [+] button to [-]
		$(this).html('&ndash;');
	
		// center
		var t = $(this).closest('.entry-wrapper');
	
		var name = t.attr('id');
		trackClick('Zoom', name);
		
		var tW = $(t).width();
		var tH = $(t).height();

		var pdH = $(document).height();
		var pdW = $(document).width();


		// enlarge		
		if( $(t).attr('id') !== 'collections' ) 
		{ 

				var widest = 0;
				$(t).find('.entry-content').children().each(function() {
					if( $(this).outerWidth() > widest) widest = $(this).outerWidth();
				});
			if($(t).attr('id') == 'journal') var newTW = widest * 2.5;
			else var newTW = widest + 50;


			
			var newTH = tH * 2;
			if(newTW > pdW) newTW = pdW * 0.6;
			if(newTH > pdH) newTH = pdH * 0.8;
		}
		else 
		{ //is lookbook, widen 50%
			var newTW = tW*1.5;
			var newTH = tH;			
		}
		
			
		var newTX = (pdW/2) - (newTW/2);
		var newTY = (pdH/2) - (newTH/2);

		$('.scrollWrapper').fadeOut(300);

		z += 1;
		$(t).css({'z-index': z+1}).animate({ 'top': newTY, 'left': newTX, 'width': newTW, 'height': newTH }, {

			duration: 600,
			complete: function(){
				// black out background
				toggleCurtain();
				// fix scrollbar
				var n = ($(this).closest('.entry-wrapper').prevAll().size())+1;
				vScroll(n, 'animate');
			}
		});
	}, function(){
		//change [-] back to [+]
		$(this).html('+');
		
		// make small again
		var t = $(this).closest('.entry-wrapper');

		if($(t).attr('id') == 'journal')
		{
			var oTW = $(t).width() / 2;
			var oTH = $(t).height() / 2;		
		}
		else if( $(t).attr('id') !== 'collections' )
		{
			var oTW = $(t).width() - 50;
			var oTH = $(t).height() / 2;
		}
		else
		{
			var oTW = $(t).width() * 0.75;
			var oTH = $(t).height();
		}		
		var n = $(this).closest('.entry-wrapper').prevAll().size()+1;

		$('.scrollWrapper').fadeOut(300);

		$(t).animate({
			'top': positionsY[n], 
			'left': positionsX[n],
			'width': oTW,
			'height': oTH
		}, {
			duration: 600,
			complete: function(){
				// hide black out
				toggleCurtain();			
				// fix scrollbar
				vScroll(n, 'animate');				
			}
		});
		
	});
	
	
	//////////////////////////////////////////////// FLIP
	
	$('#logo').click(function(){
/*
		signUp();
		var t = $(this);
		var name = t.attr('id');
*/
		trackPage('Page', 'sign up');
		document.location = 'http://eepurl.com/zCwB';
		
	});
	
	//Set up front and back rotation behaviour

	$('#logo').hover(function(){
		$(this).find('.wrapper').rotate3Di('flip', 300, { sideChange: mySide });		
	}, function(){
		$(this).find('.wrapper').rotate3Di('unflip', 300, { sideChange: mySide });
	});

	function mySide(front) {
		if(front) {
			$(this).find('.theBack').hide();
			$(this).find('.theFront').show();
		}
		else {
			$(this).find('.theBack').show();
			$(this).find('.theFront').hide();
		}
	}

	
	
	
	
	////////////////////////////////////////////////	
	
	

	// stacking z-index & draggability
	var z = 1;
	$('.entry-wrapper').not('#branding').draggable({ 
		handle: '.h',
		start: function(){ 
			z = z + 1; 
			$(this).css({ 'z-index': z });
			$(this).animate({ opacity: 0.4 },100); 
		},
		stop: function(){
			$(this).animate({ opacity: 1 },400);
			var t = $(this).position().top;
			var l = $(this).position().left;
			var n = $(this).prevAll().size()+1;
			positionsX[n] = l;
			positionsY[n] = t;
		}
	}).click(function(){ 
		z = z + 1; $(this).css({ 'z-index': z }); 
	});
	
	// resizable
	$('.entry-wrapper').not('#branding, #collections').resizable({
		start: function(){
			$(this).find('.scrollWrapper').fadeOut(300);
		},
		stop: function(){
			var n = ($(this).prevAll().size())+1;
			vScroll(n, 'animate');
		}
	});



	
	var theHash = read_hash();
	
	var use_horizontal = 0;



	///////////////////////////// MENU /////////////////////////////////////////////////
	

	var thePages = read_hash('pages');
	var pages = new Array();
	var page_matrix = new Array();
	
	$('.close-all').click(function(){
		$('.entry-wrapper').not('#branding').fadeOut(1000);
		document.location = '#/pages/';
	})
	
	function newLinkHashes() 
	{
		thePages = read_hash('pages');
		if(thePages == null)  { var thePages = '0^'; }
		else {
			pages = thePages.split('^');
			pages = pages.sort();
		}

		for(i=0; i<=9; i++) 				page_matrix[i] = 0;
		for(i=0; i <= pages.length; i++) 	page_matrix[pages[i]] = 1;
	}
	
	function setLinkHashes(t, type) 
	{

		if(type == 'window') {	var n = t;	}
		else 				 {	var n = ($(t).prevAll().size())-1;	}
		
//		if(n>3) n = n - 1;
		
		//reverse current
		if(page_matrix[n] == 1) {  	page_matrix[n] = 0; var set = 1; } 
		else { 						page_matrix[n] = 1; var set = 0; }
		
		//set containing link url
		var url = '';
		for(i=0; i<=8; i++) {
			if(page_matrix[i]) url += i+'^';
		}
		url = url.substring( 0, (url.length-1) )
		url = '#/pages/'+url;
		$(t).find('a').attr('href', url);

		if(type == 'window') {
			window.location = url;
		}

		//re-reverse for next iteration
		if(set == 1) page_matrix[n] = 1;
		if(set == 0) page_matrix[n] = 0;
		set = 0;
	}
	
	newLinkHashes();
	//menu link behaviour

	//randomize positions in an array that reads on open
	var positionsX = new Array();
	var positionsY = new Array();
	var window_n = 9;
	
		var menuW = $('#menu img:first').width();
		var step = 15;
		
	for(i=0;i<window_n;i++) {		

		if($('#menu').length)
		{
			//alternate
			if((i+1) % 2 == 0) {
				//L
				positionsX[i] = ($('#menu').offset().top/2) + (step * (i-1));
				positionsY[i] = ($('#menu').offset().top/2) + (step * (i-1));
			}
			else {
			 	//R
				positionsX[i] = (($(document).width()/2) + (menuW/2)) + (step * (i-1));
				positionsY[i] = ($('#menu').offset().top/2) + (step * (i-1));
			}
		}

	}
	$('.entry-wrapper').not('#branding').each(function(){
		var n = $(this).prevAll().size()+1;
		$(this).css({
			'top': positionsY[n], 
			'left': positionsX[n]
		});
	});
	
	
	var first = 0; //shows welcome modal
	$('#menu-over div').each(function()
	{	
		var t = $(this);
		setLinkHashes(t);
					
		$(this).find('a').click(function() {
			
			toggleWindow(t, 'menu');
			
			if(first == 0) {
				first += 1;
				welcome();
			}
		});	
	});


	////////////////////////// WINDOW TOGGLE /////////////////////
	function toggleWindow(t, type) {
		
		if(type == 'window') var n =($(t).prevAll().size())+1; 
		else var n = ($(t).prevAll().size());
		
		if( $('.entry-wrapper').eq(n).is(':visible') ) { 
			$('.entry-wrapper').eq(n).fadeOut(600); 
	 		
	 		if(n == '2') {
				autoScroll('stop');
				autoScroll('reset');
	 		}
		}
		else {				

//			if(n > 3) n = n - 1;
//			alert(n)

			function fixWin()
			{
				var rX = positionsX[n];
				var rY = positionsY[n];
				
				var wHeight = $('.entry-wrapper').eq(n).height() + rY;
				var docHeight = $(window).height();
				//alert(wHeight+' > '+docHeight)
				// var docH = $(document).height() - ($(this).position().top * 1);
				// if(winH > docH) $(this).height((docH - ($(this).position().top * 1)));

				/* if( (wHeight + rY) > docHeight ) { */
				if( wHeight > docHeight ) {
					var newHeight = docHeight - rY - (rY * 2);
					//alert(newHeight)
					$('.entry-wrapper').eq(n).css({ 'height': newHeight });
				}	
				 
				// show
				z += 1;
				
				$('.entry-wrapper').eq(n).css({ 
					'z-index': z, 
					'position': 'absolute', 
					'top': rY+'px', 
					'left': rX+'px' 
				}).fadeIn(600);
				vScroll(n);
				
				var name = $('.entry-wrapper').eq(n).attr('id');
				trackPage('Page', name);

	 		}

			if(n == '5') {
				// ajax load
				$('#loader').show();
				var w = $('.entry-wrapper').eq(n);

				if( w.find('.entry-content').html() == "<!--AJAX-->" ) 
				{
					var content = w.find('h2.entry-title a').attr('href') + ' .entry-content';
					$('#loader').show();
					w.find('.entry-content').load(content, function(){
						fixWin();
						$('#loader').hide();
					});
				}
			}
			else {
				fixWin();
			}
				 		
			if(n == '2') {
				fixLookbookText(); 
				autoScroll('start'); 
			}
		}
		
		if(type == 'window') n -= 1;
		newLinkHashes();
		
		if(type == 'window'){	setLinkHashes(n, 'window');	}
		else 				{	setLinkHashes(t);	}
	}


	function vScroll(sel, setting) 
	{
		var n = sel;
		var t = $('.entry-wrapper').eq(n);
		var h = $(t).height();
		var w = $(t).width();
		var inner = 0;
		$('.entry-wrapper:eq('+n+') .entry:visible').each(function(){
			inner += $(this).outerHeight()
		});
		
		if( $(t).find('.scrollWrapper').length ) var hasScroller = 1;
		else var hasScroller = 0;
		
		// if content is taller than modal window
		if(inner > h)
		{
			// if scroller exists, don't create another one
			if(hasScroller == 0) {
				$(t).find('.entry')
					.css({ 'padding': '0 20px 0 10px' })
				$(t).find('.entry:first')
					.after('<div class="scrollWrapper"><div class="scrollHandle"></div></div>');
				// set colour
				var headerColor = $(t).find('.h').css('background-color');
				$(t).find('.scrollHandle').css({'background': headerColor });
			}
			
			// set up size & behaviour of scroller
			
			var theScrollWrapper = $(t).find('.scrollWrapper');
			var theScrollWrapperHeight = (h-(24*2));

			if( t.find('.e div:first').hasClass('blog-nav') ) {
				var blognav = 37+15;
				h = theScrollWrapperHeight;
			}
			else blognav = 0;

			var handleHeight = (h / inner) * h;
			
			if(setting == 'animate') $(theScrollWrapper).fadeIn(400);
			else $(t).find(theScrollWrapper).show();
			
			$(theScrollWrapper)
				.css({ 'left': w-(10+4), 'top': (24+4+blognav), 'height': (h-(24*2)), 'opacity': 0.8 })
					.find('.scrollHandle')
					.css({ 'height': handleHeight })
					.draggable({
						containment: 'parent',
						cursor: 'move',
						axis: 'y',
						drag: function(event, ui) {
							var move = ui.position.top;
							var p = ( inner - (h-(24*3)) ) * ( move / ((h-(24*2)) - handleHeight) );
							$(t).find('.entry').css({ 'top': (p * -1) });
						}
					});
		}
		else {

		}
	}



	$('#menu-over img').css({
		'opacity': 0,
		'display': 'block'
	});

	var speed = 0;
	$('#menu-over img').hover(function(){
		$(this).css({
			'opacity': 1
		});
	}, function(){
		$(this).css({
			'opacity': 0
		});
	});


	////////////////// end menu //////////////////
	


	/* Change single post image size to largest */
	$('.single .entry-content img').each(function()
	{
		var url = $(this).attr('src');
		var alt = $(this).attr('alt');
		var classes = $(this).attr('class');
		var end = url.substring((url.length-4), url.length)
		url = url.split('').reverse().join('');
		var url_l = ((url.split('-')[0]).length)+1;
		url = url.split('').reverse().join('');
		url = url.substring(0,(url.length-url_l))+end;
		$(this).replaceWith('<img src="'+url+'" class="'+classes+'" alt="'+alt+'">');
	});

	
	
	// NEW LOOKBOOK THINGY
	// COLLECTIONS
	
	var container = $('#lookbook-container');
		container.width(99999);
	
	$('#collections .entry-content img').removeClass('alignleft');
	$('#collections .wp-caption-text').remove();
	$('#collections .wp-caption').contents().unwrap().wrap('<p></p>');
	var current = 0;
	var total_move = 0;
	
	// set lookbook-text sizes and move into place	
	function fixLookbookText() {
		$('#collections .lookbook img').each(function(){
			var t = $(this);
			var data = t.data('text');
			if(data != 1)
			{
				t.data('text', 1);
				var w = t.width();
				var h = t.height();
				var text = t.closest('.lookbook').find('.lookbook-text');
				$(this).log('w: '+w+'\n'+'h: '+h)
				text.width(w-20).height(h-10).css({ 'opacity': 0 }).show();
			}
		});
	}
	
	// collections extra image loader	
	function ajaxLoader(call)
	{
		// load one more image
		var t = $('#lookbook-container .unloaded:first');
		if(t.length) {
			var href = t.find('a').attr('href') + ' .entry-content';
			$('#lookbook-container .unloaded:first .entry-content').load(href, function(){
				t.removeClass('unloaded');
				var img = t.find('.entry-content img');
				var h = img.height() - 10;
				t.find('.lookbook-text').find('h1').css({ 'position': 'relative', 'top': -h });
				fixLookbookText();
			});
		}		
	}
	
	// scroll one image at the time and recall itself. also calls ajaxloader for additional images
	function autoScroll(call, callback)
	{
		if(call == 'start')
		{
			var mover = $('#lookbook-container');
			var img = $('.lookbook:eq('+current+') img');
			var total = $('.lookbook').not('.unloaded').length;
			if(current < total-1)
			{
				var w = img.width();
				total_move -= w;			
				mover.animate({ 'left': total_move }, w*20, 'linear', function(){
					current += 1;
					ajaxLoader();
					// hide first visible image and its text
					$('#lookbook-container .entry-content:visible').eq(0).hide().parent().find('h1').hide();
					autoScroll('start');
				});
			}
			else {
				// reset to start position
				mover.animate({ 'left': 0 }, 5000, function(){
					current = 0;
					autoScroll('start');
				});				
			}
		}
		else if(call == 'stop')
		{
			// stop animation
			$('#lookbook-container').stop();
		}
		else if(call == 'reset') {
			// reset to start position...?
		}
	}


		
	$('.lookbook').live('mouseover mouseout', function(event) {
	  if (event.type == 'mouseover') {
	    $('.lookbook-text', this).stop().animate({'opacity': 0.4}, 200);
	  } else {
	    $('.lookbook-text', this).stop().animate({'opacity': 0}, 500);
	  }
	});

	// resize setup
	var lb_h = $('#collections').outerHeight();
	$('#collections').resizable({
		ghost: false,
		maxHeight: lb_h,
	});

	
	
	//next prev collections
	var first = 0;
	$('.next2 img, .prev2 img').click(function(){
		autoScroll('stop');

		var left = $('#lookbook-container').position().left;
		var sel = $(this).closest('span').attr('class').substr(0,4);

		var nextID; //starting at 0
		var nextDist;
		var prevID;
		var prevDist;
		var currentID;
		
		var dist = new Array();
		$('#lookbook-container img').each(function(){
			var o = $(this).offset().left;
			dist.push(o)
		});
		
		var w = $(this).closest('.entry-wrapper').offset().left;
		var order = new Array();
		for(i=0; i<dist.length; i++)
		{
			var distFromWrapper = ((w-dist[i])*-1);
			order[i] = distFromWrapper;				
		}			
		
		var found = 0;
		for(i=0; i<order.length; i++)
		{
			if( order[i] >= 0 && found == 0)
			{
				var found = 1;
				currentID = i;
			}
		}
		
		// PREV
		if(sel == 'prev') {
			// show previously hidden image and its text
			$('#lookbook-container .entry-content').show()
			$('#lookbook-container h1').show();
				
			$('#lookbook-container').stop().animate({
				'left': '+='+(order[currentID-1] * -1)
			}, 500);
			current -= 1;
		}
		// NEXT
		else {
			if(first == 0) {
				first = 1;
				var nextID = currentID;
			}
			else {
				var nextID = currentID + 1;
			}
			$('#lookbook-container').stop().animate({
				'left': '+='+(order[nextID] * -1)
			}, 500);
			current += 1;	
			// load another image
			ajaxLoader();
			
		}

	});
	
	/////////////////////////////////////////////////////////////////////////


	// BLOG NEXT PREV
	$('.e .blog-nav img').click(function(e){
		var c = $(e.target);
		var sel = c.attr('class');
		if(sel == 'n') sel = 'next';
		else if(sel == 'p') sel = 'prev';
		var win = c.closest('.entry-wrapper').attr('id');
		var counter = c.closest('.e').find('span');
		var page = counter.attr('class');
		
		if(sel == 'next')
		{
			var nextPage = parseInt(page) + 1;
			var prevPage = parseInt(page);
		}
		else if(sel == 'prev')
		{
			var nextPage = parseInt(page);
			var prevPage = parseInt(page) -1;		
		}

		if(sel == 'next') var newPage = nextPage;
		else if(sel == 'prev') var newPage = prevPage;
		counter.attr('class', newPage);		

		var total = c.closest('.entry-wrapper').find('.data').attr('id');


		$('#loader').fadeIn(800);
		var t = c.closest('.entry-wrapper').find('.all-entry-content');
		t.fadeOut(500); 
		t.load('?'+win+'page='+newPage+' .'+win, function(){

				var name = win;
				trackPage('Page', name, newPage);

				//gallery
				tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
				imgLoader = new Image();// preload image
				imgLoader.src = tb_pathToImage;

			if(newPage > 1) $('.e .blog-nav .p').show();
			else $('.e .blog-nav .p').hide();
			if(newPage == total) $('.e .blog-nav .n').hide(500);
			else $('.e .blog-nav .n').show();

			$('#loader').fadeOut(500);
			Cufon.replace('h2', { fontFamily: 'CenturyGothic', fontWeight: '600'});
			var n = (c.closest('.entry-wrapper').not('#branding').prevAll().size())+1;

			t.fadeIn(200, function(){
				var winH = $(this).height();
				var docH = $(document).height()
				if(winH > docH) $(this).height((docH - ($(this).position().top * 2)));
			
				vScroll(n);
			});


		});

	});


	// PROJECTS
	
	$('#projects .entry-content').children().hide();
	$('#projects .entry-content').show().find('p:first').show().find('img').unwrap('a');



	// SIGN UP
	function signUp() 
	{
		toggleCurtain();
		
		if( $('#signup').is(':visible') ){
			$('#signup').fadeOut(1000);
			$('#curtain').css({ 'z-index': 0 });
		}
		else {
			var toLoad = '/mailchimp/?mailchimp=1 .entry-content';
			//var toLoad = 'http://eepurl.com/zCwB';
			$('#signup .form').load(toLoad, function(){
					// SEARCH AJAX
					/* $('#formBuilderSign_up').submit(function() { */ // catch the form's submit event
/*
					$('#mc_signup_form').submit(function() {
					    $.ajax({ // create an AJAX call...
					        data: $(this).serialize(), // get the form data
					        type: $(this).attr('method'), // GET or POST
					        url: $(this).attr('action'), // the file to call
					        beforeSend: function(){
					        },
					        success: function(response) { // on success..
								$('#signup .form').html('<div class="thanks">Thank you!</div>');
					        }
					    });
					    return false; // cancel original event to prevent form submitting
					});
*/
				Cufon.replace('h1', { fontFamily: 'CenturyGothic', fontWeight: '600'});
				$('#signup').fadeIn(1000);
				$('#curtain').css({ 'z-index': 999 });
			});
		}
	}
	$('#subscribe-close').click(function(){
		signUp();
	});

	/////////////////////////////////////////////////////////////////////////////////////////////
	// what to hide
	
	if(thePages == null) thePages = '';
	var pages = thePages.split('^');
	
	for(i=0; i < pages.length; i++) {
		var id = parseInt(pages[i])+1;
		$('.entry-wrapper').eq(id).addClass('dont-hide');
	}

	$('.entry-wrapper').not('#branding').each(function(){
		if( $(this).is('#branding') == false && $(this).hasClass('dont-hide') == false ) {
			$(this).hide();
		}
		else {
			$(this).show();
			$(this).each(function(){
				// check that windows visible are not too tall!
				var winH = $(this).height();
				var docH = $(document).height() - ($(this).position().top * 1);
				//alert(winH +' > '+docH)
				if(winH > docH) { 
					var newHeight = (docH - ($(this).position().top * 1));
					$(this).height(newHeight);  
					//var n = ($(this).prevAll().size())+1;					
					//vScroll(n);
				}
//				if( $(this).index() == 1 ) autoScroll('#lookbook-container', 'start');
				if( $(this).index() == 1 ) {
						fixLookbookText(); 
						autoScroll('start'); 
				}

				// journal
				if( $(this).index() == 4 ) {
					var w = $(this);
					var content = w.find('h2.entry-title a').attr('href') + ' .entry-content';
					w.find('.entry-content').load(content, function(){
						// fix height
						var winH = $(this).height();
						var docH = $(document).height();
						if(winH > docH) {							
							window.setTimeout(function(){
								w.height((docH - (w.position().top * 2)));
								var n = (w.prevAll().size())+1;					
								vScroll(n);
							}, 200);
						}
					});
				}

				if( $(this).is(':visible') ) {
					var n = ($(this).prevAll().size())+1;					
					vScroll(n);
				}
			});
		}
	});
	
	var loader = $('#loader');
	$(window).load(function(){
		loader.fadeOut(600);
	});
	
	//////////////////////////////////////////////////////////////////////////////////////////////////////
	
	function trackClick(type, data, page)
	{
		if(typeof(page) == 'undefined') var log = '/'+type+'/'+data;
		else var log = '/'+type+'/'+data+'/'+page;
		_gaq.push(['_trackEvent', type, data, page]);
//		$(this).log('GOOGLE ANALYTICS > '+log)
	}

	function trackPage(type, data, page)
	{
		if(typeof(page) == 'undefined') var log = '/'+type+'/'+data;
		else var log = '/'+type+'/'+data+'/'+page;
		_gaq.push(['_trackEvent', type, data, page]);
		_gaq.push(['_trackPageview']);
//		$(this).log('GOOGLE ANALYTICS > '+log)
	}
	
	//////////////////////////////////////////////////////////////////////////////////////////////////////	

	
});




//////////////////////////////////////////////////////////////////////////////////////////////////////	

// CONSOLE LOG FUNCTION
jQuery.fn.log = function (msg) {
	if(typeof(console) != 'undefined') console.log("%s: %o", msg, this);
	return this;
};

//////////////////////////////////////////////////////////////////////////////////////////////////////	

// $('img.photo',this).imagesLoaded(myFunction)
// execute a callback when all images have loaded.
// needed because .load() doesn't work on cached images

// callback function is passed the last image to load
// as an argument, and the collection as `this`

$.fn.imagesLoaded = function(callback){
  var elems = this.filter('img'),
      len = elems.length;
      
  elems.bind('load',function(){
      if (--len <= 0){ callback.call(elems,this); }
  }).each(function(){
     // cached images don't fire load sometimes, so we reset src.
     if (this.complete || this.complete === undefined){
        var src = this.src;
        // webkit hack from http://groups.google.com/group/jquery-dev/browse_thread/thread/eee6ab7b2da50e1f
        this.src = '#';
        this.src = src;
     }
  });
};


