function function_exists(a){if(typeof a=='string'){return(typeof window[a]=='function')}else{return(a instanceof Function)}}
function is_object(a){if(a instanceof Array){return false}else{return(a!==null)&&(typeof(a)=='object')}}
function empty(a){var b;if(a===''||a===0||a==='0'||a===null||a===false||a===undefined){return true}if(typeof a=='object'){for(b in a){if(typeof a[b]!=='function'){return false}}return true}return false}

/**
 * 倒计时
 * $Id: jquery.countdown.js
 *
 * @param string id 对象id
 * @param int total 总时间,单位毫秒
 * @param function callback 回调函数
 * @return void
 */
countdown = function(id, total, callback)
{
	if( total <= 0 ) {
		function_exists(callback) && callback.call(callback);
		return;
	}
	var start_hours = parseInt( total / (60 * 60 * 1000), 10 );
	var start_minutes = parseInt( (total - start_hours * 60 * 60 * 1000) / (60 * 1000), 10 );
	var start_sec = parseInt( ((total - start_hours * 60 * 60 * 1000) - start_minutes * 60 * 1000) / 1000 );
	if( is_object($(id)) ) {
		var html = '';
		if( start_hours > 0 )
			html += start_hours + '小时';
		if( start_minutes >= 0 )
			html += (start_minutes < 10 ? '0' + start_minutes : start_minutes) + '分';
		if( start_sec >= 0 )
			html += (start_sec < 10 ? '0' + start_sec : start_sec) + '秒';
		if( empty(html) )
			html = '----';
		$(id).html(html);
	}
	total = total - 1000;
	var self = this;
	setTimeout(function(){
		self.countdown(id, total, callback);
	}, 1000);
}
