function iPhoneListLinksAltRowColours(list, colour) {
	$$('#' + list + ' li').each(function(li, i) {
		if (0 != i % 2) {
			li.childElements().each(function(a) {
				a.setStyle('background-color: ' + colour + ';');
			});
		}
	});
}

function iPhoneCreateLinksListAjax(type) {
	var headingText = null;
	var ajaxContent = null;
	var subLinkHref = null;
	var subLinkText = null;
	var directory = null;
	switch (type) {
		case 'recentProjectsLinksList' : 
			headingText = 'Recent Project Examples';
			ajaxContent = rootPath + 'json/projectExamples.json';
			subLinkHref = rootPath + 'project-examples/';
			subLinkText = 'More Project Examples';
			directory = rootPath + 'project-examples/';
			break;
		case 'codeTechniquesLinksList' : 
			headingText = 'Recent Code Techniques';
			ajaxContent = rootPath + 'json/codeTechniques.json';
			subLinkHref = rootPath + 'code-techniques/';
			subLinkText = 'More Code Techniques';
			directory = rootPath + 'code-techniques/';
			break;
		case 'projectsLinksList' : 
			ajaxContent = rootPath + 'json/projectExamples.json';
			subLinkHref = rootPath + 'project-examples/';
			directory = rootPath + 'project-examples/';
			break;
			break;
		case 'codeLinksList' : 
			ajaxContent = rootPath + 'json/codeTechniques.json';
			subLinkHref = rootPath + 'code-techniques/';
			directory = rootPath + 'code-techniques/';
			break;
	}
	if (type == 'recentProjectsLinksList' || type == 'codeTechniquesLinksList') {
		$('headingOne').insert({
			before: '<h4 class="quickLinks">' + headingText + '</h4><ul class="quickLinks" id="' + type + '"></ul><div class="quickLinks"><a href="' + subLinkHref + '" title="' + subLinkText + '">' + subLinkText + '</a></div>'
		});
	} else {
		$('headingOne').insert({
			after: '<ul class="quickLinks" id="' + type + '"></ul>'
		});
	}
	new Ajax.Request(ajaxContent, {
		method: 'get',
		onSuccess: function(transport) {
			var items = transport.responseText.evalJSON();
			var numItems = items.length;
			items.each(function(it, i) {
				if (type == 'recentProjectsLinksList' && i < 2 || type == 'codeTechniquesLinksList' && i < 2) {
					$(type).insert('<li><a href="' + directory + items[(numItems - 1) - i].staticPage + '" title="' + items[(numItems - 1) - i].title + '"><img src="' + directory + 'images/thumb_iphone_' + ((numItems - 1) - i) + '_' + items[(numItems - 1) - i].image + '-01.jpg" alt="' + items[(numItems - 1) - i].title + '" width="108" height="108" /><h5>' + items[(numItems - 1) - i].h3 + '</h5><p>' + items[(numItems - 1) - i].date + '</p></a></li>');
				} else if (type == 'projectsLinksList' || type == 'codeLinksList') {
					$(type).insert('<li><a href="' + directory + items[(numItems - 1) - i].staticPage + '" title="' + items[(numItems - 1) - i].title + '"><img src="' + directory + 'images/thumb_iphone_' + ((numItems - 1) - i) + '_' + items[(numItems - 1) - i].image + '-01.jpg" alt="' + items[(numItems - 1) - i].title + '" width="108" height="108" /><h5>' + items[(numItems - 1) - i].h3 + '</h5><p>' + items[(numItems - 1) - i].date + '</p></a></li>');
				}
			});
			if (type == 'codeTechniquesLinksList') 
				$('codeTechniquesLinksList').previous().setStyle('margin-top: 17px;');
			if (type == 'projectsLinksList' || type == 'codeLinksList') 
				$$('#wrapper h1')[0].setStyle('margin-right: 1px; border-right: 1px solid #330; background-image: url(../images/iphone_h1_background_alt.gif);');
			if (type == 'projectsLinksList') 
				$('projectsLinksList').setStyle('margin-bottom: 5px;');
			if (type == 'codeLinksList') 
				$('codeLinksList').setStyle('margin-bottom: 5px;');
			iPhoneListLinksAltRowColours(type, '#757149');
		}
	});
}

function setIntroLinksList() {
	iPhoneCreateLinksListAjax('recentProjectsLinksList');
	iPhoneCreateLinksListAjax('codeTechniquesLinksList');
}
function setProjectsLinksList() {
	iPhoneCreateLinksListAjax('projectsLinksList');
}
function setCodeLinksList() {
	iPhoneCreateLinksListAjax('codeLinksList');
}