/*****************************************
* tiff.js
*
* Javascripts written for the Toronto Italian Film Festival website
* (c) 2002, inflectionDesign, inc. All Rights Reserved.
*********************************************************************************/		

/*****************************************
* DOM Sniffer
*
* This code snippet gets executed everytime a page loads on the site. If the browser
* does not support the DOM (i.e.: it's an older browser), the visitor gets sent to
* the Web Standards project to download a newer browser.
*********************************************************************************/		
if ( !document.getElementById )
    window.location = "http://www.webstandards.org/upgrade/"

/*****************************************
* cssPicker(  )
*
* Returns the best CSS File name for this environment
*********************************************************************************/	
function cssPicker() {
	switch( navigator.platform )
	{
		case "Win32":
			if( navigator.appName == "Microsoft Internet Explorer" )
				return "tiffPC.css";
			else
				return "tiff.css";
		
		default:
			return "tiff.css";
	}
}

/*****************************************
* imageHandler( targetImage, isOver, path )
*
* Handles the rollovers, including the menu items which are split between two 
* tiles of the menu
*********************************************************************************/		
function imageHandler( targetImage, isOver )
{
	if( document.images )
	{
		var nameEnder = "";
		
		if( isOver )
			nameEnder = "_over";

		document.images[ targetImage ].src = path + "images/header/" + targetImage + nameEnder + ".jpg";
	}
}

/*****************************************
* outputHeader()
*
* Outputs the navigation, keeping in mind the current section so it can be show with
* the "in" image
*********************************************************************************/	
function outputHeader( currSection )
{
	// sections is in the order that the content gets outputed, not in left-to-right reading order
	// The "BREAK" item signifies the line break in the header
	var sections = new Array( new Array( "contact", "staff", "BREAK", "films", "schedule", "tickets", "theatres", "sponsors" ),
							  new Array( "Contact Us", "Staff List", "", "Film Synopsis", "Screening Schedule", "Ticket Information", "Theatre Locations", "Sponsors" ));
	var linkEnd = "";
	var inEnd = "";
	
	document.write('<TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="0" BORDER="0">');
	document.write('	<TR>');
	document.write('		<TD COLSPAN="2" BACKGROUND="' + path + 'images/header/1_1.jpg" CLASS="headerBack">');
	
	if( currSection != "home" )
	{
		document.write( '<A HREF="../index.html">');
		linkEnd = "</A>";
	}
	document.write('		<IMG SRC="' + path + 'images/header/1_1.jpg" ALT="" WIDTH="140" HEIGHT="130" BORDER="0"></TD></A>' + linkEnd );
	
	document.write('		<TD COLSPAN="5"><IMG SRC="' + path + 'images/header/1_2.jpg" ALT="" WIDTH="465" HEIGHT="130" BORDER="0"></TD>');
	document.write('		<TD WIDTH="100%">&nbsp;</TD>');
	document.write('	</TR>');
	document.write('	<TR>');
	document.write('		<TD COLSPAN="5" BACKGROUND="' + path + 'images/header/2_1.jpg" CLASS="headerBack"><IMG SRC="' + path + 'images/header/2_1.jpg" ALT="" WIDTH="415" HEIGHT="70" BORDER="0" BACKGROUND="' + path + 'images/header/2_1.jpg" CLASS="headerBack"></TD>');

	for( counter = 0; counter <= sections[0].length - 1; counter++)
	{
		if( sections[0][ counter ] != "BREAK" )
		{
			linkEnd = "";
			inEnd = "_in";
			
			document.write('		<TD>');
			if( sections[0][ counter ] != currSection )
			{
				document.write('<A HREF="' + path + sections[0][ counter ] + '/index.html" onMouseOver="imageHandler( \'' + sections[0][ counter ] + '\', true ); window.status=\'' + sections[1][ counter ] + '\'; return true;" onMouseOut="imageHandler(\'' + sections[0][ counter ] + '\', false); window.status=\'\'; return true;">');
				linkEnd = "</A>";
				inEnd = "";
			}
			document.write('<IMG SRC="' + path + 'images/header/' + sections[0][ counter ] + inEnd + '.jpg" ALT="' + sections[1][ counter ] + '" NAME="' + sections[0][ counter ] + '" BORDER="0">' + linkEnd + '</TD>');			
		}
		else
			document.write('		<TD WIDTH="100%">&nbsp;</TD></TR><TR>');
	};
	
	//document.write('		<TD COLSPAN="2"><SCRIPT LANGUAGE="Javascript" TYPE="text/javascript">outputDate();</SCRIPT><NOSCRIPT>&nbsp;</NOSCRIPT>');
	document.write('		<TD COLSPAN="2">&nbsp;</TD>');
	document.write('		<TD WIDTH="100%">&nbsp;</TD>');
	document.write('	</TR>');
	document.write('</TABLE>');
}

