function showNextMovie(id) {
	new Ajax.Request('ajax.php?action=get&list=1&id=' + id, {
  		method: 'get',
  		onSuccess: function(transport) {
			$('nowshowing01').innerHTML = $('nowshowing02').innerHTML;
			$('nowshowing02').innerHTML = $('nowshowing03').innerHTML;
			$('nowshowing03').innerHTML = generateNowShowingCell(transport.responseText);
 		}
	});
	
	updatePrevBtn(id,3);
	updateNextBtn(id,1);
}

function showPrevMovie(id) {
	new Ajax.Request('ajax.php?action=get&list=1&id=' + id, {
  		method: 'get',
  		onSuccess: function(transport) {
			$('nowshowing03').innerHTML = $('nowshowing02').innerHTML;
			$('nowshowing02').innerHTML = $('nowshowing01').innerHTML;
			$('nowshowing01').innerHTML = generateNowShowingCell(transport.responseText);
 		}
	});
	
	updatePrevBtn(id,1);
	updateNextBtn(id,3);
}

function updatePrevBtn(id,offset) {
	
	new Ajax.Request('ajax.php?action=getprev&list=1&id=' + id + '&offset=' + offset, {
		method: 'get',
		onSuccess: function(transport) {
			if (transport.responseText != "") {
				prevMovie = transport.responseText.evalJSON(true);
				if (typeof prevMovie != 'undefined') {
					html = '<a href="javascript:showPrevMovie(' + prevMovie.id + ')">';
					html += '<img src="images/more-left.png" alt="&lt;-More" width="31" height="337" />';
					html += '</a>';
				}
				else {
					html = '<img src="images/more-left.png" alt="&lt;-More" width="31" height="337" />';					
				}
			}
			else {
				html = '<img src="images/more-left.png" alt="&lt;-More" width="31" height="337" />';
			}
			$('nowShowingLess').innerHTML = html;
		}
	});
}

function updateNextBtn(id,offset) {	
	new Ajax.Request('ajax.php?action=getnext&list=1&id=' + id + '&offset=' + offset, {
		method: 'get',
		onSuccess: function(transport) {
			if (transport.responseText != "") {
				nextMovie = transport.responseText.evalJSON(true);
				if (typeof nextMovie != 'undefined') {
					html = '<a href="javascript:showNextMovie(' + nextMovie.id + ')">';
					html += '<img src="images/more-right.png" alt="More-&gt;" width="31" height="337">';
					html += '</a>';
				}
				else {
					html = '<img src="images/more-right.png" alt="More-&gt;" width="31" height="337">';
				}
			}
			else {
				html = '<img src="images/more-right.png" alt="More-&gt;" width="31" height="337">';
			}
			$('nowShowingMore').innerHTML = html;
		}
	});
}

function generateNowShowingCell(json) {
	movie = json.evalJSON(true);
	html = '<a href="index.php?page=movies#movie_' + movie.id + '">';
	html += '<img src="' + movie.nowShowingPoster + '" />';
	html += '</a>';
	
	return html;
}