// JavaScript Document
// Oct 25, modified code for the Central Okanagan Sailing Association  (COSA)
// March 11, 2009 disabled slide show until new photos taken.
// Jan 8, 2009, doubled up the display of the rooftop cam during slide show.
// Dec 15, added another slide (webcamf.jpg) Roses Pub
// Dec 14, added a 3 second delay before showing initial live image to allow credits to be seen.
// Dec 13, chose to only show credits at start of slide show.
// Dec 13, streamlined slide show forcing refresh only on live camera.
// Dec 8, added slide show after dark.
// Dec 5, 2008, added seasonal time shifting. 
// March 11, 2009 turned off slide show for the summer
// July 15, 2009, added a line to function Live(0) to allow a maintenance image to display if required.
// previous working version was saved as webcam7Dec2008.htm

// get the Universal hour of the day
//	var camera =0 //initial setting is for live camera
//  var d = new Date();
//  var month = d.getUTCMonth();
//  var UTCHours = d.getUTCHours(); 
//  var UTCMinutes =d.getUTCMinutes();
  
  	
 	//preload specific images below. webcam.jpg is from the rooftop camera
	//and the other webcams are slides to be displayed during the night.
	var myimages=new Array();
	myimages[0]="davis/webcam.jpg";  //rooftop cam at KYC
	//myimages[0]="http://members.shaw.ca/jackborno/last.jpg"
	myimages[1]="webcamTitle.jpg"; //opening title image  
  	myimages[2]="webcamb.jpg";  //harbour lights
  	myimages[3]="webcamc.jpg";  //harbour lights 
	myimages[4]="webcam.jpg";  //rooftop cam at KYC
	myimages[5]="webcamd.jpg";  //Rose's pub 
  	myimages[6]="webcame.jpg";  //Fintry Queen
	myimages[9]="webcamunavailable.jpg"; //out of service slide	
	
  
	
		
					
  //start of function based on Universal Time to determine available hours with enough light for live camera.
    function selectwebcam(){;
	// get  Universal time 
  var d = new Date();
  var UTCMonth = d.getUTCMonth();
  var UTCHours = d.getUTCHours();  
  var UTCMinutes = d.getUTCMinutes();

  //camera =1 ;  //set slide show as default
  camera =0 ; //disabled slide show until new photos taken.. jca,  March 11, 2009
 if (UTCMonth ==0 && UTCHours ==15 && UTCMinutes >19) {camera=0}; //go live at 7:20 AM in January
 if (UTCMonth ==0 && UTCHours >=16 && UTCHours <=23) {camera=0};  
 if (UTCMonth ==0 && UTCHours >=0 && UTCHours <2 && UTCMinutes <15) {camera=0}; //extend live camera until 5:15 pm local time in late January
 if (UTCMonth ==1 && UTCHours ==15 && UTCMinutes >9) {camera=0}; //go live at 7:10 AM in February
 if (UTCMonth ==1 && UTCHours >=16 && UTCHours <=23) {camera=0};
 if (UTCMonth ==1 && UTCHours >=0 && UTCHours <2 && UTCMinutes <50) {camera=0}; //extend live camera until 5:50 pm local time in February
 if (UTCMonth ==2 && UTCHours >=14 && UTCHours <=23) {camera=0};
 if (UTCMonth ==2 && UTCHours >=0 && UTCHours <4) {camera=0}; //extend live camera until 7 pm local time in March (daylight savings starts)
 if (UTCMonth ==3 && UTCHours >=13 && UTCHours <=23) {camera=0};
 if (UTCMonth ==3 && UTCHours >=0 && UTCHours <4) {camera=0};
 if (UTCMonth ==4 && UTCHours >=12 && UTCHours <=23) {camera=0};
 if (UTCMonth ==4 && UTCHours >=0 && UTCHours <5 ) {camera=0};
 if (UTCMonth ==5 && UTCHours >=11 && UTCHours <=23) {camera=0};
 if (UTCMonth ==5 && UTCHours >=0 && UTCHours <5) {camera=0};
 if (UTCMonth ==6 && UTCHours >=11 && UTCHours <=23) {camera=0};
 if (UTCMonth ==6 && UTCHours >=0 && UTCHours <5 ) {camera=0};
 if (UTCMonth ==7 && UTCHours >=12 && UTCHours <=23) {camera=0};
 if (UTCMonth ==7 && UTCHours >=0 && UTCHours <4 ) {camera=0};
 if (UTCMonth ==8 && UTCHours >=13 && UTCHours <=23) {camera=0};
 if (UTCMonth ==8 && UTCHours >=0 && UTCHours <3 ) {camera=0};
 if (UTCMonth ==9 && UTCHours >=14 && UTCHours <=23) {camera=0};
 if (UTCMonth ==9 && UTCHours >=0 && UTCHours <2 ) {camera=0};
 if (UTCMonth ==10 && UTCHours >=15 && UTCHours <=23) {camera=0}; //live camera at 7 am in November
 if (UTCMonth ==10 && UTCHours >=0 && UTCHours <1 && UTCMinutes <25) {camera=0}; //extend live camera until 4:25 pm local time in November
 if (UTCMonth ==11 && UTCHours ==15 && UTCMinutes >19) {camera=0};  //go live at 7:20 AMlocal time in December
 if (UTCMonth ==11 && UTCHours >=16 && UTCHours <=23) {camera=0}; // stay live until 4 pm			 
 if (UTCMonth ==11 && UTCHours >=0 && UTCHours <1 && UTCMinutes <25) {camera=0}; //extend live camera until 4:25 pm local time in December
			  
			  
  //alert (UTCMonth + ":"  + UTCHours +":" + camera) //just for debugging purposes..			  
	
     
} 
// end of selectwebcam function


function Live() { ;
	 var t = 60; // interval in seconds  (1 minutes)
	  image = myimages[camera]; //name of the image 
	  if (!document.images) return;
	  selectwebcam();  //recheck UTC time for appropriate webcam images
	  //alert ("Live Routine " + "camera " + camera);  //code for debugging code
	  // switched off slide show  March 11, 2009 for the summer.. jca
	  camera =0;
	  if (camera != 0) {location.reload()};  //time to refesh web page and allow the slideshow
	 
 		 
	  tmp = new Date(); 
		tmp = "?"+tmp.getTime() ;	  //using "?+"tmp ensures that refresh grabs the most recent image. creates unique id for document.images
	  document.images["refresh"].src = myimages[camera]+ tmp;  // refresh or replace webcam image 1 on screen
	  //document.images["refresh"].src = myimages[9]; //display webcam unavailable slide
  	    setTimeout("Live()", t*1000) ;
	  }
	 
	  

function Slideshow(){;	
	var t = 10 ;// interval in seconds 
	image = myimages[slide]; //name of the image 
	if (!document.images) return;
	selectwebcam();  //recheck UTC time for appropriate webcam images
	//alert ("Slideshow Routine " + "camera " + camera + ":" + "slide = "  +slide); for debugging code
	if (camera == 0  ) {location.reload()}; // time to start over and go live camera..
	if (slide==0 || slide==4) {
	tmp = new Date() 
	tmp = "?"+tmp.getTime()
	document.images["refresh"].src = myimages[slide] +tmp} //refresh latest live image during slide show as well
	else  {
	document.images["refresh"].src = myimages[slide]};  // cycle slide images on screen
 	slide++
 	if (slide >6) {slide=0};
	if (slide == 1) slide++ // skip credits on repeated cycles after initial credit.			 
 	setTimeout("Slideshow()", t*1000) ;
}
 