/*****************************************
* outputBoxes()
*
* Outputs the boxes down the right edge of the page
*********************************************************************************/	
function outputBoxes( showFeature, showICS, showSponsor, excludedFeature, excludedICS )
{
	document.write('<TD BACKGROUND="' + path + 'images/dash_v.jpg" CLASS="dashBackV">&nbsp;</TD>');
	document.write('<TD WIDTH="20%" VALIGN="TOP"><TABLE WIDTH="100%" BORDER="0"><TR><TD CLASS="dashBackH" BACKGROUND="' + path + 'images/dash_h.jpg">&nbsp;</TD></TR>');
	
	if( showFeature )
	{
		document.write('<TR><TD CLASS="bodyText">');
		document.write('<DIV CLASS="randomTitles">Featured Film</DIV><DIV CLASS="indent">');
		outputFeaturedFilm( excludedFeature );
		document.write('</DIV></TD></TR><TR><TD CLASS="dashBackH" BACKGROUND="' + path + 'images/dash_h.jpg">&nbsp;</TD></TR>');
	}					
	
	if( showICS )
	{
		document.write('<TR><TD CLASS="bodyText">');
		document.write('<DIV CLASS="randomTitles">Featured Italian-Canadian Short</DIV><DIV CLASS="indent">');
		outputICS( excludedICS );
		document.write('</DIV></TD></TR><TR><TD CLASS="dashBackH" BACKGROUND="' + path + 'images/dash_h.jpg">&nbsp;</TD></TR>');
	}
	
	if( showSponsor )
	{
		document.write('<TR><TD CLASS="bodyText">');
		document.write('<DIV CLASS="randomTitles">Featured Sponsor</DIV><DIV CLASS="indent">');
		outputSponsor( '' );
		document.write('</DIV></TD></TR><TR><TD CLASS="dashBackH" BACKGROUND="' + path + 'images/dash_h.jpg">&nbsp;</TD></TR>');
	}
	
	// Download Program
	document.write('<TR><TD CLASS="bodyText"><DIV CLASS="randomTitles">Downloads</DIV>');
	document.write('<DIV CLASS="smallSize indent"><A HREF="' + path + 'downloads/TIFF2002schedule.pdf"><IMG SRC="' + path + 'images/pdf.jpg" ALT="pdf" BORDER="0" WIDTH="31" HEIGHT="32"> <B>Schedule</B></A><DIV CLASS="xSmallSize">176 kb &bull; ~25 secs @ 56k</DIV></DIV>');
	document.write('<P><DIV CLASS="smallSize indent"><A HREF="' + path + 'downloads/TIFF2002program.pdf"><IMG SRC="' + path + 'images/pdf.jpg" ALT="pdf" BORDER="0" WIDTH="31" HEIGHT="32"> <B>Program</B></A><DIV CLASS="xSmallSize">5.9 mb &bull; ~15 mins @ 56k</DIV></DIV></P>');
	document.write('<P><DIV CLASS="smallSize indent"><A HREF="http://www.adobe.com/products/acrobat/readstep.html"><IMG SRC="' + path + 'images/acrobat.jpg" ALT="Get Acrobat" WIDTH="88" HEIGHT="31" BORDER="0"></A></DIV></P>');
	document.write('<TR><TD CLASS="dashBackH" BACKGROUND="' + path + 'images/dash_h.jpg">&nbsp;</TD></TR>');
	
	document.write('<TR><TD CLASS="bodyText"><DIV CLASS="randomTitles">Site by</DIV>');
	document.write('<DIV CLASS="xSmallSize indent"><A HREF="http://www.inflectiondesign.com" target="_blank"><IMG SRC="' + path + 'images/sponsors/id.jpg" ALT="" WIDTH="110" HEIGHT="26" BORDER="0"><BR>');
	document.write('www.inflectiondesign.com</A></DIV></TD></TR><TR><TD CLASS="dashBackH" BACKGROUND="' + path + 'images/dash_h.jpg">&nbsp;</TD></TR></TABLE></TD>');
}



