		
function GAF_getTimeLeft(endTime) {
	var n = new Date();	
	var timestamp = n.getTime()/1000;
	var secs = endTime - timestamp;
	if (secs>0) {
		var day = Math.floor(secs/60/60/24);
		secs = secs - day * 60*60*24;
		var hour = Math.floor(secs/60/60);
		secs = secs - hour  * 60*60;
		var min = Math.floor(secs/60);
		s = null;
		s = (day>0?(s==null?'':s+' ')+day+'d':s);
		s = (hour>0?(s==null?'':s+' ')+hour+'h':s);
		s = (min>0?(s==null?'':s+' ')+min+'m':s);
		return s;		
	} else {
		return 'a few minutes';
	}
}
			
		
function toTitleCase(str)
{
    return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
}

// Test for upper case letters (only good up to char 127)
function isUpper(aChar)
{
        myCharCode = aChar.charCodeAt(0);
        if((myCharCode > 64) && (myCharCode <  91))
        {
         return true;
        }
        return false;
}


function GAF_update_projects_horizontal_callback(json) {
	var str = '';
	if (json.projects.count>0) {
		var cellWidth = Math.round(100/json.projects.count);
		str += '<table cellpadding="0" cellspacing="3px" border="0"><tr valign="top">';
		for (var i=0;i<json.projects.count;i++) {
			var p = json.projects.items[i];
			budget = ((p.budget.min!='' && p.budget.max!='')?'$'+p.budget.min+' - $'+p.budget.max:'')+
				((p.budget.min!='' && p.budget.max=='')?'from $'+p.budget.min:'')+
				((p.budget.min=='' && p.budget.max!='')?'up to $'+p.budget.max:'');
			jobs = null;
			for (var j=0;j<p.jobs.length;j++) {
				jobs = ((jobs==null)?'':jobs+', ') + p.jobs[j];
			}

			if (isUpper(p.name.charAt(0)) && isUpper(p.name.charAt(1))) {
                                p.name = toTitleCase(p.name);
                        }

			str += '<td width="'+cellWidth+'%" style="cursor:hand;cursor:pointer; padding: 10px 5px 0 5px" onclick="window.open(\''+p.url+'\',\'_blank\')"><span style="font-size:12px; color: '+GAF_title_color+'"><u><b>'+p.name+'</b></u>'+
				(p.options.featured?' <sup><b style="color:darkblue">Featured</b></sup>':'')+
				(p.options.fulltime?' <sup><b style="color:blue">Full Time</b></sup>':'')+
				(p.options.trial?' <sup><b style="color:gray">Trial</b></sup>':'')+
				(p.options.nonpublic?' <sup><b style="color:#694E5A">Nonpublic</b></sup>':'')+
				(p.options.urgent?' <sup><b style="color:red">Urgent</b></sup>':'')+
				'</span>';

			str += '<br><span style="font-size:12px;color:'+GAF_text_color+'">'+p.short_descr;
			if (jobs!=null)
				str += ' Jobs: '+jobs+',';
			if (budget!=false && budget!=null)
				str += ' Budget: '+budget;
			str +='</span>';

			str += '<div>';
			if (p.anchor!=null && p.anchor!=false)
				str += '<span style="font-size:12px;color:'+GAF_link_color+'">'+p.anchor+'</span>';
			else
				str += '<span style="font-size:12px;color:'+GAF_link_color+'">Bid on this project</span>';
			if (p.end_unixtime!=null && p.end_unixtime!=false) {
				str += '<span style="font-size:11px;color:'+GAF_text_color+'">';
				str += ' - ends in '+GAF_getTimeLeft(p.end_unixtime)+'';
				str += '</span>';
			}
			str += '</div>';

			str += '</td>';
		}
		str += '</tr></table>';
	}
	document.getElementById('GAF_projects_horizontal').innerHTML = str;
}


