$(document).ready(function(){
	
	//the file_path variable needs to be set for whatever folder the various refworks_ex files have been put in. Make sure to include trailing /
	var file_path = 'http://library.temple.edu/scripts/';
	var file_path_encoded = escape(file_path);
	
	// if a#recordnum exists then it is a single item page.
	if ( $("#recordnum").attr("href") ) {
		//grab bib record number from the page
		var bibnumber = $("#recordnum").attr("href");
		var start = bibnumber.lastIndexOf('b');
		bibnumber = bibnumber.substr(start,8);
		
		//adds export to refworks image with link to refworks as well as info image with link to libguides
		$('<div id="refworks-export" style="float:left;"><a title="Export to Refworks" target="_blank" href="http://www.refworks.com/express/ExpressImport.asp?vendor=Marc%20Format&url=' + file_path_encoded + 'refworks_ex.php%3Fid%3D' + bibnumber + '"><img style="margin-right: 10px;" src="' + file_path + 'refworks_ex.jpg" alt="Export to Refworks" /></a><a target="_blank" href="http://guides.temple.edu/content.php?pid=44395&sid=328206"><img style="margin-right:14px;" src="http://diamond.temple.edu/screens/smsq.gif"/></a></div>').prependTo("#smsfeatures");

	
	//otherwise it is multi-item page
	} else {
	
		// grab href of a's descended from td class="browseEntryData", extract the bib number and put them into a comma separated string
		var bibrecords = $(".browseEntryData > a").map(function(){
			var start = this.href.lastIndexOf('b');
			this.number = this.href.substr(start,8);
			return this.number;
		}).get().join(",");

		// Inserts refworks button with appropriate url link
		$('<tr><td id="refworks-export" align="left"><a title="Export to Refworks" target="_blank" href="http://www.refworks.com/express/ExpressImport.asp?vendor=Marc%20Format&url=' + file_path_encoded + 'refworks_ex.php%3Fid%3D' + bibrecords + '"><img style="margin-right: 10px;" src="' + file_path + 'refworks_ex.jpg" alt="Export to Refworks" /></a></td></tr>').insertAfter('tr:contains("Local Disk"):last');
	};
});