/*****************************************
* outputDate()
*
* Outputs today's date followed by a countdown to the festival start or end
* depending on today's date
*********************************************************************************/	
function outputDate()
{
	/*months = new Array('January','February','March', 'April','May','June','July','August','September', 'October','November','December');
	weekdays = new Array('Sunday','Monday','Tuesday', 'Wednesday','Thursday','Friday','Saturday');

	date = new Date();
	
	d  = date.getDate();
	day = (d < 10) ? '0' + d : d;
	weekday = date.getDay() + 1;

	m = date.getMonth() + 1;
	month = (m < 10) ? '0' + m : m;

	yy = date.getYear();
	year = (yy < 1000) ? yy + 1900 : yy;

	hours = date.getHours();
	minutes = date.getMinutes();
	if( minutes < 10 )
		minutes = "0" + minutes;
	
	document.write( '<DIV CLASS="date xxSmallSize">' + weekdays[ weekday - 1 ] + " " + months[ m - 1 ] + " " + day + ", " + year + " - " + hours + ":" + minutes + "</P>");
	document.write( 'See you in June 2003 for the 5th Annual Festival!' );
	If there are any days left before the festival, display the countdown
	festivalDate = new Date( 2002, 6, 19 );
	daysLeft = parseInt( festivalDate.getDate(), 10 ) - parseInt( date.getDate(), 10 );
	if ( festivalDate.getMonth() < m )
		daysLeft = -1;
		
	document.write( '<DIV CLASS="date xSmallSize"><B>' );
	if( daysLeft > 0 )
	{
		if( daysLeft == 1 )
			document.write( "The Festival starts tomorrow!" );
		else
			document.write( daysLeft + " days until the festival!" );
	}
	else
	{
		festivalDate = new Date( 2002, 6, 24 );
		daysLeft = parseInt( festivalDate.getDate(), 10 ) - parseInt( date.getDate(), 10 );
		if ( festivalDate.getMonth() < m )
			daysLeft = -1;
	
		if( daysLeft > 0 )
		{
			if( daysLeft == 1 )
				document.write( "Today is the last day of the Festival!" );
			else
				document.write( daysLeft + " days of Festival left!" );
		}
		else
		{
			document.write( "The Festival is over! See you next year!" );
		}
	}*/
	//document.write( '<DIV CLASS="date">See you June 11 - 15, 2003 for the 5th Annual Festival!</DIV>');
}

