// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

// how often should we run this
const timeout_period_s = 1;

function updateTime()
{
		objStart = objStart + timeout_period_s;
		
		var s = parseInt(objStart);
		
		//get minutes
		var m = parseInt(s / 60);
		
		//shrink seconds
		s = (s % 60);
		
		//get hours:
		var h = parseInt(m / 60);
		
		//shrink minutes:
		m = (m % 60);
		
		var timeElapsed = "Time Elapsed: " + checkTime(h) + ":" + checkTime(m) + ":" + checkTime(s)
		
		// check div. It will be missing in a clocked out state
		if (document.getElementById('time')) 
		{
			document.getElementById('time').innerHTML = timeElapsed;
		}
		
		t = setTimeout("updateTime()", timeout_period_s * 1000);
}    

function stopTimer()
{
    if(t)
        clearTimeout(t);
    objStart=null;
}               
function checkTime(i)
{
    if(i<10)
        i="0" + i;
    return i;
}


document.observe("dom:loaded", function() {
  // the element in which we will observe all clicks and capture
  // ones originating from pagination links
  var container = $(document.body)

  if (container) {
    var img = new Image
    img.src = '/images/ajax-loader.gif'

    function createSpinner() {
      new Element('img', { src: img.src, 'class': 'spinner' })
    }

    container.observe('click', function(e) {
      var el = e.element()
      //if (el.match('.pagination a')) {
      if (el.match('.pagination a') ) {
	  	Element.show("spinner");
        //el.up(".pagination").insert(createSpinner());
        new Ajax.Request(el.href, { method: 'get' });
		Element.hide("spinner");
        e.stop();
      }
    })
  }
})

