if (window.navigator.userAgent.indexOf('iPhone') !== -1) {
	$(document).ready(function () {
		//add iPhone tags
		$('head').append('<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>');
		$('head').append('<meta name="apple-mobile-web-app-capable" content="yes" />');
		$('head').append('<link rel="apple-touch-icon-precomposed" href="/resources/images/iphone_icon.png" type="image/png" />');
		
		//add iPhone css
		$('head').append('<link rel="stylesheet" href="/resources/css/iphone.css" />');
		
		var articles = [];
		var count    = $('.last5 li:not(.all) a').size();
		var loaded   = 0;
		
		//function so slide list over and article out
		var goBack = function (div) {
			var div = div;
			$('ul').eq(0).removeClass('toLeft');
			div.removeClass('toView');
			$('header span.back').removeClass('show');
		};
		
		//function to slide article over and list out
		var showArticle = function (articleIndex) {
			var div = articles[articleIndex].div;
			$('header span.back').addClass('show').get(0).onclick = function () {
				goBack(div);
				return false;
			};
			$('ul').eq(0).addClass('toLeft');
			articles[articleIndex].div.show().addClass('toView');
			$('#iphone').height(articles[articleIndex].div.height() + 60);
		};
		
		//function to build list and articles
		var buildInterface = function () {
			$('body').addClass('iPhone');
			var iPhone = $('<div id="iphone"></div>');
			iPhone.append('<header><span class="title">Finley, I am.</span><span class="back">back</span></header>');
			var articleList = $('<ul></ul>');
			articleList.appendTo(iPhone);
			$.each(articles, function (i, article) {
				var i  = i;
				var li = $('<li><a href="#">'+article.subject+'</a></li>');
				li.find('a').click(function () {
					showArticle(i);
					return false;
				});
				articleList.append(li);
				article.div = $('<article>'+article.article+'</article>');
				article.div.hide().appendTo(iPhone);
			});
			iPhone.appendTo('body');
		};
		
		//get article list, and load articles
		$('.last5 li:not(.all) a').each(function (i) {
			if (!$(this).parent('li').hasClass('all')) {
				var href = $(this).attr('href');
				var i    = i;
				$.get(href, function (data) {
					var obj = {};
					obj.subject = $('section#blog article', data).eq(0).find('h2').eq(0).text();
					obj.article = $('section#blog article', data).eq(0).html();
					articles[i] = obj;
					loaded++;
					if (loaded === count) {
						buildInterface();
					}
				}, 'xml');
			}
		});
		
		//remove container
		$('#container').remove();
	});
}