var Countdowntimer = function() {  
  this.s = null;  // The seconds left in the timer  
  this.reset = null; // The seconds to reset the timer to : HJG Dont need reset
  this.el = null;  // The element container used to draw the timer : ?
  this.timerId = null; // The timerId as provided by setTimeout : ?
  this.isStopped = true;
  return {  
  
	/**  
	 * Initialize the timer with the number of seconds and the element that  
	 * will be used to draw the timer.  
	 * @param {Integer} s The number of seconds in the timer 
	 * @param {String} el The id of the element whose contents will be replaced  
	 */  
  
	init : function(s, el) {  
	  Countdowntimer.s = s;  
	  Countdowntimer.reset = s;  
	  Countdowntimer.el = document.getElementById(el);  
	},  
	/**  
	 * Draw the timer and then start the countdown  
	 */  
	start : function() {  
	  Countdowntimer.isStopped = false;
	  Countdowntimer.draw(); 
	  if (Countdowntimer.s > 0 &&!Countdowntimer.timerId) {  
		Countdowntimer.timerId = setTimeout(Countdowntimer.step, 1000);  
	  }  
	}, 
	stop : function() {
		if (!Countdowntimer.s) return;
		Countdowntimer.isStopped = true;
	},
	resume : function() {
		if (!Countdowntimer.s) return;
		Countdowntimer.isStopped = false;
		Countdowntimer.timerId = setTimeout(Countdowntimer.step, 1000); 
	},
	/**  
	 * If the timer has reached zero, notify the user. Otherwise, decrement  
	 * it, draw it, and call this method again in 1 second.  
	 */  
	step : function() {  
	  if (Countdowntimer.isStopped) return;
	  if (Countdowntimer.s > 0) {  
		Countdowntimer.s--;  
		Countdowntimer.draw();  
		Countdowntimer.timerId = setTimeout(Countdowntimer.step, 1000);  
	  }  
	  else {   /* Jumps to the next throwdown - Skip button */
		window.location = $('nextThrowdown').getAttribute('href'); 
	  }  
	},  
	/** 
	 * Draw the value of the timer in the container element.  Draw extra 0 and red if lower than 10
	 */  
	draw : function() {  
	  if (Countdowntimer.s < 10) {
		Countdowntimer.el.innerHTML = '<span>0' + Countdowntimer.s + '</span>';  
		}  
	  else { 
		Countdowntimer.el.innerHTML = Countdowntimer.s;   
	  }
	}  
  };  
}();  
window.onload = function() {  
	/* Set second here */
}  
var _landing = {};
_landing.constructor = function(params) {
	if(!params["battleType"].match(/photo|video/)) {
		throw('no or wrong type passed');
	}
	for(var i in params) {
		this[i] = params[i];
	}
	if(this.battleType == "photo") {
	var _startCountdown = function(){
		Countdowntimer.init(24,'countdown');  
		Countdowntimer.start();  
		window.throwdowns.addTimerPauseEvents();
	};
		window.addEvent("load",_startCountdown);
	}
};

_landing.addTimerPauseEvents = function() {
	$$('textarea').each( function(item) {
		item.onfocus = function() { Countdowntimer.stop();	}
		item.onblur = function() { Countdowntimer.resume();	}
	});
};

dojo.provide( 'takkle.view.page.throwdown.landing' );
dojo.declare( 'takkle.view.page.throwdown.landing', takkle.view.page, _landing);
