var x = 0;
var ismymovies;
movies=new Array();
movies[x]=new Movie("2002/07/28", " Ultimate X", "f_ultimate.html");
x++;
movies[x]=new Movie("2002/07/28", " Bad Company", "f_badcompany.html");
x++;
movies[x]=new Movie("2002/08/05", " Heaven", "f_heaven.html");
x++;
movies[x]=new Movie("2002/08/16", " Spy Kids 2", "f_spykids2.html");
x++;
movies[x]=new Movie("2002/08/30", " Insomnia", "f_insomnia.html");
x++;
movies[x]=new Movie("2002/08/23", " Reign of Fire", "f_reignoffire.html");
x++;
movies[x]=new Movie("2002/09/06", " The Importance of Being Earnest", "f_tiobe.html");
x++;
movies[x]=new Movie("2002/09/13", " Signs", "f_signs.html");
x++;
movies[x]=new Movie("2002/10/04", " Lilo and Stitch", "f_liloandstitch.html");
x++;
movies[x]=new Movie("2002/10/11", " The Rookie", "f_therookie.html");
x++;
movies[x]=new Movie("2002/10/25", " Halloween: Resurrection", "f_halloween.html");
x++;
movies[x]=new Movie("2002/11/01", " Hope Springs", "");
x++;
movies[x]=new Movie("2002/11/08", " Rabbit Proof Fence", "f_rabbit.html");
x++;
//movies[x]=new Movie("2002/11/15", " Four Feathers", "f_feathers.html");
//x++;
movies[x]=new Movie("2002/11/29", " Santa Clause 2: Mrs Clause", "f_santaclause2.html");
x++;
movies[x]=new Movie("2002/12/20", " Country Bears", "");
x++;
movies[x]=new Movie("2002/11/29", " Quiet American", "f_quiet.html");
x++;
//movies[x]=new Movie("2002/12/20", " Sweet Home Alabama", "f_sweethome.html");
//x++;
movies[x]=new Movie("2003/01/16", " Sweet Home Alabama", "f_sweethome.html");
x++;
movies[x]=new Movie("2002/12/26", " The Lion King - IMAX", "f_lionking.html");
x++;
//movies[x]=new Movie("2002/12/13", " Dirty Pretty Things", "f_dirtyprettythings.html");
//x++;
movies[x]=new Movie("2003/01/16", " Dirty Pretty Things", "f_dirtyprettythings.html");
x++;
//movies[x]=new Movie("2003/01/03", " City of God ", "f_citygod.html");
//x++;
movies[x]=new Movie("2003/02/02", " City of God ", "f_citygod.html");
x++;
movies[x]=new Movie("2003/03/07", " Frida ", "f_frida.html");
x++;
movies[x]=new Movie("2003/03/06", " Moonlight Mile ", "f_moonlightmile.html");
x++;
movies[x]=new Movie("2003/03/05", " The Hours ", "f_thehours.html");
x++;
movies[x]=new Movie("2003/02/14", " Treasure Planet ", "f_treasureplanet.html");
x++;
//movies[x]=new Movie("2003/01/16", " Chicago ", "f_chicargo.html");
//x++;
movies[x]=new Movie("2003/03/04", " Chicago ", "f_chicargo.html");
x++;
movies[x]=new Movie("2003/03/14", " Confessions of a Dangerous Mind ", "f_confessions.html");
x++;
movies[x]=new Movie("2003/03/28", " The Recruit ", "f_recruit.html");
x++;
movies[x]=new Movie("2003/04/04", " Shanghai Knights ", "f_shanghaiknights.html");
x++;
//movies[x]=new Movie("2003/04/04", " The Hot Chick ", "f_hotchick.html");
//x++;
movies[x]=new Movie("2003/04/25", " The 25th Hour ", "f_25hour.html");
x++;
movies[x]=new Movie("2003/09/26", " Ghosts of the Abyss ", "f_ghostabyss.html");
x++;
movies[x]=new Movie("2003/04/11", " Jungle Book 2 ", "f_junglebook2.html");
x++;
movies[x]=new Movie("2003/05/09", " Hope Springs ", "f_hopesprings.html");
x++;
movies[x]=new Movie("2003/05/02", " Heartlands ", "f_heartlands.html");
x++;
movies[x]=new Movie("2003/05/28", " Bringing Down The House ", "f_bringhouse.html");
x++;
movies[x]=new Movie("2003/05/23", " Full Frontal ", "f_fullfrontal.html");
x++;
movies[x]=new Movie("2003/05/23", " The Hot Chick ", "f_hotchick.html");
x++;
movies[x]=new Movie("2003/06/20", " Tadpole ", "f_tadpole.html");
x++;
movies[x]=new Movie("2003/07/17", " Bruce Almighty ", "f_brucealmighty.html");
x++;
movies[x]=new Movie("2003/07/18", " Piglet's Big Movie ", "f_piglet.html");
x++;
movies[x]=new Movie("2003/07/18", " Four Feathers", "f_feathers.html");
x++;
movies[x]=new Movie("2003/09/27", " Spy Kids 3D", "f_spykids3.html");
x++;
movies[x]=new Movie("2003/08/29", " Veronica Guerin ", "f_veronica.html");
x++;
movies[x]=new Movie("2003/11/09", " Pirates of the Caribbean ", "f_pirates.html");
x++;
movies[x]=new Movie("2003/08/29", " The Lizzie McGuire Movie ", "f_lizzie.html");
x++;
//movies[x]=new Movie("2003/08/29", " A View From the Top ", "f_viewfrom.html");
//x++;
movies[x]=new Movie("2003/11/08", " Calendar Girls", "f_calendar.html");
x++;
movies[x]=new Movie("2003/09/30", " Once Upon a Time in Mexico ", "f_mexico.html");
x++;
movies[x]=new Movie("2003/11/12", " Holes ", "f_holes.html");
x++;
movies[x]=new Movie("2003/12/25", " Freaky Friday ", "f_freaky.html");
x++;
movies[x]=new Movie("2003/12/24", " Finding Nemo ", "f_nemo.html");
x++;
movies[x]=new Movie("2003/11/25", " Kill Bill - Vol. 1", "f_killbill.html");
x++;
movies[x]=new Movie("2003/11/13", " Seabiscuit ", "f_seabiscuit.html");
x++;
movies[x]=new Movie("2003/11/14", " Octane ", "f_octane.html");
x++;
movies[x]=new Movie("2003/11/28", " Intermission ", "f_intermission.html");
x++;

