swfobject.embedSWF("curtain-container.swf", "flash-container", "100%", "710", "10.0.0", false, null, {wmode:"opaque",allowScriptAccess:"always"}, {id:"flashsite", name:"flashsite"});
var tweeturl = "./includes/twitter_json.php?username=";
function getTweets (username,target) {
	$.getJSON(tweeturl+username, function(d) {  
		var html = "";
		$.each(d, function(i, item) {
			var dated = item.created_at.substring(0,20);
			html += "<div>\"" + item.text + "\"</div><span>" + dated + " from " + item.source+ "</span>";
		});
		$(target).append(html);
	});
}

function getTrailer() {
	swfobject.embedSWF("brightcove.swf", "trailer-holder", "600", "389", "10.0.0", false, null, {wmode:"opaque"}, null);
	$("#trailer").css({"top":120});
	$("#tmodal").css({"top":0});
	scroll(0,0);
}
function closeTrailer() {
	$("#trailer").animate({"top":-800}, 500);
	$("#tmodal").animate({"top":-800}, 500);
	$("#trailer-holder").remove();
	$("#trailer").append('<div id="trailer-holder"></div>');
	getFlashHome();
}
function getTickets() {
	$("#showtimes").css({"top":70});
	$("#tmodal").css({"top":0});
	scroll(0,0);
}
function closeTickets() {
	$("#showtimes").animate({"top":-800}, 500);
	$("#tmodal").animate({"top":-800}, 500);
	getFlashHome();
}
function getFlashMovie(movieName) {
   var isIE = navigator.appName.indexOf("Microsoft") != -1;
   return (isIE) ? window[movieName] : document[movieName];  
}  
function getFlashHome() {
	var swf = document.getElementById("flashsite");
	swf.getHomePage();     
}    
function getTheatersXML () {
	$.ajax({
		type: "GET",
		url: "./xml/theaters.xml",
		dataType: "xml",
		success: function(xml) {
			$('#listing').html('<img src="./images/click-a-theater.gif" />');
			$('#listing').append('<table></table>');
			$(xml).find('theater').each(function(){
				var th_name = $(this).attr('id');
				var title = $(this).find('title').text();
				var url = $(this).find('url').text();
				var th_name = $(this).find('name').text();
				var th_city = $(this).find('city').text();
				var th_state = $(this).find('state').text();
				var th_url = $(this).find('url').text();
				var th_text = $(this).find('textblock').text();
				
				var row_formatted = '<tr><td><a target="_blank" href="'+th_url+'">'+th_name+'</a></td><td>'+th_city+', '+th_state+'</td><td width="73"><a target="_blank" href="'+th_url+'"><img src="./images/get-tickets-btn.gif" width="63" height="16"></a></td></tr>';
				if (th_text.length > 4) row_formatted += '<tr><td class="promo-block" colspan="3">'+th_text+'</td></tr>';
				$('#listing table').append(row_formatted);
			});
		}
	});
}

function setPreorder () {
	$(".buy-dvd").html('<img src="./images/amazon-btn-dvd-preorder.gif" alt="Get the DVD" />');
	$(".buy-br").html('<img src="./images/amazon-btn-br-preorder.gif" alt="Get the BluRay™" />');
}

$(function() {
	now = new Date();
	flip_at = new Date("April 13, 2010");
	if (now < flip_at) {
		setPreorder();
	}
	getTweets('slamminmovie','#tweetbox1');
	getTweets('brokenlizard','#tweetbox2');
	$("#trailer .close-btn").click(function () {closeTrailer();});
	$("#showtimes .close-btn").click(function () {closeTickets();});
	$("#tmodal").click(function () {
		closeTrailer();
		closeTickets();
	});
	//getTheatersXML();
	//getTickets();
});