$(document).ready( function(){
	var cache = [];
	$.extend( {
		trackPortfolio: function( p ){
			_gaq.push(['_trackPageview', p]);
			//log.info( "_gaq._trackPageview( '"+p+"' );" );
		},
		preloadImages: function(){
			var argsLen = arguments.length;
			
			for (var i = argsLen; i--;) {
				var img = document.createElement( 'img' );
				img.src = arguments[i];
				cache.push( img );
			}
		}
	} );
	
	$("a.outbound").click( function(){
		var action = $(this).attr( 'rel' );
		
		try {
			_gaq.push( ['_trackEvent', 'Social Media', 'Follow Link', action] );
			setTimeout('document.location = "' + $(this).attr( 'href' ) + '"', 100);
		}
		catch (err) {
			document.location = $(this).attr( 'href' );
		}
		
		return false;
	} );
	
	$("ul#crew a").each( function(){
		$(this).attr( 'title', $(this).attr( 'title').replace( 'Email', 'View' )+"'s Profile" );
	} ).click( function(){
		var link = $(this);
		var url = link.attr( 'rel' );
		$.ajax( {
			url:	'/profile/'+url,
			success:	function( data, textStatus, XMLHttpRequest ){
				$.modal( data, {
					overlayClose:	true,
					opacity:			50,
					overlayCss:		{
						backgroundColor: '#000'
					},
					containerCss:	{
						background:	'none',
						height:			302,
						width:			573
					}
				} );
				_gaq.push( ['_trackEvent', 'Profile', 'View', link.attr( 'title' ).replace( 'View ', '' ).replace( "'s Profile", '' )] );
				//log.info( 'Title: '+link.attr( 'title' ).replace( 'View ', '' ).replace( "'s Profile", '' ) );
			}
		} );
		return false;
	} );
	
	$.preloadImages( '/css/images/profile-bg.png', '/css/images/hook.png', '/css/images/email.png', '/css/images/email.gif' );
} );