/*****************************************
* outputFeaturedFilm( notThisOne )
*
* Outputs a randomly selected sponsor from the full list, including their logo
* and a link to their site (if they have one). Accepts a path to the image directory
* in case we're on a nested page and a notThisOne so we don't display the film whose page we're on
*********************************************************************************/	
function outputFeaturedFilm( notThisOne )
{
	var films = new Array( 
		new Array('appointment',			'francesca',				'hotel',					'impossible',				'lastkiss',					'probablylove',				'sleepless',				'taranta',					'tobiascafe', 				'tomorrow',					'tropical',				'vipera',					'zeno'), 
		new Array('The Appointment',		'Francesca and Nunziata',	'Hotel Dajti', 				'An Impossible Crime', 		'The Last Kiss', 			'Probably Love', 			'Sleepless', 				'La Taranta',				"Tobia's Caf&eacute;",		'Tomorrow', 				'Our Tropical Island', 	'Mother Viper', 			'My Father\'s Words'),
		new Array("L'appuntamento",			'Francesca e Nunziata',		'Hotel Dajti', 				'Un Delitto Impossibile', 	"L'ultimo Bacio", 			"L'amore Probabilmente",	'No Ho Sonno',				' ',						"Tobia Al Caffe", 			'Domani', 					'Mari del Sud',			'Vipera', 					'La Parole di mio Padre'),
		new Array('Veronica Bilbao La Vieja', 'Lina Wertmuller',		'Carmine Fornari',			'Antonello Grimaldi',		'Gabriele Muccino',			'Giuseppe Bertolucci',		'Dario Argento', 			'Gianfranco Mingozzi',		'Gianfranco Mingozzi',		'Francesca Archibugi', 		'Marcello Cesena',		'Sergio Citti',				'Francesca Comencini'),
		new Array('2001 &bull; 76 minutes',	'2001 &bull; 125 minutes',	'2001 &bull; 93 minutes',	'2000 &bull; 100 minutes',	'2001 &bull; 115 minutes',	'2001 &bull; 107 minutes',	'2001 &bull; 117 minutes',	'1962 &bull; 20 minutes',	'2000 &bull; 105 minutes', 	'2001 &bull; 120 minutes', 	'2001',					'2000 &bull; 100 minutes', 	'2001 &bull; 85 minutes'));
		
	// Randomly choose a film
	rnd.today = new Date();
	rnd.seed = rnd.today.getTime();

	theFilm = 0;
	filmName = "";
	if( notThisOne == null )
	{
		theFilm = rand( films[0].length );
		theFilm--;
	}
	else
	{
		filmName = notThisOne;
		while( filmName == notThisOne )
		{
			theFilm = rand( films[0].length );
			theFilm--;
			filmName = films[0][theFilm];
		}
	}
	
	// Output...
	if( filmName == 'taranta' )
		document.write( '<A HREF="' + path + 'films/tobiascafe.html#taranta"><IMG SRC="' + path + 'images/films/' + films[0][theFilm] + '_thumb.jpg' + '" BORDER="0">' );
	else
		document.write( '<A HREF="' + path + 'films/' + films[0][theFilm] + '.html"><IMG SRC="' + path + 'images/films/' + films[0][theFilm] + '_thumb.jpg' + '" BORDER="0">' );
	document.write( '<DIV CLASS="engTitle largeSize">' + films[1][theFilm] + "</DIV>" );
	document.write( '<DIV CLASS="italTitle sallSize">' + films[2][theFilm] + "</DIV></A>" );
	document.write( '<DIV CLASS="director xSmallSize">' + films[3][theFilm] + "</DIV>" );
	document.write( '<DIV CLASS="bodyText xSmallSize">Italy ' + films[4][theFilm] + "<BR>" );
}

