var biblio = {};
var citeKeys = [];
var bibData = "";
var bibJSON = "";
		
// Available firld names (all as lowercase):
//BibliographyType,ISBN,Identifier,Author,Title,Journal,Volume,Number,Month,Pages,Year,Address,Note,URL,Booktitle,Chapter,Edition,Series,Editor,Publisher,ReportType,Howpublished,Institution,Organizations,School,Annote,Custom1,Custom2,Custom3,Custom4,Custom5

function footnote(cite, fieldList)
     {
		 
		 fieldList = fieldList.replace(/ /g,"").split(",");
		var show = "<p class=\"biblio\">";
		 for (field in fieldList)
		    {
				
				var text = biblio[cite][fieldList[field]] + "";
				
					 if (text != 'undefined')
					   {
						 switch(fieldList[field])
						      {
									
								case 'url':
								show +=  '<a href="' + text + '">'+text+'</a>. &nbsp;';
								break;	
																	
								case 'title':
								show +=  '<i>' + text + "</i>. &nbsp;";
								break;	
																		
								default:	
									show +=   text + ". &nbsp;";
								break;	 
									}
						 
						  }
				}	 
				
				return(show + "</p>");
		
		 }
		 
function loadBiblio(biblioSrc, callBack)		
     {
  
		 jQuery.get(biblioSrc, 
		 
		 function(data){
		 bibData = data;
		 bibJSON = data.replace(/\"/g,"\'\'");
		 
		/* buildKeys = bibJSON.match(/@(.*){(.*),/g);
		 
		   for (key in buildKeys)
			    {
			 var hold = buildKeys[key].split("{")[1];
					 hold = hold.substr(0, hold.length -1); // get rid of trailing comma
					 citeKeys.push(hold);
					 }		 
		 */
				 	 
		 bibJSON = bibJSON.replace(/@(.*){(.*),/g,"\"$2\" : { \"doctype\" : \"$1\",");
		 bibJSON = bibJSON.replace(/^%.*[\d\n\r]/mg, ""); // get rid of JabRef comments
		 bibJSON = bibJSON.replace(/},/g,"\",");
		 bibJSON = bibJSON.replace(/\s+([a-z]*) = {/g,  " \"$1\" : \"");
		 bibJSON = bibJSON.replace(/^}/g,"},");
		 bibJSON = bibJSON.replace(/^},,/g,"},");
     //bibJSON = bibJSON.replace(/: {/g,": \"");					 
		 
		 bibJSON = bibJSON.replace(/^}$/gm,"@@##,");
		 bibJSON = bibJSON.replace(/}/g,"\"");
		 bibJSON = bibJSON.replace(/@@##,/gm,"},");
		 
		 bibJSON = bibJSON.replace(/@comment.*.[\d\n\r]$/mg, ""); // get rid of JabRef comments
		 
				bibJSON = bibJSON.replace(/\n/g,""); // remove all new lines, they break JSON
				bibJSON = bibJSON.replace(/\r/g,""); // remove all line-returns, they break JSON
				bibJSON = "biblio = {" + bibJSON + "};";
				bibJSON = bibJSON.replace("\"},};", "\"} };");
 
		  eval(bibJSON);
		 
		  for (var citeRef in biblio) {
        citeKeys.push(citeRef); // build array of citekeys only
             }		
				 
					if (callBack != "")
					  {
						 eval(callBack);
						 }	 	 
		 })
		 
		  } // end function loadBiblio()
     
		 