movies[x]=new Movie("2003/12/05", " Brother Bear ", "f_brotherbear.html");
x++;
movies[x]=new Movie("2003/12/26", " Cold Mountain ", "f_coldmountain.html");
x++;

movies[x]=new Movie("2004/01/23", " Scary Movie 3", "f_scary_movie3.html");
x++;
movies[x]=new Movie("2004/01/23", " Human Stain ", "f_humanstain.html");
x++;
movies[x]=new Movie("2004/02/13", " Haunted Mansion ", "f_hauntedmansion.html");
x++;
movies[x]=new Movie("2004/04/30", " Our House ", "f_ourhouse.html");
x++;
movies[x]=new Movie("2004/04/16", " Hidalgo ", "f_hidalgo.html");
x++;
movies[x]=new Movie("2004/04/23", " Kill Bill: Vol. 2 ", "f_killbill2.html");
x++;
movies[x]=new Movie("2004/04/15", " Under the Tuscan Sun ", "f_tuscan.html");
x++;
movies[x]=new Movie("2004/01/30", " Cold Creek Manor ", "f_coldcreekmanor.html");
x++;
movies[x]=new Movie("2004/02/27", " House of Sand & Fog ", "f_sandfog.html");
x++;
movies[x]=new Movie("2004/06/11", " I'm Not Scared ", "f_notscared.html");
x++;
movies[x]=new Movie("2004/06/19", " Jersey Girl ", "f_jerseygirl.html");
x++;
movies[x]=new Movie("2004/06/25", " The Ladykillers ", "f_ladykillers.html");
x++;
movies[x]=new Movie("2004/04/14", " Starsky & Hutch (WE)", "f_starsky.html");
x++;
movies[x]=new Movie("2004/04/14", " Starsky & Hutch ", "f_starsky.html");
x++;
movies[x]=new Movie("2004/04/16", " The Station Agent ", "f_station.html");
x++;
movies[x]=new Movie("2004/05/07", " Confessions of a Teenage Drama Queen ", "f_dramaqueen.html");
x++;

movies[x]=new Movie("2004/07/30", " King Arthur ", "f_kingarthur.html");
x++;
movies[x]=new Movie("2004/08/27", " Raising Helen ", "f_raisinghelen.html");
x++;
movies[x]=new Movie("2004/08/06", " Home on the Range ", "f_homerange.html");
x++;
movies[x]=new Movie("2004/08/20", " The Village ", "f_village.html");
x++;

