var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-11982886-1']);
_gaq.push(['_setAllowAnchor', true]);
	(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(document).ready(function($) {
	/////////////////////////////////////////////// UI / BOOTSTRAP //////////////////////////////////////////////////////////

	ui_bootstrap();
	
	// FIX SIDEBAR
	$('.widget_search').wrap('<div id="search"></div>').prepend('<div id="search-text">Search The Internetwork</div>');
	$('#mycategoryorder-3 .cat-item-304').remove();
	var n = 1;
	columnize('#info', 'a');
	columnize('#contributors', '.wpu-user');
	columnize('#mycategoryorder-3', '.cat-item');
	$('#sidebar').css({ 'left': 0 });

	var fullPageSet = 0;

	// HIDE LOADING ICON IN SINGLE VIEW
	$('body.single #loader').remove();
	
	// MOVE CONTRIBUTORS SIDEBAR ITEM TO THE TOP
	$('#text-4').before('<div id="contrib"></div>');
	$('#contributors').remove().clone().prependTo('#contrib');
	
	$('#contributors h2.widgettitle').wrap('<a href="#user/all">');
	
	// BROWSER SPECIFIC
	if ($.browser.safari) {
 		$('#searchform input[type=submit]').css({'position': 'relative', 'top': -3});
	}


	////////////////////////////////////////////// FUNCTION CALLS //////////////////////////////////////////////////////////
	
	// Start header fader
	headerFader();
	

	// CATEGORY > REWRITE LINKS TO #'s:
	linkRewrite('#mycategoryorder-3 a');
	linkRewrite('#newtagcloud a', 'tag');


	$('#newtagcloud a:odd').css({ 'text-decoration': 'underline' });


	// SINGLE VIEW
	if( $('body').hasClass('single') ) {
		gallerize();
		scrollBar();
	}
	
	// PAGER	

	// SEARCH AJAX
	fixSearchForm();

	var close = 0;

	///////////////////////////////////////////// FUNCTIONS //////////////////////////////////////////////////////////////
	/*
			term							meaning
			===========================		===================================================================
			bootstrap						set up pages on default page load
			entry							a box in the grid with a thumbnail and title to open a post
			post							a larger box with content that potentially scrolls and shows a gallery
			page							like a post but in Wordpress' pages: "static" pages, not blog entries/posts
			contributor						somebody posting to internetwork
			user							a contributors user ID number
			entry footer					share, navigate gallery, etc
			user profile					user info loaded with AJAX on top of usual content
			hash							the AJAX URL handler, i.e. #contributor/the-brothers-barton
			breadcrumb						the navigation bar under the header
			header							the logo and header images+fader
			scroll							custom AJAX scroll function for content containers such as div's
			zoom							AJAX windows for viewing larger versions of images (if available)
			modal window					AJAX window for sharing info, etc
			tracking						Google Analytics
			logging							Firebug debugging in Firefox as well as Inspector in Safari, etc
	
			function						purpose
			===========================		===================================================================
			ui_bootstrap					Set up default page view and related function calls, recyclable
			$(window).bind('hashchange'		When hash (#) changes, do stuff, i.e. load pages, with the BBQ plugin
				initPost						Set up a post (scrolling, gallery, etc)
			contributor2user				Put in a user ID to get the user name
			fullPage						For blog view/Q&A view, show massive post without entries
			scrollToTop						Scroll main browser window on post open
			makeRoomForPost					Move entry boxes out of the way and hide "empty" (gray) entry boxes
			fixEntryFooter					Set the entry footer in place
			closeEntry						Close button for posts
			readHash						See what page is open
			splitHash						Determine the fragments of the URL
			columnize						Fix up sidebar in 2 columns
			linkRewrite						Rewrites links like /post-name/ to #post/post-name for AJAX loading
			userProfile						Load or hide user profile
			gridPlaceholders				Handles "empty" gray entry boxes in grid
			breadcrumb						Handles the nav bar and the browser window title
				wrap							Wrap in HTML for formatting
				firstCap						Capitalise the first letter of each word
				findAuthor						Figure out who is being displayed
			showEntries						Show entries grid either as animation or instantly
			gallerize						Set up AJAX gallery
				rePad							Move text under gallery up or down depending on image height
			scrollBar						Set up post/page scrolling
			imageZoom						Handle image zooming from gallery
				zoomThis
					doTheZoom				for dynamic callback purposes
					center					
				closeZoomer
			updatePager						Handle the entries grid pagination (next, prev)
			modalWindow						Like image zoomer but for text, etc
			headerFader						Set up fading of images in site header (under the logo)
				cycleHeader						Animate it
			fixSearchForm					AJAXify Wordpress' search function
			trackClick						Google Analytics: Event
			trackPageview					Google Analytics: Pageview + Event
			jQuery.fn.log					Firebug (and equivalent) console logging

	*/
	//////////////////////////////////////////////////////////////////////////////////////////////////////
	
	function ui_bootstrap(callback)
	{
		$(this).log('======================= BOOT ================================');	

		$('.home .entry').hide();
		// unhide from .css
		$('.home #entries').css({ 'left': 0 });
	
		if(fullPageSet == 1) fullPage('close');	
	
		// ADD BLANK ENTRY PLACEHOLDERS FOR PAGES NOT ENTIRELY POPULATED
		gridPlaceholders();

		// HIDE ALL BUT FIRST CATEGORY IN ENTRIES VIEW
		$('.entry').each(function(){
			$(this).find('.post-categories li').not(':first').hide();
			// FIX GRAY BOXES IN ENTRIES WITHOUT IMAGES
			var cat = $(this).find('.entry-category').text();
			if(cat == 'Music') $(this).find('.no-thumb').addClass('music');
			if(cat == 'Video') $(this).find('.no-thumb').addClass('video');
			if(cat == 'Art') $(this).find('.no-thumb').addClass('text');
			else if(cat !== 'Music' && cat !== 'Video' && cat !== 'Art') $(this).find('.no-thumb').addClass('text');
		});
		$('.no-thumb').each(function(){
			var href = $(this).closest('.entry').find('.post-link').attr('href');
			$(this).wrap('<a href="'+href+'" class="no-thumb-link">');			
		});
	    
		
		// BREADCRUMBS
		breadcrumb();
				
    	// ENTRIES PAGER: rewrite pager links
		$('#page-next a, #page-prev a').each(function(){		
			updatePager($(this));
		});
    
        if(typeof(callback) == 'function') callback();        
	}	
	

	//////////////////////////////////////////////////////////////////////////////////////////////////////
	//																									//
	//								BBQ LOADING FUNCTION/S												//
	//																									//
	//////////////////////////////////////////////////////////////////////////////////////////////////////
	
	
	
	
		// give full entry the class which bbq loads into by default
		$('#full-entry').addClass('bbq-content');
  
  // Keep a mapping of url-to-container for caching purposes.
  var cache = {
    // If url is '' (no fragment), display this div's content.
    '': $('.bbq-default')
  };
  
  $(window).bind( 'hashchange', function(e) {
    
    // Get the hash (fragment) as a string, with any leading # removed. Note that
    // in jQuery 1.4, you should use e.fragment instead of $.param.fragment().
    var url = $.param.fragment();
    url2 = "/" + url.split('/')[1] + "/";
    
    var type = url.split('/')[0];
    var data = url.split('/')[1];
    var page = url.split('/')[2];
    if(typeof(type) == 'undefined') type = '';
    if(typeof(data) == 'undefined') data = '';
    if(typeof(page) == 'undefined') page = '';
    
	trackPageview(type, data, page);
    
	////////////////////////////////////////////////////////////////////////////////////////////////////      
    // ### LOAD: ALL POSTS ###
    if(url == '')
    {
    	if(close != 1)
    	{
			showEntries();
			close = 0;
		}
		$('#loader').hide();
		$('#full-entry').hide();
    }
    else
    {

	    // Remove .bbq-current class from any previously "current" link(s).
	    $( 'a.bbq-current' ).removeClass( 'bbq-current' );
	    // Hide any visible ajax content.
		$( '.bbq-content' ).children( ':visible' ).hide();
	    // Add .bbq-current class to "current" nav link(s), only if url isn't empty.
	    url && $( 'a[href="#' + url + '"]' ).addClass( 'bbq-current' );
	    
	    
	    ///////////////////////////////////
	    // IF CACHED
	    //////////////////////////////////
	    if ( cache[ url ] ) 
	    {
	      $('#full-entry').show();
	      //$('#loader').hide();
	      
	      // Since the element is already in the cache, it doesn't need to be
	      // created, so instead of creating it again, let's just show it!
	      cache[ url ].show().find('.entry').show();

	      var t = cache[ url ];
		  makeRoomForPost();
	      breadcrumb(t);
		  scrollToTop();	      		  
	    } 
		///////////////////////////////////
		// NOT CACHED, LOAD IT
		//////////////////////////////////
	    else
	    {
		      $('#loader').show();
	    
			  ////////////////////////////////////////////////////////////////////////////////////////////////////          
			  // 									POST & PAGE VIEWS
			  ////////////////////////////////////////////////////////////////////////////////////////////////////          
			  
		      if(type == 'post' && data != 'all' || type == 'page' || type == 'q-and-a')
		      {
  				  $('#loader').addClass('load-post');
			  	  $('#full-entry').show();
				  scrollToTop();
				  makeRoomForPost();
				  
		  	      var toLoad = url2 + ' .entry';		
			      cache[ url ] = $( '<div class="bbq-item"/>' )
			        .appendTo( '.bbq-content' )
			        .load( toLoad, function()
			        {
						gridPlaceholders(type);
						showEntries(type);

						var t = $(this);

			        	if( t.find('.gallery').length ) t.find('p img:eq(0)').not('.gallery p img').closest('p').hide();
						var g = t.find('.gallery img:first');
						
						function initPost() {
									t.find('img').css({ 'opacity': 1});
									if(type != 'q-and-a') scrollBar(t);
									imageZoom(t);
									breadcrumb(t);
									closeEntry(t);
									linkRewrite('#full-entry .category a');
									$('#loader').hide();
									if(type != 'q-and-a') 	t.hide().css({ 'left': 0 }).show('drop', { 'duration': 800, 'direction': 'right' });
									else 					t.css({ 'left': 0 }); //q&a
						}
						
						if(g.length && type != 'q-and-a') {
							// when gallery is loaded, if it exists
							var first = 0;
							$('img',this).imagesLoaded(function(){
								if(first != 1) {
									first = 1;
									gallerize(t, function(){
										initPost();
										t.find('.gallery-nav').show();
									});
								}
							});
						}
						else if(type == 'q-and-a') {
							fullPage('open', function(){
								initPost();								
							});
						}
						else {
							// no gallery
							initPost();
							t.find('.gallery-nav').hide();
						}

						fixEntryFooter(t);
					});
				  $('#entries').addClass('posted');
				  
		      } //end page
		      
			  ////////////////////////////////////////////////////////////////////////////////////////////////////
		      // 										ALL USERS
		      ////////////////////////////////////////////////////////////////////////////////////////////////////
		      
		      else if(type == 'user' && data == 'all' || type == 'contributor' && data == 'all')
		      {
					userGrid();
		      }
		      
		      
			  ////////////////////////////////////////////////////////////////////////////////////////////////////
		      // 										ENTRIES
		      ////////////////////////////////////////////////////////////////////////////////////////////////////
		      
		      else if( type == 'post' && data == 'all' && $('#entries').hasClass('not-all') == false && typeof(page) == 'undefined' )
		      {
					// if all entries already loaded, don't reload. show fast or slow depending on route
					$('.entry').css({ 'margin-right': 10 });
					if( $('#entries').hasClass('posted') ) 	showEntries('all-fast');	
		      		else 									showEntries();
					$('#full-entry').hide();		
					$('#entries').removeClass('all');      
					$('#loader').hide();
		      }
		      else {
	      			
	      			// move loader
					$('#loader').removeClass('load-post');
	
		  			//rewrite contributor calls to user id's
					if(type == 'contributor') { data = contributor2user(data); type = 'user'; }
					
					// show user info
					if(type == 'user' && data != 'all') userProfile('load', data);
					else userProfile('hide');
					
					if(type == 'search') 	var newEntries = '?s='+data+' #content';
					else					var newEntries = '?'+type+'='+data+'&page='+page+' .entry';
					
					$('#full-entry').hide();
					$('#entries').load(newEntries, function() {
						ui_bootstrap(function() {
							showEntries();
							breadcrumb($(this));
						});
					}).addClass('not-all');
					$('#loader').hide();
		      } 
		      //end entries	
            
      }//end "bbq not cached"
	}	
  });
  
  // Since the event is only triggered when the hash changes, we need to trigger
  // the event now, to handle the hash the page may have loaded with.
  $(window).trigger( 'hashchange' );
  
	
	
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//										END BBQ.........
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	

	function contributor2user(sel)
	{
		// contributor user id's
		var contributors = {
			'darren-sylvester': 27,
			'douglas-lance-gibson': 28,
			'ffixxed': 16,
			'jason-crombie': 11,
			'jeremy-wortsman': 15,
			'jonathan-zawada': 13,
			'joseph-allen-shea': 14,
			'karl-maier': 21,
			'kris-moyes': 17,
			'lyn-and-tony': 12,
			'melissa-loughnan': 18,
			'michael-kucyk': 29,
			'perks-and-mini': 26,
			'the-brothers-barton': 19,
			'thomas-jeppe': 10,
			'urchin': 23,
			'news': 31,
			'deanne-cheuk': 32,
			'cameron-allan-mckean': 34,
			'warren-taylor': 36,
			'rainoff': 37,
		}
		
		var id = contributors[sel];
		
		$(this).log('contributor2user: '+id);
		
		// return the number
		return id;
	}
	

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

	function fullPage(f, callback)
	{
		if(f == 'close')
		{
			// reset heights after q&a resize! (fix this!!!)
			$('#main').css({ 'height': 1390 });
			$('#pager').css({ 'position': 'relative', 'top': 0 });
			$('#page-prev').show();
			$('#full-entry').removeClass('fullPageSet');
			fullPageSet = 0;
		}
		else {
			//open
			fullPageSet = 1;
			$('#full-entry').show().addClass('fullPageSet');
			var inner = $('#full-entry .entry-inside').height() + 100;
			$('#full-entry').css({ 'height': inner });
			$('#full-entry .entry-content').css({ 'height': inner });
			$('#full-entry .entry-footer').hide();
			$('#pager').css({ 'position': 'relative', 'top': inner - 1406 });
			$('#main').css({ 'height': inner + 375 });
			$('#page-prev').hide();

			if(typeof(callback) == 'function') callback();
		}
	}
	
	//////////////////////////////////////////////////////////////////////////////////////////////////////

		
	function scrollToTop() {
		var m = $("#bread").offset().top;
		$('html, body').animate({
			scrollTop: m
		}, 1000);
	}

	//////////////////////////////////////////////////////////////////////////////////////////////////////
	
	function makeRoomForPost()
	{
		$('#entries .entry, #entries .entry-empty').addClass('all-boxes');
		$('#entries').css({ 'margin-top': 0 });
		$('#full-entry').css({ 'width': 360, 'height': 495, 'margin-left': 130 });
		$('#full-entry .entry').css({ 'width': 600 });
		$('.all-boxes:even').slice(0, 4).css({ 'margin-right': 400 });	
	}
	
	//////////////////////////////////////////////////////////////////////////////////////////////////////
	
	function fixEntryFooter(sel)
	{
		sel.find('.footer-nav-icon').click(function()
		{
			var id = $(this).attr('id');
			if(id == 'share' || id == 'send') { 
				var url = readHash();
				url = url.split('/');
				url = '/' + url[1] + ' .share';
				modalWindow('ajax', url);
			}
			else if(id == 'link') {
				var url = readHash();
				url = url.split('/');
				url = 'http://theinternetwork.com.au/' + url[1];
	
				modalWindow('local', '<div style="width: 200px; height: 50px;" class="share"><b>LINK</b><br/><br/>'+url+'</div>');
			}			
		});
	}
		
	//////////////////////////////////////////////////////////////////////////////////////////////////////
	
	function closeEntry(sel)
	{
		sel.find('h2.entry-title').after('<div class="close-entry">x</div>');
		$('.close-entry').click(function(e){
			
		    window.location.hash = '';
  			  		
  			// hide the window
			$('#full-entry').hide();
			$('.bbq-item').hide();
			
			// fix bbq current-entry
			$( 'a.bbq-current' ).removeClass( 'bbq-current' );
			
			// move back entries
			$('.entry').css({ 'margin-right': 10 }).show();

			// add two empties
			if($('.entry-empty:visible').length) for(i=0; i < 7; i++) { $('#entries').append('<div class="entry-empty">&nbsp;</div>'); }	

			// empties
			close = 1;
			
			// header and window title
			breadcrumb();
			
			if(fullPageSet == 1) fullPage('close');
		});
	}
	
	
	//////////////////////////////////////////////////////////////////////////////////////////////////////

	function readHash()
	{
		var url = '#' + $.param.fragment();
		return url;	
	}
		
	//////////////////////////////////////////////////////////////////////////////////////////////////////	
	
	function splitHash(thisHash, output) 
	{
			// split URL hash into type and data and log it
			if(typeof(thisHash) !== 'undefined')
			{
				var type = thisHash.substring(1, thisHash.length).split('/')[0];
				var data = thisHash.split('/')[1];
				var page = thisHash.split('/')[2];
				if(output == 'type') return type;
				else if(output == 'data') return data;
				else if(output == 'page') return page;
			}
			else $(this).log('SPLIT HASH > undefined');
	}


	//////////////////////////////////////////////////////////////////////////////////////////////////////
	
	function columnize(sel, children) 
	{
		// put half of elements inside of selection in another div on the side
					
		var sel2 = $(sel+' '+children);
		var cat_n = $(sel2).length;
		if (cat_n % 2 == 0) var cat_n2 = parseInt(cat_n/2);
		else 				var cat_n2 = parseInt(cat_n/2)+1;
				
		var cats_move = $(sel2).slice(cat_n2, cat_n);
		var cats_stay = $(sel2).slice(0, cat_n2);
		
		$(cats_move).wrapAll('<div class="col2" id="col2-'+n+'"></div>');
		$(cats_stay).wrapAll('<div class="col1" id="col1-'+n+'"></div>');
		
		$(sel+' '+children).before('<div class="sep">-</div>');
		var cats_height = ($('#col1-'+n).height());
		$('#col2-'+n).css({ top: (cats_height * -1) })
		$(sel).css({ 'height': cats_height });
		
		n += 1;
	}
	
	//////////////////////////////////////////////////////////////////////////////////////////////////////

	function linkRewrite(t, type)
	{
		$(t).each(function(){
			if(typeof(type) !== 'undefined')
			{
				// custom
				var href = $(this).attr('href').split('/');
				var size = href.length-2;
				$(this).attr('href', '#'+type+'/'+href[size]);				
			}
			else 
			{
				var href = $(this).attr('href').split('/');
				var size = href.length-2;
				$(this).attr('href', '#category/'+href[size]);
			}

		});
	}

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

	function userProfile(type, data)
	{
		// HIDE
		if(type == 'hide') {
			if($('#user-profile').is(':visible')) $('#user-profile').hide('blind', 500);
			$(this).log('USER PROFILE > Hide');
		}
		
		// LOAD
		if(type == 'load') 
		{
			profile = 1;
			var userToLoad = 'contributors/?uid='+data+' #wpu-profile';
			
			$('#user-profile').contents().hide('drop', 500)
			
			window.setTimeout(function(){
				$('#user-profile').load(userToLoad, function()
				{
					$('.profile-meta-wrapper li').each(function(){
						var t = $(this);
						var prefix = $(t).text().substr(0,7);
						if(prefix == 'http://') {
							var link = $(t).text().substr(7);
							$(t).html('<a href="'+$(this).text()+'" target="_blank">'+link+'</a>');
						}
					});
					if($('#user-profile').is(':hidden')) $('#user-profile').show('blind', 500);
					else $('#user-profile').contents().show('drop', {
						duration:500,
						direction: 'right'
					});
					breadcrumb();
					$(this).log('USER PROFILE > Show');				
				});
			},200);

		}
	}
	
	//////////////////////////////////////////////////////////////////////////////////////////////////////	
			      	////////////// SHOW USER GRID FRONT PAGE ////////////////////
			      	
	function userGrid(f)
	{
			var not_entries = 1;
			
			$('#full-entry').hide();
			userProfile('hide');
			
			var contributors = 'contributors/ #main .entry-content';
		
			$('#entries').load(contributors, function()
			{
				$('#entries .wpu-user').hide();

				$('#loader').fadeOut(400);

				$('.entry-content .wpu-avatar').height(110);

				$('.entry-content .wpu-id, .entry-content .wpu-updated').hide();
				$('.entry-content .wpu-user').hover(function(){
					var t = $(this);
					$(this).find('.wpu-id').show();
					$(this).find('.wpu-updated').show();
					$(t).find('.wpu-avatar').animate({ 'height': 55 }, { easing: 'easeOutQuart', duration: 1000 });
					$(t).find('.wpu-avatar img').css({ 'position':'relative' }).animate({ 'top': -15}, { easing: 'easeOutQuart', duration: 1000 });
				},function(){ 
				//unhover
					var t = $(this);
					var t2 = $('.entry-content .wpu-user');
					$(t).find('.wpu-avatar').animate({ 'height': 110 }, { duration: 500, easing: 'easeOutSine', complete: function(){
						$(t).find('.wpu-id').hide();
						$(t).find('.wpu-updated').hide();							
					}});
					$(t).find('.wpu-avatar img').animate({ 'top': 0 }, { easing: 'easeOutSine', duration: 500 });
				});
				
				// fix links (broken worpress-users plugin?)
				$('.entry-content .wpu-avatar a').each(function(){
					var realHref = $(this).closest('.wpu-user').find('.wpu-id a').attr('href');
					$(this).attr('href', realHref);
				});
				
				
				// ALL USERS UI BOOT
				breadcrumb();

				// SHOW USERS ONE BY ONE
				var i = 0;
				gridPlaceholders();
				
				// set up new container
				$('#entries .entry-inside').after('<div class="entry-inside2" />');
				
				// what order?

				/*
				ffiXXed					4
				Jason Crombie			5
				Jeremy Wortsman			6
				Cameron					0
				Jonathan Zawada			7
				Douglas Lance Gibson	3
				Joseph Allen Shea		8
				Karl Maier				9
				Perks and Mini			14
				Darren Sylvester		1
				Kris Moyes				10
				Lyn and Tony			11
				Michael Kucyk			13
				Melissa Loughnan		12
				Deanne					2
				The Brothers Barton		15
				Thomas Jeppe			16
				Urchin					17
				Warren Taylor
				Rainoff
				*/
						//4,5,6,0,7,3,8,9,14,1,10,11,13,12,2,15,16,17
				var newOrder = 
					[
						0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19
					];

				// after which to place blanks
				var blankAfter = [ 1, 8, 10, 17 ];
				//var blankAfter = [ 0, 1, 4, 12, 15, 16 ];
				
				// assign order
				for(k=0;k<newOrder.length;k++)
				{
					$('#entries .entry-inside .wpu-user:eq('+(newOrder[k])+')').attr('id', 'order'+k);
				}
				
				// move to entry-inside2 in new order
				var e = 0;
				for(i=0;i<newOrder.length;i++)
				{								
					$('#entries .entry-inside #order'+i).appendTo('.entry-inside2');
					
					if( i == blankAfter[e] ) {
						$('.entry-inside2').append('<div class="entry-empty">&nbsp;</div>');
						removeEmpty();
						e += 1;
					}
					
					if( i == (newOrder.length/2)-1 ) { // <------ where to place the black VIEW ALL square
						var msg = "VIEW ALL ENTRIES";
						$('.entry-inside2').append('<div class="entry-empty2" id="mid"><br/><br/><br/><br/><a href="#post/all" class="view-all-entries-front">'+msg+'</a></div>');
						var blackPlacement = i;
						removeEmpty();
					}
				}
				
				var emptiesLeft = $('.entry-empty').length -1;
				$('.entry-empty').slice(emptiesLeft-15, emptiesLeft).remove();
					
				showOneByOne();

				function showOneByOne()
				{	
					var i = 0;
					$('#entries .entry-inside2 .wpu-user').each(function(){
						var t = $(this);
						var time = i * 100;
															
						window.setTimeout(function(){
							removeEmpty();
							$(t).fadeIn(1000);
						}, time);	

														
						i += 1;
					});
				}

				function removeEmpty(n)
				{	
					var last = $('.entry-empty').length;
					$('.entry-empty').slice(last-1, last).remove();
				}

				window.setTimeout(function(){
					$(this).log('BLACK SQUARE > ' + i);
					$('#mid').animate({ backgroundColor:'#000000', color: '#FFFFFF' },1000);
					$('#mid a').css({ color: '#FFFFFF' },1000)
				}, (100 * blackPlacement));
			});
	}
	////////////////////////// END USER FRONT PAGE ///////////////////

	
	//////////////////////////////////////////////////////////////////////////////////////////////////////
	
	function gridPlaceholders(option)
	{
		var total = 40;
		$('.entry-empty, .entry-empty2').remove();
		for(i=0; i < total; i++) { $('#entries').append('<div class="entry-empty">&nbsp;</div>'); }	
		$('.entry-empty').show();
	}
	

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

	function breadcrumb(sel)
	{
		var hash = readHash();
		var type = splitHash(hash, 'type');
		var data = splitHash(hash, 'data');
		var page = splitHash(hash, 'page');
		var sep = '<div class="bread-sep">&nbsp;</div>';
		var home = "<a href='#post/all'>The Internetwork</a>";

		var hashType = type;

		if(type == 'post' && data != 'all') { type = findAuthor(); var a = 1 }
		if(data == 'all') { type = 'all'; data = ''; }

		var typeNice = type;	

		// CAPS
		type = firstCap(type);
		data = firstCap(data);
		
		// EXCEPTIONS
		if(type == 'Ffixxed') type = 'ffiXXed';


		// BUILD BROWSER WINDOW TITLE
		var TITLE = "The Internetwork";
		if(type != '' && type != 'All' && type != 'Page') TITLE = type + " | " + TITLE;
		if(data != '') TITLE = data + " | " + TITLE;
		document.title = TITLE;

		
		// BUILD BREADCRUMB
		if(a == 1) type = '<a href="#contributor/'+ typeNice +'">'+ type +'</a>';
		var BREAD = wrap(home) + sep;
		if(type != '' && type != 'Page') BREAD = BREAD + wrap(type) + sep;
		if(hashType != 'post') BREAD = BREAD + wrap(data);

		// replace it
		$('#breadcrumbs').replaceWith('<div id="breadcrumbs">'+BREAD+'</div>');		
		
		// functions
		function wrap(string) { return '<div class="breadcrumb">'+string+'</div>'; }	
		function findAuthor(sel) {
			if( $('.bbq-current').length ) {			
				var classes = $('.bbq-current').closest('.entry').attr('class');
				if(typeof(classes) == 'undefined') return '';
				else {
					var author = classes.split(' ')[1].substr(7);
					return author;
				}
			}
			else return '';
		}
		function firstCap(string) {
			if(typeof(string) != 'undefined')
			{
				var sA = string.split('-');
				var sB = new Array();
				for(i=0;i<sA.length;i++) sB[i] = sA[i].charAt(0).toUpperCase() + sA[i].substr(1);
				return sB.join(' ');
			}
			else return '';
		}
	}

	//////////////////////////////////////////////////////////////////////////////////////////////////////
	
	function findAuthor(type, data, sel)
	{
		if(type == 'post')
		{
			var author = sel.find('.entry-footer .author').text();
			var href = $('#contributors').find('a:contains("'+author+'")').attr('href');
			link = author;
			return link;
		}
		else if(type == 'user') 
		{
			var author = sel.find('#user-profile .profile-name').text();
			return author;						
		}
		else return "Error: Couldn't find author!";
		
	}
	if(typeof(type) == 'undefined') var type = 'undefined';
	if(typeof(data) == 'undefined') var data = 'undefined';
	$(this).log('FIND AUTHOR > type: '+type+', data: '+data);
	
	//////////////////////////////////////////////////////////////////////////////////////////////////////

	function showEntries(type)
	{
		if(type == 'post' || type == 'page') 
		{			
			// SHOW ENTRIES INSTANTLY AND HIDE 12 MORE THAN USUAL
			$('.entry').show();
			var entries = $('.entry').not('#full-entry .entry').length;
			var empties = $('.entry-empty').length;
			var postSize = 12;
			var excess = empties - entries - postSize;

			if(excess < 1)
			{
				$('.entry-empty').remove();
				$('.entry').not('#full-entry .entry').slice(28, entries).hide();
			}
			else {
				$('.entry-empty').slice(excess-4, empties).remove();
			}
			
		}
		else if(type == 'all-fast')
		{
			// Like above but without the post.
			$('.entry').show();
			var entries = $('.entry').not('#full-entry .entry').length;
			var empties = $('.entry-empty').length;
			var postSize = -2;
			var excess = empties - entries - postSize;

			if(excess < 1)
			{
				$('.entry-empty').remove();
			}
			else {
				$('.entry-empty').slice(excess-2, empties).remove();
			}
		
		}
		else 
		{	
			// SHOW ONE BY ONE, ANIMATEDLY. REMOVE EMPTIES ONE BY ONE.
			var i = 0;
			$('.entry').not('#full-entry .entry').each(function(){
				var t = $(this);
				var time = i * 80;
	
				window.setTimeout(function(){
					var last = $('.entry-empty').length;
					$('.entry-empty').slice(last-1, last).remove();

					$(t).fadeIn(1000);
				}, time);
				i += 1;
			});
		}
		$(this).log('SHOW ENTRIES > One by one');
	}
	
	//////////////////////////////////////////////////////////////////////////////////////////////////////
	
	function gallerize(sel, callback) 
	{		
	
		// set up
  		sel.find('.gallery-pager').hide();
//		if( sel.find('.gallery').length ) sel.find('p img:eq(0)').not('.gallery p img').closest('p').hide();
/* 		sel.find('.gallery').css({ 'opacity': 0 }); */
		
		sel.find('.gallery-item img').each(function(){
			var gH = $(this).height();
			if(gH > 360) $(this).closest('.gallery-item').css({ 'width': 360, 'height': 360, 'overflow': 'hidden' });
		});
	
		// inside
		sel.find('.gallery').wrap('<div class="gallery-wrapper">');
		
		var wrapperWidth = 0;
		var tallest = 0;
		var img_n = 0;
		
		// set width for sliding
		sel.find('.gallery-item').each(function(){
			var imgWidth = $(this).width();
			var imgHeight = $(this).height();
			if(imgHeight > tallest) tallest = imgHeight;
			wrapperWidth += imgWidth;
			img_n += 1;
		});
		
		if(img_n > 0)
		{
			sel.find('.gallery').width(wrapperWidth+100)
			sel.find('.gallery-row, .gallery-wrapper')
	
			// create navigation
			sel.find('#tot-img').html(img_n);
			sel.find('.gallery-pager').fadeIn(1000);
			
			var move = 0;
			
			// navigation behaviour
			$('.gallery-nav .next, .gallery-nav .prev').click(function(){
				var direction = $(this).attr('class');
				if(direction == 'next') {
					var item = $(this).closest('.entry').find('.gallery-item');
					scroll(item, 'next');
				}
				else if(direction == 'prev') {
					var item = $(this).closest('.entry').find('.gallery-item');
					scroll(item, 'prev');
				}
			});
		}
		
		// init padding for gallery and underlying content
		rePad(sel, 1, 'first');
		
		function scroll(t, direction)
		{
			var thisWidth = $(t).width();
			var n = parseInt(sel.find('.img_n').text());
			
			if(direction == 'prev')  {
				if(n > 1) move -= thisWidth;
				n -= 1;
				if(n < 1) n = 1;
			}
			else {
				move += thisWidth;
				n += 1;
				if(n > img_n) n = 1;
			}

			sel.find('.img_n').html(n);
			
			if(move >= wrapperWidth) move = 0;
			sel.find('.gallery').stop().animate({ 'right': move }, { easing: 'easeOutQuart', duration: 1000 });

			rePad(sel, n);
			
			$(this).log('GALLERY > Wrapper: '+wrapperWidth+', Moved: '+move);
			
			var hash = readHash();
			var type = splitHash(hash, 'type');
			var data = splitHash(hash, 'data');
			var page = splitHash(hash, 'page');
			//$(this).log('gallery '+ data+' '+ n)
			trackClick('gallery', data, n);

			
		}
			
		if(typeof(callback) == 'function') callback();
	}
	
	//////////////////////////////////////////////////////////////////////////////////////////////////////
	
	function rePad(sel, n, f) {
		var row = sel.find('.gallery-wrapper').height();
		var item = sel.find('.gallery-item:eq('+(n-1)+')').height();
		var diff = row - item;
		
		if(f == 'first') sel.find('.gallery-wrapper').nextAll().css({'position':'relative', 'top': -diff });
		else sel.find('.gallery-wrapper').nextAll().css({'position':'relative'}).animate({ 'top': -diff }, { speed: 500, easing: 'easeOutQuart' });

		var nextall = sel.find('.gallery-wrapper').nextAll().html();
		if(nextall !== null) {
		}
		if(typeof(callback) == 'function') callback();
	}

	//////////////////////////////////////////////////////////////////////////////////////////////////////	
	
	function scrollBar(sel) 
	{
			// fix footer in place
			if(sel.find('.entry-footer').length > 0)
			{
				var f = sel.find('.entry-footer');
				var fpos = $(f).position();		
				if(typeof(fpos) !== 'undefined') $(f).css({ 'position': 'absolute', 'top': fpos.top });
			}
						
			var title = sel.find('.entry-title');
			var tpos = $(title).position();				
			
			// measure 
			var t = sel.find('.entry-content');
			var t2 = $('#full-entry');
			var w = $(t2).width();
			var h = $(t).height();
			var cH = sel.find('.entry-inside').outerHeight() * 1.03;
			var scale = h/cH;
			var sbH = (h*scale); // /2
	
			$(this).log('SCROLLBAR > outside: '+h+', inside: '+cH);
			
			// if contents are longer than container
			if( cH > h )
			{
				sel.find('.entry-content p').css({ 'padding-right': 10 });

				// re-measure after padding			
				cH = sel.find('.entry-inside').outerHeight() * 1.03;
				scale = h/cH;
				sbH = (h*scale); // /2
			
			
				var pos = 0;
			
				// mouse wheel scrolling
				sel.bind('mousewheel', function(event, delta) {

					var scroll = sel.find('.entry-inside');										
					var dir = delta > 0 ? 'u' : 'd';
					
					var nsH = -(cH-(h-20));
					
					pos = pos + (50 * (delta/3));
					if(pos > 0) pos = 0;
					if(pos < nsH) pos = nsH;
					
					if(pos < 1 && pos > nsH) 
					{
						scroll.css({ 'top': pos });
						
						var sbTp = -pos / -nsH;
						if(sbTp > 1) sbTp = 1;
						var sbT = (h-sbH) * sbTp;
						$(this).log(sbT)
						$(this).closest('.bbq-item').find('.scroll_bar').css({ 'top': sbT });
					}
					
					return false;
				});

			
				// create scrollbar
				sel.find('.entry-content').after('<div class="scroll_wrapper"><div class="scroll_bar">&nbsp;</div></div>');
				sel.find('.scroll_wrapper').css({ 'left': w-10, 'top': -h, 'height': h });
				sel.find('.scroll_bar').css({ 'height': sbH });
				
				// make scrollbar work
				sel.find('.scroll_bar').draggable({
					containment: 'parent',
					cursor: 'move',
					axis: 'y',
					drag: function(event, ui) {
						var move = ((ui.position.top / (h - sbH)) * (cH - h)) * -1;
						pos = move;
						sel.find('.entry-inside').css({ 'top': move });
					}
				});
			}
	}
	
	//////////////////////////////////////////////////////////////////////////////////////////////////////
	
	function imageZoom(t)
	{
		$('#full-entry .entry-content img').each(function(){
			var link = $(this).closest('a');
			var image = $(this);
			zoomThis(link, image);
		});
		var zoomT = t;
		
		function zoomThis(link, image, href) 
		{
			var t = link;
			if(typeof(href) == 'undefined') var href = $(t).attr('href');
			
			if(typeof(href) !== 'undefined')
			{
				var ext = href.substr(href.length-3, href.length);
				var ext = ext.toLowerCase();
				if(ext !== 'png' || ext !== 'jpg' || ext !== 'gif' || ext !== 'peg')
				{
					//not image already, find large version in url by removing resized size info at the end
					var href = image.attr('src');
					var href2 = href.split('-');
					var end = href2[href2.length-1];
					var ext = end.split('.')[1];
					var size = end.length+1;
					var end = href.length - size;
					var href = href.substring(0, end)+'.'+ext;
					//$(this).log(href)
					
					
				}

					var newHref = window.location.hash;
					$(t).attr('href', newHref);
					$(t).click(function(){
						doTheZoom();
					});
					
					function doTheZoom() {
//						var author = t.find('.entry-footer .author').text();
//						var title = t.find('h2.entry-title').text();
//						var info = title+'<br/>'+author+'<br/><br/>(Click to close)'
						 
//						$('#full-entry .image_zoomer').remove();
//						$('#full-entry').append('<div class="image_zoomer"><img src="/wp-content/themes/old-popular-yolk/loader-fff.gif" alt="Loading..." id="zoomer_loader" /><img id="zoomed_image" src="'+href+'" /><div class="zoomer_footer"><br/>'+info+'</div></div><div id="curtain">&nbsp;</div>');
						$('#full-entry').append('<div class="image_zoomer"><img src="/wp-content/themes/old-popular-yolk/loader-fff.gif" alt="Loading..." id="zoomer_loader" /><img id="zoomed_image" src="'+href+'" /></div><div id="curtain">&nbsp;</div>');

						
						$('#curtain').css({ 'opacity': 0}).animate({ 'opacity': 0.8 }, 750);
		
						$('#zoomed_image, .zoomer_footer').hide();
						center();
	
						$('#zoomed_image').load(function()
						{
							$('#zoomer_loader').fadeOut(500, function() { 
								$('#zoomer_loader').remove();
								center('animate');
							});
						});

						trackClick('Image zoom', href);
	
						function center(t)
						{
							var docH = $(window).height();
							var docW = $(document).width();
							if(t == 'animate') var img = $('.image_zoomer img');
							else var img = $('.image_zoomer');
	
							var zf = $('.zoomer_footer').height() / 1.5;
							
							var imgH = $(img).height();
							var imgW = $(img).width();
	
							var contain = 0.75;
							
							$(this).log('Img: '+imgW+'x'+imgH+'\nDoc: '+docW+'x'+docH);
								
							if(imgH > docH)
							{
								var scale = docH / imgH;
								imgH = imgH * scale * contain + zf;
								imgW = imgW * scale * contain;
								$(this).log('Scale:'+scale);
								$(img).width( $(img).width() * scale * contain );
							}
	
							var newTop = (docH / 2) - (imgH / 1.9);
							var newLeft = (docW / 2) - (imgW / 2);
							if(t == 'animate') 
							{
								$('.image_zoomer').css({ 'position': 'fixed' }).animate({ 'top': newTop, 'left': newLeft, 'width': imgW, 'height': imgH, 'opacity': 1 }, 600, function(){
									$('#zoomed_image, .zoomer_footer').fadeIn(600);
								});
							} 
							else 
							{ 
								$('.image_zoomer').css({ 'position': 'fixed', 'top': newTop, 'left': newLeft, 'opacity': 0 }).animate({ 'opacity': 1 }, 600);
							}
						}
		
						$('.image_zoomer, #curtain').click(function()
						{
							closeZoomer();
						});
						
						function closeZoomer()
						{
							$('.image_zoomer').fadeOut(500, function(){
								$('.image_zoomer').remove();
							});
							$('#curtain').animate({ 'opacity': 0 }, 500, function(){
								$('#curtain').remove();
							});
						}
					}
			}
	
		
		}
	}
		


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

	function updatePager(t)
	{
		$(t).show();
	
		var theHash = readHash();
		$(this).log('UPDATE PAGER > '+theHash);
	
		var entries_n = $('.entry').length;
	
		
		if(theHash != 'not set' && theHash != '#') {
			var type = splitHash(theHash, 'type');
			var data = splitHash(theHash, 'data');
			var page = splitHash(theHash, 'page');
		}
		else {
			var type = 'post';
			var data = 'all';
		}
		
		//rewrite contributor calls to user id's
		if(type == 'contributor')
		{
			// translate user id to name
			data = contributor2user(data);
			type = 'user';
		}


		if(typeof(page) == 'undefined') var page = 1;
		else page = parseInt(page);
		var nextPage = page - 1;
		var prevPage = page + 1;

		var href = '#'+type+'/'+data;		
		var d = $(t).parent().attr('id'); //direction
		d = d.substr(-4);
		
		if(d == 'next') {
			if(nextPage > 0) {
				$(t).show();
				href = href + '/'+nextPage;
				
				//also fix post/all links (breadcrumb already ok)
				$('#text-5 #col1-1 a, a#logo').attr('href', '#post/all/1');
				
			}
			else {
				$(t).hide();
				$('#text-5 #col1-1 a, a#logo').attr('href', '#post/all');
			}
		}
		else if(d == 'prev') {
			if(prevPage > 0) {
				if(entries_n >= 40 && type !== 'user'){
					$(t).show();
					href = href + '/'+prevPage;
				}
				else $(t).hide();
			}
			else $(t).hide();
		}
		
		$(t).attr('href', href);
	}

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

	function modalWindow(type, content)
	{
		if(typeof(info) == 'undefined') var info = '';
		if(typeof(type) == 'undefined') var type = 'local';
		
		if(type == 'ajax') 
		{
			$('#full-entry').append('<div class="modal_window"><img src="/wp-content/themes/old-popular-yolk/loader-fff.gif" alt="Loading..." id="zoomer_loader" /><div id="zoomed_content"></div><div class="zoomer_footer"><br/>'+info+'</div></div><div id="curtain">&nbsp;</div>');
			
			$('#curtain').css({ 'opacity': 0}).animate({ 'opacity': 0.8 }, 750);
		
			$('#zoomed_content, .zoomer_footer').hide();
			center();
		
			$('#zoomed_content').load(content, function(){
				$('#zoomer_loader').fadeOut(500, function() { 
					$('#zoomer_loader').remove();
					center('animate');
				});		
			});
		}
		if(type == 'local')
		{
			$('#full-entry').append('<div class="modal_window"><img src="/wp-content/themes/old-popular-yolk/loader-fff.gif" alt="Loading..." id="zoomer_loader" /><div id="zoomed_content"></div><div class="zoomer_footer"><br/>'+info+'</div></div><div id="curtain">&nbsp;</div>');
			
			$('#curtain').css({ 'opacity': 0}).animate({ 'opacity': 0.2 }, 750);
		
			$('#zoomed_content, .zoomer_footer').hide();
			center();
		
			$('#zoomed_content').html(content);
				$('#zoomer_loader').fadeOut(500, function() { 
					$('#zoomer_loader').remove();
					center('animate');
				});
		}
		
		
		
		trackClick('Modal window', content);
	
		function center(t)
		{
			var docH = $(window).height();
			var docW = $(document).width();
			if(t == 'animate') var container = $('.modal_window *');
			else var container = $('.modal_window');
	
			var zf = $('.zoomer_footer').height() / 1.5;
			
			var containerH = $(container).height();
			var containerW = $(container).width();
	
			var contain = 0.75;
			
			$(this).log('Container: '+containerW+'x'+containerH+'\nDoc: '+docW+'x'+docH);
				
			if(containerH > docH)
			{
				var scale = docH / containerH;
				containerH = containerH * scale * contain + zf;
				containerW = containerW * scale * contain;
				$(this).log('Scale:'+scale);
				$(container).width( $(container).width() * scale * contain );
			}
	
			var newTop = (docH / 2) - (containerH / 1.9);
			var newLeft = (docW / 2) - (containerW / 2);
			if(t == 'animate') 
			{
				$('.modal_window').css({ 'position': 'fixed' }).animate({ 'top': newTop, 'left': newLeft, 'width': containerW, 'height': containerH, 'opacity': 1 }, 600, function(){
					$('#zoomed_content, .zoomer_footer').fadeIn(600);
				});
			} 
			else 
			{ 
				$('.modal_window').css({ 'position': 'fixed', 'top': newTop, 'left': newLeft, 'opacity': 0 }).animate({ 'opacity': 1 }, 600);
			}
		}
	
		$('.modal_window, #curtain').click(function()
		{
			closeZoomer();
		});
		
		function closeZoomer()
		{
			$('.modal_window').fadeOut(500, function(){
				$('.modal_window').remove();
			});
			$('#curtain').animate({ 'opacity': 0 }, 500, function(){
				$('#curtain').remove();
			});
		}
	}

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


	function headerFader()
	{
		$(window).load(function()
		{
			$('#image-header').hide().css({ 'left': 0 }).fadeIn(1000);
			
	
			// centre vertically
			var viewH = 115;
			var viewW = 640;
			$('#image-header img').each(function(){
				var imgH = $(this).height();
				var imgW = $(this).width();
				var imgT = (imgH / 2) - viewH;
				var imgL = (viewW - imgW) / 2;
				$(this).css({ 'top': -imgT, 'left': imgL, 'opacity': 0 }).animate({ 'opacity': 1 },500);
				$('#image-header .wp-caption-text').css({ 'opacity': 0, 'left': 0 }).animate({ 'opacity': 1 },500);
			});
			// rotate
			var headImg = $('#image-header div');
			var headImgN = headImg.length;
			var cycleSpeed = 6000;
			var animSpeed = 1000;
			var left = headImgN + 1;
			function cycleHeader(f) {
				if(f == 'reset') {
					left = headImgN + 1;
					$('#image-header div').delay(cycleSpeed).fadeIn(animSpeed);
				}	
				left -= 1;
				if(left > 1) $('#image-header div:eq('+(left-1)+')').delay(cycleSpeed)
							.fadeOut(animSpeed, function(){
								cycleHeader(); });
				else cycleHeader('reset');
			}
			cycleHeader();
			
			// USERGRID in HEADER
			window.setTimeout(function(){
				$('#usergrid').hide().css({ 'left': 0 }).fadeIn(800);
					//.show('blind', 1000);
				$('#usergrid img').hover(function(){
/*
					if($(this).attr('src').substr(-5) != '0.png')
					{
*/
						var name = $(this).attr('alt');
						$('#usergrid-title').html(name);
/*
					}
					else {
						$('#usergrid-title').html('Contributors');	
					}
*/
				}, function(){
				});
				$('#usergrid').hover(function(){}, function(){
					$('#usergrid-title').html('Contributors');
				});			
			}, 1000);
		});

	}

	//////////////////////////////////////////////////////////////////////////////////////////////////////	
	
	function fixSearchForm() 
	{
		$('#searchform').submit(function() { // catch the form's submit event
		    $.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(){
		        	$('#full-entry').hide();
					$('#loader').show();
					var data = $('#s').attr('value');
					var url = window.location.pathname + '#search/'+data
					window.location.replace(url);
					trackClick('Search', data);
		        },
		        success: function(response) { // on success..
		            $('#entries').html(response); // update the DIV
			        ui_bootstrap();   
					// SHOW THEM
					$(this).log('SEARCH');
					$('#loader').fadeOut(400);
					showEntries();
		        }
		    });
		    return false; // cancel original event to prevent form submitting
		});
	}
	
	//////////////////////////////////////////////////////////////////////////////////////////////////////		
	/* These two functions used to be different, one for logging clicks as events, 
	and the other to log both event and pageview. Now they are the same.
	Look for references in the rest of the code for calls to these:

		-Change of URL (Ajax hash (#) path) with jQuery BBQ
		-No change of URL:
			-Clicking on an image to enlarge (zoom it)
			-Clicking on the post pager navigation to flick through image gallery
	
	Logging occurs in the console on these calls; i.e. Firebug, Web inspector, etc.
	 */

	function trackClick(type, data, page)
	{
		var log = '/'+type+'/'+data+'/'+page;
		_gaq.push(['_trackEvent', type, data, page]);
		_gaq.push(['_trackPageview']);
		//_gaq.push(['_trackPageview']);	
		$(this).log('GOOGLE ANALYTICS > '+log)
	}
	
	function trackPageview(type, data, page)
	{
		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

// mit license. paul irish. 2010.
// webkit fix from Oren Solomianik. thx!

// 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;
     }
  });
	$(this).log('imagesLoaded');
};
