// JavaScript Document
// Controls for project pages
var expanded = false;
var originalWidths = null;
var originalContent = null;
var posterImg;
function showMovie(url, height){
	originalContent = $('poster').innerHTML;
	var width = 600;
	var height = Math.max(height+16, 336);
	
	expand(function(){movieMode(url, width, height);}, width, height);
	 
	 return false;
}

function expand(afterFinish, width, height){
	if (expanded && $('poster').getHeight()!=height){
		var oldh = $('poster').getHeight();
		$('poster').innerHTML = "";
		$('poster').style.height = oldh+"px";
		$('left').style.width = (width-10)+"px";
		new Effect.Parallel([
			new Effect.Morph('poster', {style:"height:"+height+"px", sync:true}),
			new Effect.Morph('left', {style:"width:"+width+"px", sync:true})
		],
			{duration: 2, afterFinish: afterFinish }
		);
		
		
	} else if (!expanded){
		if (!originalWidths) originalWidths = [$('left').getWidth(), $('right').getWidth()];
		if (!posterImg) posterImg = $('posterImg');
		$('body').style.overflow = "hidden";
		$('right').style.overflow = "hidden";
		$('movieLinks').innerHTML += '<a href="javascript:void(0);" onclick="contract();" style="visiblity:hidden" id="backButton">Back</a>';
		$('backButton').setOpacity(0);
		new Effect.Parallel([
			new Effect.Morph('right', {style:'width:0px', sync:true}),
			new Effect.Morph('left', {style:'width:600px', sync:true}),
			new Effect.Opacity('poster', {from: 1, to:0, sync:true}),
			new Effect.Opacity('backButton', {from: 0, to:1, sync:true}),
			new Effect.Morph('poster', {style:"width:"+width+"px; height:"+height+"px", sync:true})
		],
			{duration: 2, afterFinish: afterFinish }
		);
		expanded = true;
	} else {
		afterFinish();
	}
}

function contract(){
	if (expanded){
		$('poster').innerHTML = "";
		$('poster').setOpacity(0);
		$('poster').appendChild(posterImg);
		$('right').style.display = "block";
		
		
		new Effect.Parallel([
			new Effect.Morph('right', {style:'width:'+originalWidths[1]+'px', sync:true}),
			new Effect.Morph('left', {style:'width:'+originalWidths[0]+'px', sync:true}),
			new Effect.Opacity('poster', {from: 0, to:1, sync:true}),
			new Effect.Opacity('backButton', {from: 1, to:0, sync:true}),
			new Effect.Morph('poster', {style:'width:'+originalWidths[0]+'px; height:336px', sync:true})
		],
			{duration: 2, afterFinish:afterContract }
		);
		expanded = false;
	}
	
	return false;
}

function afterContract(){
	$('backButton').remove();
	$('right').style.overflow = "auto";
}

function movieMode(url, width, height) {
	$('right').style.display = "none";
	$('poster').innerHTML="<object classid=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\" codebase=\"http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0\" width=\""+width+"\" height=\""+height+"\" align=\"middle\"><param name=\"src\" value=\""+url+"\" /><param name=\"autoplay\" value=\"true\" /><embed src=\""+url+"\" autoplay=\"true\" width=\""+width+"\" height=\""+height+"\" align=\"middle\" bgcolor=\"black\" pluginspage=\"http://www.apple.com/quicktime/download/\"></embed></object>";
	$('poster').setOpacity(1);
}

function showGallery(url){
	
	var width = 600;
	var height = 400;
	
	expand(function(){galleryMode(url);}, width, height);
	
	
	return false;
}

function galleryMode(url){
	$('right').style.display = "none";
	$('poster').setOpacity(1);
	$('poster').innerHTML="<iframe src='"+url+"'></iframe>";
}