/*****************************************
* outputICS( notThisOne )
*
* Outputs a randomly selected Italian-Canadian Short from the full list. Accepts a path to the image directory
* in case we're on a nested page and a notThisOne so we don't display the film whose page we're on
*********************************************************************************/	
function outputICS( notThisOne )
{
	var films = new Array( 
		new Array('street',													'elevated',				'bath',						'walls',					'franco',							'generation'), 
		new Array('Portrait of a Street (The Soul and Spirit of College)',	'Elevated',				'The Bath', 				'When The Walls Come Down',	'Franco - Story of an Immigrant', 	'First Generation'),
		new Array(' ',														' ',					'Il Bagno', 				' ',						'Franco - Storia di un emigrante',	' '),
		new Array('Sandra Danilovic', 										'Vincenzo Natali',		'Sergio Navarretta',		'Daniel De Santo',			'Salvatore Greco',					'Vince DeMarinis'),
		new Array('2001 &bull; 52 minutes',									'1995 &bull; 21 minutes','2002 &bull; 26 minutes',	'2002 &bull; 5 minutes',	'1976 &bull; 29 minutes',			'2001 &bull; 16 minutes'));
		
	// Randomly choose a film
	rnd.today = new Date();
	rnd.seed = rnd.today.getTime();
	if( notThisOne == null )
	{
		theFilm = rand( films[0].length );
		theFilm--;
	}
	else
	{
		filmName = notThisOne;
		while( filmName == notThisOne )
		{
			theFilm = rand( films[0].length );
			theFilm--;
			filmName = films[0][theFilm];
		}
	}
	
	// Output...
	document.write( '<A HREF="' + path + 'films/shorts.html#' + films[0][theFilm] + '"><DIV CLASS="engTitle largeSize">' + films[1][theFilm] + "</DIV>" );
	document.write( '<DIV CLASS="italTitle smallSize">' + films[2][theFilm] + "</DIV></A>" );
	document.write( '<DIV CLASS="director xSmallSize">' + films[3][theFilm] + "</DIV>" );
	document.write( '<DIV CLASS="bodyText xSmallSize">Italy ' + films[4][theFilm] + "</DIV>" );
}

/*****************************************
* outputSponsor()
*
* Outputs a randomly selected sponsor from the full list, including their logo
* and a link to their site (if they have one). Accepts a path to the image directory
* in case we're on a nested page
*********************************************************************************/	
function outputSponsor()
{
	var sponsors = new Array( 
		new Array('ici',						'italia',						'puglia',						'maserati',							'adriana',						'intramovies',					'itc',								'intesa',					'windsor',							'rosehaven',						'trestelle',						'colio',				'italpasta',				'vitale',						'dupont',						'cfmt',					'cfrb',					'chin',						'corriere',					'prthing', 						'marios',											'sotto',									'romagna'), 
		new Array('Italian Cultural Institute',	'Italia Cinema',				'Puglia Review', 				'Maserati of Ontario',				'Adriana Chiesa Enterprises', 	'intra movies',					'Italian Trade Commision',			'IntesaBci Canada',			'Windsor Arms', 					'Rosehaven Homes',					'Tre Stelle',						'Colio Estate Wines',	'Italpasta',				'Vitale',						'S.T. Dupont',					'CFMT International',	'CFRB',					'CHIN',						'Corriere Canadese',		'thatPRthing',					"East Side Mario's",								'Sotto Sotto',								'Romagna Mio Osteria' ),
		new Array('http://www.iicto-ca.org/',	'http://www.italiacinema.net/',	'http://www.pugliareview.com/', 'http://www.maseratiofontario.com', '#', 							"http://www.intramovies.com/",	'http://www.abruzzovillage.com/',	'http://www.bcibank.com',	'http://www.windsorarmshotel.com/', 'http://www.rosehavenhomes.com',	'http://www.nationalcheese.com/',	'http://www.colio.com',	'http://www.italpasta.com/','http://www.italpasta.com/',	'http://www.st-dupont.com/', 	'http://www.cfmt.com',	'http://www.cfrb.com',	'http://www.chinradio.com',	'http://www.corriere.com/',	'http://www.thatprthing.com',	'http://www.primerestaurants.com/eastsidemarios/',	'http://www.toronto.com/profile/146878/',	' '));
		
	// Randomly choose a film
	rnd.today = new Date();
	rnd.seed = rnd.today.getTime();
	theSponsor = rand( sponsors[0].length );
	theSponsor--;
	
	// Output...
	document.write( '<IMG SRC="' + path + 'images/sponsors/'+ sponsors[0][theSponsor] + '.jpg" ALT="' + sponsors[2][theSponsor] + '">');
	document.write( '<DIV CLASS="bodyText"><A HREF="' + sponsors[2][theSponsor] + '" target="_blank">' + sponsors[1][theSponsor] + '</A></DIV>');
}

