var selectedScreenshot = 0;

function science()
{
        jQuery(".tweet").tweet({
            username:"improbableapps",
            join_text: "auto",
            avatar_size: null,
            count: 5,
            auto_join_text_default: "we said,", 
            auto_join_text_ed: "we",
            auto_join_text_ing: "we were:",
            auto_join_text_reply: "we replied to",
            auto_join_text_url: "we were checking out:",
            loading_text: "loading tweets..."
        });
}

function showScreenshot(screenshotNumber)
{
	if (selectedScreenshot != screenshotNumber)
	{
		var callback = function() { jQuery("#iPhoneScreen").html(""); }
		jQuery("#iPhoneScreen").animate({opacity: 0, marginLeft: "240px"}, 360)
		.animate({marginLeft: "-240px", backgroundPosition: "0 -" + (screenshotNumber*360) +"px",},{duration: 1, complete: callback })
		.animate({opacity: 1, marginLeft: "0px",},360);
		jQuery(".selected-thumbnail").removeClass("selected-thumbnail");
		jQuery("#screenshot-"+screenshotNumber).addClass("selected-thumbnail");
		selectedScreenshot = screenshotNumber;
	}
}

function showMovie(movieURL)
{

	jQuery("#iPhoneScreen").html("<a class='media' href='" + movieURL + "'>&nbsp;</a>");
	var callback = function()
	{
		if (Modernizr.video)
		{
			jQuery('.media').replaceWith(html5Video(movieURL,240,360,'autoplay','no'));
		}
		else
		{
			jQuery('.media').media({ 
		    	width:     240, 
		    	height:    360, 
		    	autoplay:  true, 
		    	src:       movieURL + ".mov", 
		    	attrs:     { CONTROLLER:  'FALSE' },  // object/embed attrs 
				params:		{ wmode: 'transparent'},	// added to object element as param elements; added to embed element as attrs
		    	caption:   false, // supress caption text 
				bgColor:   'black'
			});
		}
	}
	if (selectedScreenshot != 0)
	{
		jQuery("#iPhoneScreen").animate({opacity: 0, marginLeft: "240px",}, 360)
		.animate({marginLeft: "-240px", backgroundPosition: "0 0px",},1)
		.animate({opacity: 1, marginLeft: "0px",},{duration: 360, complete: callback });
	}else{
		callback();
	}
	jQuery(".selected-thumbnail").removeClass("selected-thumbnail");
	jQuery("#screenshot-"+0).addClass("selected-thumbnail");
	selectedScreenshot = 0;	
}

function html5Video(movieBaseURL,width,height,autoplay,controls)
{
	var output = '<video class="media" style="width: '+width +'px; height: ' + height + 'px;" width="width" height="height" poster="' + movieBaseURL + '.jpg"';
	
	if (autoplay) output += "autoplay='YES'";
	if (controls) output += "controls ";
	
	output = output+ '> <source src="' + movieBaseURL + '.ogv" type="video/ogg" /> <source src="' + movieBaseURL + '.mp4" type="video/mp4" />'
	+ '</video>';
	return output;
}
