function emailLink(a, b, c) {
	var addr = a+'@'+b+'.'+c;
	return '<a href="mailto:'+addr+'">'+((arguments[3]) ? arguments[3] : addr)+'</a>';
}

$(document).ready(function() {
	loadIndex();
	
	$('#button a').click(function() {
		if($(this).hasClass('close')) {
			pjbidClose();
			return false;
		}
		else {
			pjbidBack();
			return false;
		}
	});
	
	$('#projectbidlaunch').click(function() {
		$('#projectbid, #overlay').show();
	});
});

loadIndex = function() {
	$('#pjbidcontent').load('/projectbid.php', {}, function() {
		$('#pjbidcontent').removeClass('loading');	
		$('#instructions').show();
		$('#otheractive').hide();
	
		$('#projectbid a[href^=projectbid.php], table.data a').click(function() {
			loadProject($(this).attr('href'));
			return false;
		});
		$("table.data").tablesorter().bind('sortEnd', function() {
			$("table.data tbody tr:odd").removeClass('odd');
			$("table.data tbody tr:even").addClass('odd');		
		});			
	});	
}

loadProject = function(anchor) {
	var id = anchor.match(/\?id=(\d+)/i)[1];
	$('#pjbidcontent').load('/projectbid.php', { id : id });
	$('#instructions').hide();
	showOtherActive(id);
	showBackBtn();
	return false;
}

pjbidClose = function() {
	$('#projectbid').add('#overlay').hide();
	return false;
}

showCloseBtn = function() {
	$('#button a').removeClass('back').addClass('close');
}

pjbidBack = function() {
	loadIndex();
	showCloseBtn();
	return false;	
}

showBackBtn = function() {
	$('#button a').removeClass('close').addClass('back');
}

showOtherActive = function(id) {
	$('#otheractive').show();
	$('#otheractive li').each(function() {
		$(this).show();
		if($(this).attr('id') == 'project_'+id)
			$(this).hide();
	});
}