$(document).on("pagebeforeshow", "#resultsPage", function(e, ui) {
	$('#showName1').text($('#selection1').attr('data-imdb-title'));
	$('#showName2').text($('#selection2').attr('data-imdb-title'));
	$('#resultList').html('');
});

$(document).on("pageshow", "#resultsPage", function(e, ui) {
	// Show the spinner
	$.mobile.loading('show', {
		text: 'searching',
		textVisible: true,
		theme: 'a'
	});
	
	var showsToFetch = [];
	$('.selectedResult').each(function(i, elem){
		showsToFetch.push({
			'id': $(elem).attr('data-imdb-id'),
			'title': $(elem).attr('data-imdb-title'),
			'cast': [],
			'complete': false
		});
	});

	$.each(showsToFetch, function(i, show){
		var theUrl = "http://m.imdb.com/title/" + show.id + "/fullcredits/cast";
		$.get(theUrl, function(data){

			// Scrape the cast table from the returned data
			$('.poster', $(data)).each(function(i, elem){
				var actorName = $('.title', elem).text().trim();
				if (!actorName.length) {
					return true;
				}

				var charText = $('.detail', elem).text();
				if (charText.indexOf('(') != -1) {
					charText = charText.substr(0, charText.indexOf('('));
				}
				if (charText.indexOf('/') != -1) {
					charText = charText.substr(0, charText.indexOf('/'));
				}
				
				var thumbURL = $('img', elem).attr('src').replace(/SX(\d\d)_SY(\d\d)/g, "SX100_SY110");
				if (thumbURL.substr(0,1) == '/') {
					thumbURL = 'http://m.imdb.com' + thumbURL;
				}

				show.cast.push({
					'name' : actorName,
					'char' : charText.trim(),
					'link' : $('.title a', elem).attr('href'),
					'thumb' : thumbURL
				});
			});
			show.complete = true;

			// Check whether all shows have completed scraping
			var allComplete = true;
			$.each(showsToFetch, function(i, show){
				allComplete &= show.complete;
			});

			// Find people in all shows
			if (allComplete) {
				var appearanceCount = {};
				$.each(showsToFetch, function(i, show){
					$.each(show.cast, function(j, actor){
						if (!appearanceCount[actor.link]) {
							appearanceCount[actor.link] = {
								'count': 1,
								'name': actor.name,
								'char': actor.char,
								'link': actor.link,
								'thumb': actor.thumb
							};
						} else {
							appearanceCount[actor.link].count++;
							appearanceCount[actor.link].char += ', ' + actor.char;
						}
					});
				});

				var matches = [];
				for (var key in appearanceCount) {
					var actor = appearanceCount[key];
					if (actor.count == showsToFetch.length) {
						matches.push(actor);
					}
				}

				var html = '';
				if (matches.length) {
					$.each(matches, function(i, actor){
						html += '<li>'
							+ '<a href="http://www.imdb.com' + actor.link + '" target="_blank">'
							+ '<img src="' + actor.thumb + '"/>'
							+ '<h3>' + actor.name + '</h3>'
							+ '<p>' + actor.char + '</p></a></li>';
					});
				} else {
					html += '<li>No matches</li>';
				}
				$('#resultList').html(html);
				$('#resultList').listview( "refresh" );
				$('#resultList').trigger( "updatelayout");

				$.mobile.loading('hide');
			}
		});
	});
});
@@ -830,14 +830,26 @@
 $('.
-poster
+col-xs-12.col-md-6
 ', $
@@ -903,22 +903,18 @@
 me = $('
-.title
+h4
 ', elem)
@@ -1009,15 +1009,19 @@
  $('
-.detail
+p.h4.unbold
 ', e
@@ -1426,24 +1426,229 @@
 mbURL;%0A%09%09%09%09%7D
+%0A%09%09%09%09%0A%09%09%09%09var link = $('a', elem).attr('href');%0A%09%09%09%09if (link.indexOf('?') != -1) %7B%0A%09%09%09%09%09link = link.substr(0, link.indexOf('?'));%0A%09%09%09%09%7D%0A%09%09%09%09if (link.substr(0,2) == '//') %7B%0A%09%09%09%09%09link = 'http:' + link;%0A%09%09%09%09%7D
 %0A%0A%09%09%09%09show.c
@@ -1732,40 +1732,12 @@
 ' : 
-$('.title a', elem).attr('href')
+link
 ,%0A%09%09
@@ -2824,27 +2824,8 @@
 ef=%22
-http://www.imdb.com
 ' + 

Update queries for new IMDB design