/*****************************************
* outputSponsorList()
*
* Outputs the full list of sponsors in a self-enclosed table, 3 to a line.
*********************************************************************************/	
function outputSponsorList()
{
	var sponsors = new Array( 
		new Array('ici',						'italia',						'puglia',						'maserati',							'adriana',						'intramovies',					'itc',								'intesa',					'windsor',							'rosehaven',						'trestelle',						'colio',				'italpasta',				'vitale',						'dupont',						'cfmt',					'cfrb',					'chin',						'corriere',					'prthing', 						'marios',											'sotto',									'romagna'), 
		new Array('Italian Cultural Institute',	'Italia Cinema',				'Puglia Review', 				'Maserati of Ontario',				'Adriana Chiesa Enterprises', 	'intra movies',					'Italian Trade Commision',			'IntesaBci Canada',			'Windsor Arms', 					'Rosehaven Homes',					'Tre Stelle',						'Colio Estate Wines',	'Italpasta',				'Vitale',						'S.T. Dupont',					'CFMT International',	'CFRB',					'CHIN',						'Corriere Canadese',		'thatPRthing',					"East Side Mario's",								'Sotto Sotto',								'Romagna Mio Osteria' ),
		new Array('http://www.iicto-ca.org/',	'http://www.italiacinema.net/',	'http://www.pugliareview.com/', 'http://www.maseratiofontario.com', '#', 							"http://www.intramovies.com/",	'http://www.abruzzovillage.com/',	'http://www.intesabci.ca/',	'http://www.windsorarmshotel.com/', 'http://www.rosehavenhomes.com',	'http://www.nationalcheese.com/',	'http://www.colio.com',	'http://www.italpasta.com/','http://www.italpasta.com/',	'http://www.st-dupont.com/', 	'http://www.cfmt.com',	'http://www.cfrb.com',	'http://www.chinradio.com',	'http://www.corriere.com/',	'http://www.thatprthing.com',	'http://www.primerestaurants.com/eastsidemarios/',	'http://www.toronto.com/profile/146878/',	'#'));
	var cellCounter = 0;
	
	// Output...
	document.write( '<TABLE WIDTH="100%" BORDER="0">' );
	for( counter = 0; counter <= sponsors[0].length / 3; counter++ )
	{
		document.write( '<TR>' );
		for( rowCount = 0; rowCount < 3; rowCount++ )
		{
			if( cellCounter < sponsors[0].length )
			{
				hrefString = "";
				hrefCloser = "";
				if( sponsors[2][cellCounter] != "#" )
				{
					hrefString = '<A HREF="' + sponsors[2][cellCounter] + '" target="_blank">';
					hrefCloser = '</A>';
				}
					
				document.write( '<TD ALIGN="CENTER">' + hrefString + '<IMG SRC="' + path + 'images/sponsors/'+ sponsors[0][cellCounter] + '.jpg" ALT="' + sponsors[2][cellCounter] + '" BORDER="0">');
				document.write( '<DIV CLASS="bodyText">' + sponsors[1][cellCounter] + hrefCloser + '</DIV></TD>');
				cellCounter++;
			}
		}
		document.write( '</TR><TR><TD COLSPAN="3">&nbsp;</TD></TR>' );
	}
	document.write( '</TABLE>' );
	

}


/*****************************************
* rnd(  )
*
* Seeds the rand() function
*********************************************************************************/	
function rnd() 
{
		rnd.seed = (rnd.seed*9301+49297) % 233280;
		return rnd.seed/(233280.0);
};

/*****************************************
* rand(  )
*
* Returns a randomly generated number (via rnd()) with the specified ceiling
*********************************************************************************/	
function rand(number) 
{
		return Math.ceil(rnd()*number);
};
