/*
 * Copyright Ben Hutchins
 * */
var timerID = null;

var start=0;
var now=null;
var finalhours=null;
var finalminutes=null;
var finalseconds=null;
var rseconds=null;
var rminutes=null;

var digit=null;
var countDown = 60;

function startclock() {
        start = new Date();
        finalseconds = start.getSeconds();
	//add countDown time to minutes
        finalminutes = start.getMinutes()+countDown;
        if (finalminutes>=60) {
		finalminutes -= 60;
		finalhours = start.getHours()+1;
	}
        else {
		finalhours = start.getHours();
	};
//        document.clock.timer.value = ""
}

//This function includes the capability for displaying the current time
//The displays in the HTML have been commented out
//as have the functions in this section

function showtime () {
        now = new Date();
        var hours = now.getHours();
        var minutes = now.getMinutes();
        var seconds = now.getSeconds();
        var timeValue = new String("");

//Prepare current time for printing
        var timeValue = "" + ((hours >12) ? hours -12 :hours);
        timeValue += ((minutes < 10) ? ":0" : ":") + minutes;
        timeValue += ((seconds < 10) ? ":0" : ":") + seconds;
           timeValue += (hours >= 12) ? " P.M." : " A.M.";

//Display current time in text field "face"
//       document.clock.face.value = timeValue;
        
//Print out time remaining
        
// Assumes that timer will not be used for more than one hour
//start indicates that timer has been clicked if ne 0
    if(start != 0){
        if (finalseconds >= seconds) {rseconds = finalseconds-seconds}
            else {rseconds = 60+finalseconds-seconds;
                     minutes += 1}
      }; //end if

         if (finalminutes >= minutes) {rminutes = finalminutes-minutes}
            else {rminutes = 60+finalminutes-minutes}; // end if
        
//Check for possibility that clock has run over
//         alert("rminutes= "+rminutes+ " countDown= "+countDown);
         if (rminutes <= countDown) { 
                var timeValue = "" +((rminutes < 10) ? "0" : "") + rminutes;
                timeValue += ((rseconds < 10) ? ":0" : ":") + rseconds}
         else {var timeValue = "00.00"}; // end if

//Display remaining time is text field "timer"
//        document.clock.timer.value = timeValue;
     
	document.getElementById('cd').innerHTML = timeValue;

//Check for time run out
    if (timeValue =="00:00") {
	  setTimeout("forcelogout()",1000);
          start=0
    }; // end if

        timerID = setTimeout("showtime()",1000);
} // end function

function setWatch(n){
//Set time to countdown
countDown = n;
//alert("CountDown "+n+" Minutes")
}

window.addEvent('load', function() {
	montre();
	if( $('username') )
		$('username').focus();
		return true;
});

function forcelogout() {
	window.location = '/logout.html?nextURL=/changelog.php';
}

function montre(id) {
	var d = document.getElementById(id);
	for (var i = 1; i<=10; i++) {
		if (document.getElementById('smenu'+i)) {
			document.getElementById('smenu'+i).style.display='none';
		}
	}
	if (d) {d.style.display='block';}
}


// NOTE: MooTools Feature
window.addEvent('domready', function(){
	//Lightbox.show('assets/images/25.jpg', 'Spheres in construction');

	// Add Tips
	var as = [];
	$ES('a').each(function(a){
		if ( a.getAttribute('rel') != 'lightbox' && a.getAttribute('rel') != 'lightbox-http' && a.getAttribute('title') )
			as.push(a);
	});
	new Tips( as, {
		initialize:function(){
			this.fx = new Fx.Style(this.toolTip, 'opacity', {duration: 500, wait: false}).set(0);
		},
		onShow: function(toolTip) {
			this.fx.start(1);
		},
		onHide: function(toolTip) {
			this.fx.start(0);
		},
		maxOpacity: 0.9,
		maxTitleChars: 25,
	});
});


