var timerID = null
var timerRunning = false
var counter=0
function toggleclock(){
    if(timerRunning){
        stopclock();
    }else{
        startclock();
    }
}

function stopclock(){       
    timerRunning = false;
    showtime();
    clearTimeout(timerID);        
    document.clock.clockcontrol.src="http://www.simoncapp.com/clock/play.png";
    document.clock.clockcontrol.alt="Run the pizza";
}

function startclock(){    
    resizeclock()
    stopclock()
    timerRunning = true;    
    showtime()            
    document.clock.clockcontrol.src="http://www.simoncapp.com/clock/pause.png";
    document.clock.clockcontrol.alt="Pause the pizza";
}
function resizeclock(){    
   // document.clock.clockbackground.style.width=document.body.clientHeight// * 0.8;
   // document.clock.clockbackground.style.height=document.body.clientHeight// * 0.8;//document.body.clientHeight;
   // document.clock.clockbackground.style.marginTop=-1*document.body.clientHeight/7;//aribtrary: shift up
   
}
var timercounter=0;
var offset=0;
var lastsegment=-1;
function showtime(){
    var now = new Date();
    var seconds = now.getSeconds();
	    //    var hours = now.getHours()
	    //var minutes = now.getMinutes()    
	    //var timeValue = "" + ((hours > 12) ? hours - 12 : hours)
	    //timeValue  += ((minutes < 10) ? ":0" : ":") + minutes
	    //timeValue  += ((seconds < 10) ? ":0" : ":") + seconds
	    //timeValue  += (hours >= 12) ? " P.M." : " A.M."    
    if(timerRunning){
      timerID = setTimeout("showtime()",1000)    //seems to need to be here
    }
    timercounter+=1;    
    var segment=integerdivide(timercounter,2) % 12 ;//this is 1 per n seconds, ranging from 0 to 11
	//segment=segment+1;//deliberately to range 1 to 12
    //alert( timercounter + "    " +   segment);    
    

    if (segment!=lastsegment)
    {
	   var el=document.getElementById("clockface"); 	   
	   lastsegment=segment;
	   //if (segment==0)//change source, and reset offset
 	   //{
		//el.style.backgroundImage="url(pizza0-6s.JPG)";
		//offset=0;
	   //} 
	   //else if (segment==7)
	  // {
		//el.style.backgroundImage="url(pizza7-12s.JPG)";
		//offset=0;
	   //}
	   //else
        //   {
		offset-=174;//height of each image in the source in pixels, -ve offset
  	   //}	   

	   
   	   el.style.backgroundPosition="0px " + offset + "px";
	

    }



       
    
}
function integerdivide ( numerator, denominator ) {
    // In JavaScript, dividing integer values yields a floating point result (unlike in Java, C++, C)
    // To find the integer quotient, reduce the numerator by the remainder first, then divide.
    var remainder = numerator % denominator;
    var quotient = ( numerator - remainder ) / denominator;
    
    return quotient;    
}




