/*======================================================================
	filmstrip.js
------------------------------------------------------------------------
	JavaScript
	
	PURPOSE
		Handle dynamic viewing of filmstrips on the data entry and 
	archive pages.


	HISTORY
	
	2007-11-18, Created, Jim Rich
	for www.WindowsAroundTheWorld.org
=======================================================================*/

			//Add new schools here if multiple in an area
			var bostonSchools1headDisplay;
			var bostonSchools1dataDisplay;
			var bostonSchools2headDisplay;
			var bostonSchools2dataDisplay;

			var tobagoSchools1headDisplay;
			var tobagoSchools1dataDisplay;
			var tobagoSchools2headDisplay;
			var tobagoSchools2dataDisplay;

			var filmstripToggleState = 'area';
			var bostonSchoolChoice = '1';
			var tobagoSchoolChoice = '1';

			var cfilmstripToggleState;
			var cbostonSchoolChoice;
			var ctobagoSchoolChoice;


			cfilmstripToggleState = readCookie('filmstripToggleState');
			cbostonSchoolChoice = readCookie('bostonSchoolChoice');
			ctobagoSchoolChoice = readCookie('tobagoSchoolChoice');


			//Get the cookie values if they exist
			if(cfilmstripToggleState !== ''){
			filmstripToggleState = cfilmstripToggleState;}

			if(cbostonSchoolChoice !== ''){
			bostonSchoolChoice = cbostonSchoolChoice;}

			if(ctobagoSchoolChoice !== ''){
			tobagoSchoolChoice = ctobagoSchoolChoice;}

			//Write the cookie values
			createCookie('filmstripToggleState',filmstripToggleState,1000);
			createCookie('bostonSchoolChoice',bostonSchoolChoice,1000);
			createCookie('tobagoSchoolChoice',tobagoSchoolChoice,1000);







			function createCookie(name,value,days) {
			if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
			}
			else var expires = "";
			document.cookie = name+"="+value+expires+"; path=/";
			}

			function readCookie(name) {
			var nameEQ = name + "=";
			var ca = document.cookie.split(';');
			for(var i=0;i < ca.length;i++) {
					var c = ca[i];
					while (c.charAt(0)==' ') c = c.substring(1,c.length);
					if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
				}
				return null;
			}
			
			// Toggle the filmstrip display
			function toggleFilmstrips(){

			if(filmstripToggleState == 'area')
			{

			filmstripToggleState = 'all';
			document.getElementById('showFilmstrips').style.backgroundPosition='0 0';

			//get current state
			
			bostonSchools1headDisplay = document.getElementById('bostonSchools1head').style.display;
			bostonSchools1dataDisplay = document.getElementById('bostonSchools1data').style.display;
			bostonSchools2headDisplay = document.getElementById('bostonSchools2head').style.display;
			bostonSchools2dataDisplay = document.getElementById('bostonSchools2data').style.display;

			tobagoSchools1headDisplay = document.getElementById('tobagoSchools1head').style.display;
			tobagoSchools1dataDisplay = document.getElementById('tobagoSchools1data').style.display;
			tobagoSchools2headDisplay = document.getElementById('tobagoSchools2head').style.display;
			tobagoSchools2dataDisplay = document.getElementById('tobagoSchools2data').style.display;


			//hide unselected titles
			document.getElementById('boston1NotSelected').style.display = 'none';
			document.getElementById('boston2NotSelected').style.display = 'none';
			document.getElementById('tobago1NotSelected').style.display = 'none';
			document.getElementById('tobago2NotSelected').style.display = 'none';

			document.getElementById('bostonSecondTitle').style.display = 'none';
			document.getElementById('tobagoSecondTitle').style.display = 'none';


			//display all
			document.getElementById('bostonSchools1head').style.display = '';
			document.getElementById('bostonSchools1data').style.display = '';
			document.getElementById('bostonSchools2head').style.display = '';
			document.getElementById('bostonSchools2data').style.display = '';

			document.getElementById('tobagoSchools1head').style.display = '';
			document.getElementById('tobagoSchools1data').style.display = '';
			document.getElementById('tobagoSchools2head').style.display = '';
			document.getElementById('tobagoSchools2data').style.display = '';


			}
			else
			{
			filmstripToggleState = 'area';
			document.getElementById('showFilmstrips').style.backgroundPosition='0 -36px';

			//show unselected titles
			document.getElementById('boston1NotSelected').style.display = 'inline';
			document.getElementById('boston2NotSelected').style.display = 'inline';
			document.getElementById('tobago1NotSelected').style.display = 'inline';
			document.getElementById('tobago2NotSelected').style.display = 'inline';

			document.getElementById('bostonSecondTitle').style.display = 'inline';
			document.getElementById('tobagoSecondTitle').style.display = 'inline';




			// reset displays
			if(bostonSchools1headDisplay == undefined){
			    if(bostonSchoolChoice == '1'){
			        document.getElementById('bostonSchools1head').style.display = '';
			    }
			    else {
			        document.getElementById('bostonSchools1head').style.display = 'none';
			    }
			}
			else {
			    document.getElementById('bostonSchools1head').style.display = bostonSchools1headDisplay;
			}
			
			if(bostonSchools1dataDisplay == undefined){
			    if(bostonSchoolChoice == '1'){
			    document.getElementById('bostonSchools1data').style.display = '';
			    }
			    else {
			    document.getElementById('bostonSchools1data').style.display = 'none';
			    }
			}
			else {
			    document.getElementById('bostonSchools1data').style.display = bostonSchools1dataDisplay;
			}
			
           if(bostonSchools2headDisplay == undefined){
               if(bostonSchoolChoice == '2'){
			    document.getElementById('bostonSchools2head').style.display = '';
			    }
			    else {
			    document.getElementById('bostonSchools2head').style.display = 'none';
			    }
			}
			else {
			    document.getElementById('bostonSchools2head').style.display = bostonSchools2headDisplay;
			}
			
			if(bostonSchools2dataDisplay == undefined){
			    if(bostonSchoolChoice == '2'){
			    document.getElementById('bostonSchools2data').style.display = '';
			    }
			    else {
			    document.getElementById('bostonSchools2data').style.display = 'none';
			    }
			}
			else {
			    document.getElementById('bostonSchools2data').style.display = bostonSchools2dataDisplay;
			}
			
			
			
			
			
			
			
			
			
			if(tobagoSchools1headDisplay == undefined){
			    if(tobagoSchoolChoice == '1'){
			    document.getElementById('tobagoSchools1head').style.display = '';
			    }
			    else {
			    document.getElementById('tobagoSchools1head').style.display = 'none';
			    }
			}
			else {
			    document.getElementById('tobagoSchools1head').style.display = tobagoSchools1headDisplay;
			}
			
			if(tobagoSchools1dataDisplay == undefined){
			    if(tobagoSchoolChoice == '1'){
			    document.getElementById('tobagoSchools1data').style.display = '';
			    }
			    else {
			    document.getElementById('tobagoSchools1data').style.display = 'none';
			    } 
			}
			else {
			    document.getElementById('tobagoSchools1data').style.display = tobagoSchools1dataDisplay;
			}
			
            if(tobagoSchools2headDisplay == undefined){
                if(tobagoSchoolChoice == '2'){
			    document.getElementById('tobagoSchools2head').style.display = '';
			    }
			    else {
			    document.getElementById('tobagoSchools2head').style.display = 'none';
			    }
			}
			else {
			    document.getElementById('tobagoSchools2head').style.display = tobagoSchools2headDisplay;
			}
			
			
			
			if(tobagoSchools2dataDisplay == undefined){
			    if(tobagoSchoolChoice == '2'){
			    document.getElementById('tobagoSchools2data').style.display = '';
			    }
			    else {
			    document.getElementById('tobagoSchools2data').style.display = 'none';
			    }
			    
			}
			else {
			    document.getElementById('tobagoSchools2data').style.display = tobagoSchools2dataDisplay;
			}
			
			}
			
			//write the cookie
            createCookie('filmstripToggleState',filmstripToggleState,1000);

			}
			
		    function setSchool1(city) {
		    
			document.getElementById(city + 'Schools1head').style.display='';
			document.getElementById(city + 'Schools1data').style.display='';
			document.getElementById(city + 'Schools2head').style.display='none';
			document.getElementById(city + 'Schools2data').style.display='none';
			
			createCookie(city + 'SchoolChoice','1',1000);
		    }
			
		    function setSchool2(city) {
		    
			document.getElementById(city + 'Schools1head').style.display='none';
			document.getElementById(city + 'Schools1data').style.display='none';
			document.getElementById(city + 'Schools2head').style.display='';
			document.getElementById(city + 'Schools2data').style.display='';
			
			createCookie(city + 'SchoolChoice','2',1000);
		    }
			
			

			//Get the view preferences
			function init() {

			if(bostonSchoolChoice == '1')
			{
			   setSchool1('boston');
			}
			else {
               		   setSchool2('boston');
			}


			if(tobagoSchoolChoice == '1')
			{
			    setSchool1('tobago');
			}
			else {
			    setSchool2('tobago');
			}
			
			
			if(filmstripToggleState=='area'){
			filmstripToggleState = 'all'
			}
			else {
			filmstripToggleState = 'area'

			}

			//set initial filmstrip
			toggleFilmstrips();
			
			}

