var current="Out Now"
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")

function countdown(yr,m,d) {

	theyear = yr;
	themonth = m;
	theday = d;
	
	var today=new Date()
	var todayy=today.getYear()
	
	if (todayy < 1000) {
		todayy+=1900;
	}
	
	var todaym=today.getMonth()
	var todayd=today.getDate()
	var todayh=today.getHours()
	var todaymin=today.getMinutes()
	var todaysec=today.getSeconds()
	var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec
	futurestring=montharray[m-1]+" "+d+", "+yr
	dd=Date.parse(futurestring)-Date.parse(todaystring)
	dday=Math.floor(dd/(60*60*1000*24)*1)
	dhour=Math.floor(((dd%(60*60*1000*24))/(60*60*1000)*1))
	dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
	dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)
	
	if(dday==0&&dhour==0&&dmin==0&&dsec==1){
		
		document.getElementById('countdown').innerHTML = '<img src="countdown-outnow.gif" alt="Ambients is Out Now! Click on the Amazon and iTunes links to purchase it" title="Ambients is Out Now! Click on the Amazon and iTunes links to purchase it" id="countdown_outnow" />';
		
		return
	} else {
	
		// Convert the numbers into strings
		var number_size = 36;
		var countdown = "";
		var day = dday.toString();
		var hour = dhour.toString();
		var minute = dmin.toString();
		var second = dsec.toString();
	
		image_link = '/images/mini-sites/ambients/countdown/';

		if (day < 0) {
			day = "0";
		}

		if (hour < 0) {
			hour = "0";
		}

		if (minute < 0) {
			minute = "0";
		}

		if (second < 0) {
			second = "0";
		}

		if (day.length < 2) {
			countdown += '<img src="' + image_link + '0.gif" class="countdown_number" alt="0" title="0" />';
			countdown += '<img src="' + image_link + '' + day.charAt(0) + '.gif" class="countdown_number" alt="' + day.charAt(0) + '" title="' + day.charAt(0) + '" />';
		} else {
			countdown += '<img src="' + image_link + '' + day.charAt(0) + '.gif" class="countdown_number" alt="' + day.charAt(0) + '" title="' + day.charAt(0) + '" />';
			countdown += '<img src="' + image_link + '' + day.charAt(1) + '.gif" class="countdown_number" alt="' + day.charAt(1) + '" title="' + day.charAt(1) + '" />';
		}

		countdown += '<img src="' + image_link + 'seperator.gif" class="countdown_seperator" alt="" title="" />';

		if (hour.length < 2) {
			countdown += '<img src="' + image_link + '0.gif" class="countdown_number" alt="0" title="0" />';
			countdown += '<img src="' + image_link + '' + hour.charAt(0) + '.gif" class="countdown_number" alt="' + hour.charAt(0) + '" title="' + hour.charAt(0) + '" />';
		} else {
			countdown += '<img src="' + image_link + '' + hour.charAt(0) + '.gif" class="countdown_number" alt="' + hour.charAt(0) + '" title="' + hour.charAt(0) + '" />';
			countdown += '<img src="' + image_link + '' + hour.charAt(1) + '.gif" class="countdown_number" alt="' + hour.charAt(1) + '" title="' + hour.charAt(1) + '" />';
		}

		countdown += '<img src="' + image_link + 'seperator.gif" class="countdown_seperator" alt="" title="" />';

		if (minute.length < 2) {
			countdown += '<img src="' + image_link + '0.gif" class="countdown_number" alt="0" title="0" />';
			countdown += '<img src="' + image_link + '' + minute.charAt(0) + '.gif" class="countdown_number" alt="' + minute.charAt(0) + '" title="' + minute.charAt(0) + '" />';
		} else {
			countdown += '<img src="' + image_link + '' + minute.charAt(0) + '.gif" class="countdown_number" alt="' + minute.charAt(0) + '" title="' + minute.charAt(0) + '" />';
			countdown += '<img src="' + image_link + '' + minute.charAt(1) + '.gif" class="countdown_number" alt="' + minute.charAt(1) + '" title="' + minute.charAt(1) + '" />';
		}

		countdown += '<img src="' + image_link + 'seperator.gif" class="countdown_seperator" alt="" title="" />';

		if (second.length < 2) {
			countdown += '<img src="' + image_link + '0.gif" class="countdown_number" alt="0" title="0" />';
			countdown += '<img src="' + image_link + '' + second.charAt(0) + '.gif" class="countdown_number" alt="' + second.charAt(0) + '" title="' + second.charAt(0) + '" />';
		} else {
			countdown += '<img src="' + image_link + '' + second.charAt(0) + '.gif" class="countdown_number" alt="' + second.charAt(0) + '" title="' + second.charAt(0) + '" />';
			countdown += '<img src="' + image_link + '' + second.charAt(1) + '.gif" class="countdown_number" alt="' + second.charAt(1) + '" title="' + second.charAt(1) + '" />';
		}



/*
		var countdown_style = ' width="24" height="38" style="background-image: url(\'/images/mini-sites/ambients/countdown-numbers.gif\'); ';
	
		if (day.length < 2) {
			countdown += '<img src="countdown/0.gif" class="countdown_number" alt="0" title="0" />';
			countdown += '<img src="/images/blank.gif" class="countdown_number" ' + countdown_style + 'background-position: 0px ' + Math.floor(number_size * parseInt(day.charAt(1))) + 'px;" alt="' + day[0] + '" title="' + day[0] + '" />';
		} else {
			countdown += '<img src="/images/blank.gif" class="countdown_number" ' + countdown_style + 'background-position: 0px ' + Math.floor(number_size * parseInt(day.charAt(1))) + 'px;" alt="' + day[0] + '" title="' + day[0] + '" />';
			countdown += '<img src="/images/blank.gif" class="countdown_number" ' + countdown_style + 'background-position: 0px ' + Math.floor(number_size * parseInt(day.charAt(1))) + 'px;" alt="' + day.charAt(1) + '" title="' + day.charAt(1) + '" />';
		}

		countdown += '<img src="' + image_link + 'seperator.gif" class="countdown_seperator" alt="" title="" />';

		if (hour.length < 2) {
			countdown += '<img src="/images/blank.gif" class="countdown_number" alt="0" title="0" />';
			countdown += '<img src="/images/blank.gif" class="countdown_number" ' + countdown_style + 'background-position: 0px ' + Math.floor(number_size * parseInt(hour.charAt(1))) + 'px;" alt="' + hour[0] + '" title="' + hour[0] + '" />';
		} else {
			countdown += '<img src="/images/blank.gif" class="countdown_number" ' + countdown_style + 'background-position: 0px ' + Math.floor(number_size * parseInt(hour.charAt(1))) + 'px;" alt="' + hour[0] + '" title="' + hour[0] + '" />';
			countdown += '<img src="/images/blank.gif" class="countdown_number" ' + countdown_style + 'background-position: 0px ' + Math.floor(number_size * parseInt(hour.charAt(1))) + 'px;" alt="' + hour.charAt(1) + '" title="' + hour.charAt(1) + '" />';
		}

		countdown += '<img src="' + image_link + 'seperator.gif" class="countdown_seperator" alt="" title="" />';

		if (minute.length < 2) {
			countdown += '<img src="/images/blank.gif" class="countdown_number" alt="0" title="0" />';
			countdown += '<img src="/images/blank.gif" class="countdown_number" ' + countdown_style + 'background-position: 0px ' + Math.floor(number_size * parseInt(minute[0])) + 'px;" alt="' + minute[0] + '" title="' + minute[0] + '" />';
		} else {
			countdown += '<img src="/images/blank.gif" class="countdown_number" ' + countdown_style + 'background-position: 0px ' + Math.floor(number_size * parseInt(minute[0])) + 'px;" alt="' + minute[0] + '" title="' + minute[0] + '" />';
			countdown += '<img src="/images/blank.gif" class="countdown_number" ' + countdown_style + 'background-position: 0px ' + Math.floor(number_size * parseInt(minute[0])) + 'px;" alt="' + minute.charAt(1) + '" title="' + minute.charAt(1) + '" />';
		}

		countdown += '<img src="' + image_link + 'seperator.gif" class="countdown_seperator" alt="" title="" />';

		if (second.length < 2) {
			countdown += '<img src="/images/blank.gif" class="countdown_number" alt="0" title="0" />';
			countdown += '<img src="/images/blank.gif" class="countdown_number" ' + countdown_style + 'background-position: 0px ' + Math.floor(number_size * parseInt(second[0])) + 'px;" alt="' + second[0] + '" title="' + second[0] + '" />';
		} else {
			countdown += '<img src="/images/blank.gif" class="countdown_number" ' + countdown_style + 'background-position: 0px ' + Math.floor(number_size * parseInt(second[0])) + 'px;" alt="' + second[0] + '" title="' + second[0] + '" />';
			countdown += '<img src="/images/blank.gif" class="countdown_number" ' + countdown_style + 'background-position: 0px ' + Math.floor(number_size * parseInt(second[0])) + 'px;" alt="' + second.charAt(1) + '" title="' + second.charAt(1) + '" />';
		}
		
		*/
		
		document.getElementById('countdown_numbers').innerHTML = countdown;
	
	}
	
	setTimeout("countdown(theyear,themonth,theday)",1000)
	
}

