// JavaScript Document

function Movie(url, w, h, description)
{
	this.url = url;
	this.width = w;
	this.height = h;
	this.description = description;
}

var movies = new Array();
movies.push(new Movie("movies/01-Chevy_Vastpacity.mov", 640, 360, "Chevrolet \"Vastpacity\"<br>Agency: Goodby, Silverstein & Partners<br>Music House: Barking Owl"));

movies.push(new Movie("movies/08-Coke_Two_Guys.mov", 640, 362, "Coca-Cola \"Two Guys\"<br>Dir: Valerie Pirson<br>Agency: Weiden+Kennedy<br>Music House: stimm&uuml;ng"));

movies.push(new Movie("movies/03-Sprint_Birthday.mov", 640, 360, "Sprint \"Birthday\"<br>Agency: Goodby, Silverstein & Partners<br>Music House: Barking Owl"));

movies.push(new Movie("movies/02-CenturyLink_More_Links.mov", 640, 360, "CenturyLink \"More Links\"<br>Agency: Monigle Associates<br>Music House: Barking Owl"));

movies.push(new Movie("movies/01-UniversityOfPhoenix.mov", 640, 360, "University of Phoenix \"Community\"<br>Agency: Cramer-Krasselt<br>Music House: Mophonics"));

movies.push(new Movie("movies/06-Chevy_Truck_Month_Traverse.mov", 640, 360, "Chevrolet \"Truck Month\"<br>Agency: Campbell-Ewald<br>Music House: Barking Owl"));

movies.push(new Movie("movies/02-DunkinDonuts.mov", 640, 360, "Dunkin' Donuts \"Costume Party\"<br>Agency: Hill Holliday<br>Music House: stimm&uuml;ng"));

movies.push(new Movie("movies/06-EverestCollege.mov", 640, 360, "Everest College<br>Production Company: West North Media"));

movies.push(new Movie("movies/04-World_Championship_of_Ping_Pong.mov", 640, 360, "World Championship of Ping Pong<br>Fox Sports"));

movies.push(new Movie("movies/05-Hardees_Double_Mocha_Grande.mov", 640, 360, "Hardee's \"Double Mocha Grande\"<br>Dir. Greg Bell<br>Agency: David&Goliath<br>Music House: Barking Owl"));

movies.push(new Movie("movies/07-Chevy_Summer_Event_Dibs.mov", 640, 360, "Chevrolet \"Dibs\"<br>Agency: Campbell-Ewald<br>Music House: Barking Owl"));

movies.push(new Movie("movies/08-YoGreek_Plates.mov", 640, 346, "YoGreek \"Plates\"<br>Dir: Grady Cooper<br>Production Company: Kontagious"));


movies.push(new Movie("movies/09-Cadillac_SRX_Experience_Intro.mov", 640, 360, "Cadillac \"The SRX Experience (Intro)\"<br>Agency: Modernista!<br>Music House: stimm&uuml;ng"));

movies.push(new Movie("movies/10-NFI_Ruckus.mov", 640, 360, "National Fatherhood Initiative \"Ruckus\"<br>Dir: Vance Malone<br>Agency: Campbell-Ewald<br>Music House: Barking Owl"));

movies.push(new Movie("movies/11-Migrant_Rights.mov", 640, 360, "Migrant Rights PSA<br>www.migrant-rights.org<br>Dir: Eric Epstein<br>www.najork.net"));

movies.push(new Movie("movies/15-JamesHardie.mov", 640, 360, "James Hardie Building Products<br>Production Company: West North Media"));

movies.push(new Movie("movies/12-Ford_Jonathan_Cross_The_Street.mov", 640, 362, "Ford \"Jonathan/Cross The Street\"<br>Agency: J. Walter Thompson<br>Music House: stimm&uuml;ng"));

movies.push(new Movie("movies/13-McDonalds_Same_Guy.mov", 640, 372, "McDonald's \"Same Guy\"<br>Agency: Alma DDB<br>Dir: Paul B. Cummings<br>Music House: stimm&uuml;ng"));

movies.push(new Movie("movies/14-Hyundai_Tunnel.mov", 540, 360, "Hyundai \"Tunnel\"<br>Agency: Goodby, Silverstein & Partners<br>Dir: Christian Loubek<br>Music House: stimm&uuml;ng"));

movies.push(new Movie("movies/15-Amp_Camp.mov", 640, 360, "Amp \"Camp\"<br>Agency: BBDO NY<br>Dir: Three Legged Legs<br>Music House: stimm&uuml;ng"));

movies.push(new Movie("movies/16-Street_Tests.mov", 640, 360, "Street Tests<br>Dir: Eric Epstein<br>www.najork.net"));

