
	window.BB	= window.BB || {} ;
	BB.INTERVAL	= function () {

		/* PRIVATE (CLOSURES) */

		var now, then, interval_d, interval_h, interval_m, interval_s, interval ;

		function calculate( seconds, v1, v2 ) {
		 	var s = ( ( Math.floor( seconds / v1 ) ) % v2 ).toString();
			return ( s.length < 2 ) ? "0" + s : s ;
		}

		function write( element, value ) {
			if ( element && value ) {
				if ( typeof element.innerText === "string" ) {
					element.innerText	= value ;
				} else {
					element.textContent	= value ;
				}
				return true ;
			}
			return false ;
		}

		/* PUBLIC */

		function clear() {
			interval_d	= null ;
			interval_h	= null ;
			interval_m	= null ;
			interval_s	= null ;
			if ( interval ) {
				clearInterval( interval ) ;
				interval	= null ;
			}
			return true ;

		}

		function countdown() {
			now	= new Date() ;
			if ( then > now ) {

				var i = Math.floor( ( then - now ) / 1000 ) ;
				if ( interval_d ) { write( interval_d, calculate( i, 86400, 100000 ) ); }
				if ( interval_h ) { write( interval_h, calculate( i, 3600, 24 ) ); }
				if ( interval_m ) { write( interval_m, calculate( i, 60, 60 ) ); }
				if ( interval_s ) { write( interval_s, calculate( i, 1, 60 ) ); }

			} else {
				clear() ;
			}
			return true ;
		}

		C4.BOM.addEvent( window, "load", function () {
			if ( document.getElementById ) { /* no DOM, no point */
				then		= new Date( BB.INTERVAL.date ) ;
				interval_d	= document.getElementById( "interval_d" ) ;
				interval_h	= document.getElementById( "interval_h" ) ;
				interval_m	= document.getElementById( "interval_m" ) ;
				interval_s	= document.getElementById( "interval_s" ) ;
				interval	= setInterval( BB.INTERVAL.countdown, 1000 ) ;
				return true ;
			}
			return false ;
		} ) ; /* self-initialising */
		C4.BOM.addEvent( window, "beforeunload", function () { BB.INTERVAL.clear() ; } ) ; /* self-destructing */

		return {

			clear		: clear ,
			countdown	: countdown

		} ;

	}() ;