//added 03 December 2002 to make sure links work when page is hosted by mymovies... variable set to 1 in pages hosted by them
if (ismymovies != 1) {
var xtra = '';
}
else {
var xtra = 'http://www.thefilmfactory.co.uk/';
}



function Movie(date,name,link) {
	if (date == ''){
		this.date = '2000/01/01';
	}else{
		this.date=date;
	}
	
	this.name=name;
	this.link=link;
}


function sortBy(prop) {
	sortProp=prop;
	movies=movies.sort(sortFunc);
}


function sortFunc(movie1,movie2) {
	if (movie1[sortProp]<movie2[sortProp]) retVal=-1;
	else if (movie1[sortProp]>movie2[sortProp]) retVal=1;
	else retVal=0;
	return retVal;
}


function layerWrite(id,nestref,text) {
	if (document.layers) {
		var lyr = (nestref)? eval('document.'+nestref+'.document.'+id+'.document') : document.layers[id].document
		lyr.open()
		lyr.write(text)
		lyr.close()
	}
	else { document.all[id].innerHTML = text}
}



function displaydata()
	{
	var Month = new Array();
	Month = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
	
	var todaysdate = new Date();
	var thismoviesdate = new Date();
	var thissuffix = '';
	var isShown = false;
	var printedfirstmonthsmovie = false;
	var shownfirstmonth = false;
	var thismoviesday = 0;
	var thismoviemonth = movies[0].date;
	var oldmoviemonth = 0;
	for (j=0;j<movies.length;j++)
	{
	//for each movie
	if (movies[j].link != ''){ //only for the left side nav...
		if (movies[j].date == ''){
				var thismoviesdate = new Date('2000/01/01');	
			}else{
				var thismoviesdate = new Date(movies[j].date);
			}
			
			if ((thismoviesdate <= todaysdate) && !isShown) {
			//write the very first movies, they have no date attached...
				if (timeDifference(todaysdate,thismoviesdate) < 30){
				document.write ('<font class=head10><a href="'+xtra+''+movies[j].link+'">'+ movies[j].name+'</a></font><br>');
				}
			} else {
			 
				isShown=true;
				thismoviemonth = thismoviesdate.getMonth();
				
				if ((thismoviesdate.getMonth() >= todaysdate.getMonth() && (!shownfirstmonth) && (!printedfirstmonthsmovie)) ){
					j++;
					shownfirstmonth = true;
					document.write('<br><font class=head12><b>' + Month[thismoviesdate.getMonth()] + '</b></font><br>');
					oldmoviemonth = parseInt(thismoviesdate.getMonth())
					j--;
				}
				if (parseInt(thismoviesdate.getMonth()) != oldmoviemonth){
					thismoviesday = thismoviesdate.getDate();
					thissuffix = printsuffix(thismoviesdate);
					document.write('<br><font class=head12><b>' + Month[thismoviesdate.getMonth()] + '</b></font><br><font class=head10>');
					if (movies[j].link != ''){
						document.write ('<a href="'+xtra+''+movies[j].link+'">');
					}
					
					document.write (movies[j].name);
					
					document.write ('&nbsp;(' + thismoviesday + thissuffix +')</a><br>');				
										
					document.write ('</font>');
					oldmoviemonth = parseInt(thismoviesdate.getMonth());
					
				} else {	
					thismoviesday = thismoviesdate.getDate();
					thissuffix = printsuffix(thismoviesdate);
					document.write('<font class=head10>');
					if (movies[j].link != ''){
						document.write ('<a href="'+xtra+''+movies[j].link+'">');
					}

					document.write (movies[j].name);

					document.write ('&nbsp;(' + thismoviesday + thissuffix +')</a><br>');				
										
					document.write ('</font>');
					oldmoviemonth = parseInt(thismoviesdate.getMonth());
					
			}
		}
	}	
  }
  }

	
sortBy('date');
displaydata();





function timeDifference(laterdate,earlierdate) {
    var difference = laterdate.getTime() - earlierdate.getTime();

    var daysDifference = Math.floor(difference/1000/60/60/24);

	return daysDifference;
    
}


			
function printsuffix(theday){
	var suffix = '';
	k = theday.getDate();
	var suffix = "th";
		switch (k)
		{
			case 1:
			case 21:
			case 31: 
				return "st";
			case 2:
			case 22:
				return "nd";
			case 3:
			case 23:
				return "rd";
		};
	return suffix;

}