/**
 * @author bhanbuch
 * 
 * looking for 3 divs with this style .countdown-digit and the id's are digit0, digit1, digit2
 * 
 * the body onload needs to fire the setCountdown function declared in this file
 * 
 * YAHOO.util.Event.onDOMReady(setCountdown);
 * 
 * <!-- Dependency -->  
 * <script type="text/javascript" src="http://yui.yahooapis.com/2.5.1/build/yahoo/yahoo-min.js" ></script> 
 * <!-- Event source file --> 
 * script type="text/javascript" src="http://yui.yahooapis.com/2.5.1/build/event/event-min.js" ></script>
 * 
 */


YAHOO.namespace("ib");

// declare the module
YAHOO.ib.countdown = function () 
{
    // properties
	var imageHeight = 48;
	var today = new Date(currentTime);
	var BigDay = new Date("August 8, 2008");
	var msPerDay = 86400000;
	var hours12 = msPerDay / 2;
	var timeLeft = (BigDay.getTime() - today.getTime() + hours12);
	var daysLeft = Math.abs(Math.floor(timeLeft / msPerDay));

    var init = function () 
	{
		YAHOO.util.Event.onDOMReady(YAHOO.ib.countdown.setCountDown);
    };

    var splitMe = function (s) 
	{
		var a = [];
		
		for ( var i=0; i<s.length; ++i )
		{
			a.push(s.charAt(i));
		}		
		return a;
    }; 

	var setY = function(id, pos)
	{
		//document.getElementById(id).style.backgroundPosition = ("0px -" + pos + "px");
		YAHOO.util.Dom.setStyle(id, 'backgroundPosition', ('0px -' + pos + 'px'));
	}

	var setCountDown = function()
	{
		var d = splitMe(daysLeft.toString())
		
		switch (d.length)
		{
			case 2:				
				setY("digit1", (imageHeight*d[0]));
				setY("digit2", (imageHeight*d[1]));
				break;
				
			case 1:				
				setY("digit1", 0);
				setY("digit2", (imageHeight*d[0]));
				break;
		}
	}

    return {
        // set up which functions should be public
        init: init,
		setCountDown: setCountDown
    };
}(); 

YAHOO.ib.countdown.init();