movies.push(new Movie("movies/17-T-Mobile_Flashcards.mov", 640, 364, "T-Mobile \"Family Flashcards\"<br>Agency: Publicis<br>Dir: Sam Cadman<br>Music House: stimm&uuml;ng"));

movies.push(new Movie("movies/18-PETA_Beatdown.mov", 640, 360, "PETA \"Beatdown\"<br>Dir: Scott Corbett"));

movies.push(new Movie("movies/19-Gasoline_Leaving_Aunt_Millies.mov", 640, 346, "Gasoline<br>(excerpt from the short film)<br>Dir: Andrew M. Hulse"));

movies.push(new Movie("movies/20-Rock_The_Vote_Ask_Yourself.mov", 640, 360, "Rock The Vote \"Ask Yourself\"<br>Dir: Matthew Welch"));

movies.push(new Movie("movies/21-Amp_Shotgun.mov", 640, 360, "Amp \"Shotgun\"<br>Dir: Stacy Peralta<br>Agency: BBDO NY<br>Music House: stimm&uuml;ng"));

movies.push(new Movie("movies/22-Hyundai_Perfect_Gift.mov", 540, 360, "Hyundai \"Perfect Gift\"<br>Agency: Goodby, Silverstein & Partners<br>Music House: stimm&uuml;ng"));

movies.push(new Movie("movies/23-Kites.mov", 540, 360, "Kites<br>Dir: Eric Epstein<br>www.najork.net"));



var currentIndex = 0;

var intervalID = -1;

function closeMovie()
{
	
	clearInterval(intervalID);
	intervalID = -1;
	document.getElementById("qtClose").innerHTML = "&nbsp;";
	document.getElementById("qtmovie").innerHTML = "&nbsp;";
	$(".movieText").html("");
		
}

//called by a button
function playMovie(index)
{
	clearInterval(intervalID);
	intervalID = -1;
	
	startMovie(index);
	
	

}

//
function startMovie(index)
{
	//get the movie specified from the list
	var mov = movies[index];
	
	var left = (330+(640-mov.width)/2);
	var textWidth = mov.width+((640-mov.width)/2);
	
	//show the close button
	document.getElementById("qtClose").innerHTML = "<a href=\"javascript:closeMovie();\">close</a>";
	document.getElementById("qtClose").style.width = (330+textWidth)+"px";
	document.getElementById("movieHolderInner").style.height = (mov.height+16)+"px";
	$("#qtmovie").css("left", left+"px");
	$(".movieText").css("width", textWidth+"px");
	$(".movieText").html(mov.description);
	
	//generate the quicktime text
	var qtString = QT_GenerateOBJECTText(mov.url, mov.width, mov.height+16, '', 'emb#NAME', 'movie_embed1', 'obj#Id', 'movie1', 'EnableJavascript', 'True',
	  	 'controller', 'True', 'bgcolor', '000000', 'AUTOPLAY', 'True', 'SCALE', 'Aspect', 'SaveEmbedTags', 'True', 'postdomevents', 'True');

	//add it to the qtmovie
	document.getElementById("qtmovie").innerHTML = qtString;
	
}


function writeTrace(str)
{
	document.getElementById("tracer").innerHTML = str;	
}

function movieEnd()
{
		
	//alert("movie ended");
	
	if (currentIndex < movies.length)
	{
		currentIndex++;
		playNext();
	}
	else
	{
		closeMovie();
	}
	
	
}

function monitorMovie()
{
	if (document.movie1 != null)
	{
		if (document.movie1.GetTime() == document.movie1.GetDuration())
		{
			clearInterval(intervalID);
			intervalID = -1;
			movieEnd();
		}
	}
	else 
	{
		clearInterval(intervalID);	
		intervalID = -1;
	}
	
}

function playNext()
{
	startMovie(currentIndex);
	
	if (_QTIsMSIE())
	{
		if (intervalID < 0)
		{
			intervalID = setInterval("monitorMovie()", 100);
		}
	}
	else 
	{
		//add the event listener
		rListener('qt_ended', 'movie1', 'movie_embed1', movieEnd);
	}
}


function playAll()
{
	
	currentIndex = 0;
	playNext();
	
	
}


function rEvent(obj, evt, handler, captures)
{

	if ( document.addEventListener )
	{
		obj.addEventListener(evt, handler, captures);
	}
	else
	{
		// IE
		obj.attachEvent('on' + evt, handler);
	}

}

function rListener(eventName, objID, embedID, listenerFcn)

{

	var obj = document.getElementById(objID);
	
	if ( !obj )
	{
		obj = document.getElementById(embedID);
	}
	
	if ( obj )
	{
		
		rEvent(obj, eventName, listenerFcn, false);
	}

}



