(function() {

if (document.location.protocol.indexOf('http') != -1) {
	google_analytics();
}

/**
 * Load jQuery and the necessary plugins and initialize.
 */
yepnope({
	load: 'http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js',
	callback: function() {
		//set_scroll_events();

		$('a[href=#touch]').click(function() {
			var target = $('#touch');

			// Hide visible target.
			if (target.is(':visible')) {
				target.fadeOut();
				return;
			}

			// Show target.
			target.css({
				"display": "table-cell",
				"width": 0,
				"padding": "20px 0px"
			}).animate({
				"width": 400,
				"paddingLeft": 40,
				"paddingRight": 40
			});
		});

		yepnope({
			load: [
				// Template engine
				'http://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js',

				// Social network funneler
				'js/jquery.funnel.js'
			],
			complete: function() {
				load_timelines();
			}
		});
	}
});

function google_analytics() {
	var _gaq = _gaq || [];
	_gaq.push(['_setAccount', 'UA-10764664-1']);
	_gaq.push(['_trackPageview']);

	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';
	var s = document.getElementsByTagName('script')[0];
	s.parentNode.insertBefore(ga, s);
}

/**
 * Makes the background images move around when the user scrolls.
 */
function set_scroll_events() {
	// Don't wait for the event, just poll scroll locations.
	window.setInterval(function() {
		$('#about').css({
			"backgroundPosition": ($(window).scrollTop() / 2) + 'px 0px' 
		});
	}, 20);
}

/**
 * Loads the timelines of twitter, delicious and tumblr.
 */
function load_timelines() {
	/**
	 * Load Twitter, Delicious timeline into small feed section.
	 */
	$('#timeline').funnel({
		"services": [{
			"name": 'twitter',
			"user": 'jeromche',
			"tmpl": '#tmpl_twitter',
			"max_items": 50
		}, {
			"name": 'delicious',
			"user": 'jeromche',
			"tmpl": '#tmpl_delicious',
			"max_items": 50
		}],
	});

	/**
	 * Load Tumblr into blog area.
	 */
	$('#blog').funnel({
		"services": [{
			"name": 'tumblr',
			"user": 'jeromche',
			"tmpl": {
				"regular": '#tmpl_tumblr_regular',
				"quote": '#tmpl_tumblr_quote',
				"photo": '#tmpl_tumblr_photo',
				"video": '#tmpl_tumblr_video'
			}
		}],
		"max_items": 10
	});
}

})();

