//get the start and end dates
var endDate = new Date("July 10, 2010");
var startDate = new Date();

//get the unix timestamp of the start and end dates
var startTime = startDate.getTime();
var endTime = endDate.getTime();

//get the difference in the dates
var timeDiff = endTime - startTime;

//call the function to calculate the date
var interval = setInterval(function(){ getDiff('countdown') },1000);

function getDiff(div_id){
	//make sure the div exists on the page
	if(!document.getElementById(div_id)){
		clearInterval(interval);
		return false;
	}
	
	//the time is already past
	if(timeDiff < 0){
		//set the text null
		document.getElementById(div_id).innerHTML = '';
		
		//clear the interval
		clearInterval(interval);
	}
	
	//variables for time
	var one_sec = 1000;
	var one_min = one_sec * 60;
	var one_hour = one_min * 60;
	var one_day = one_hour * 24;
	var one_month = one_day * 30;
	
	//temporary time
	var temp_time = timeDiff;
	
	//get the months
	var months = Math.floor(temp_time / one_month);
	
	//subtract the months
	temp_time -= months * one_month;
	
	//get the days
	var days = Math.floor(temp_time / one_day);
	
	//subtract the days
	temp_time -= days * one_day;
	
	//get the hours
	var hours = Math.floor(temp_time / one_hour);
	
	//subtract the hours
	temp_time -= hours * one_hour;
	
	//get the mins
	var mins = Math.floor(temp_time / one_min);
	
	//subtract the mins
	temp_time -= mins * one_min;
	
	//get the seconds
	var secs = Math.floor(temp_time / one_sec);
	
	//subtract the seconds
	temp_time -= secs * one_sec;
	
	//setup text display	
	var content = '';
	
	//get the content text
	if(months > 0){
		content += months;
		
		if(months > 1)
			content += ' Months ';
		else 
			content += ' Month ';
	}
	
	if(days > 0){
		content += days;
		
		if(days > 1)
			content += ' Days ';
		else
			content += ' Day ';
	}
	
	if(hours > 0){
		content += hours;
		
		if(hours > 1)
			content += ' Hours ';
		else 
			content += ' Hour ';
	}
	
	if(mins > 0){
		content += mins;
		
		if(mins > 1)
			content += ' Mins ';
		else
			content += ' Min ';
	}
	
	//always show the seconds
	if(secs > -1){
		content += secs;
		
		if(secs > 1)
			content += ' Secs ';
		else
			content += ' Sec';
	}
	
	//console.log(content);
	document.getElementById(div_id).innerHTML = content;

	//subtract a second from the time diff
	timeDiff -= 1000;
}