<commit_before>/**
 * Reformates returning json object into a format we define.
 *
 * @param JSON json 
 * @return JSON
 */
flickrParser = function(json){
	var imageList = []
	$(json.items).each(function(i, image){
		imageList.push({
			'title':image.title,
			'artist':image.author,
			'url':image.link,
			'image':image.media.m});
	})
	return imageList;
}


/**
 * Distributes the number of pixles in a gallery between the images of that gallery.
 * For use as the width of the rollover div that activates each image.
 *
 * @param int imgNum    Number of images in current gallery
 * @param int pxWidth   Width of Current gallery
 * @return funtion(x)   Function takes an index 'x' and returns number of pixles assigned to that index
 */
distributeimages = function(imgNum, pxWidth){
	builder = function(remainder, acumFun){
		if(remainder == 0)
			return acumFun;
		
		// Get the interval of images to skip before adding another pixle.
		// Ceil prevents adding too many.
		var a = Math.ceil(imgNum / remainder)
		
		// Create a new anonymouse function that returns the sum pixles asigned at other intervals with
		// 1 added if the index 'x' is within the current interval as well.
		var newFun = function(x){ return acumFun(x) + (x % a == 0) }
		
		// Update remainder by removing pixles taken care of by this iteration
		// while recusivly adding more layers untill remainder is 0.
		return builder(remainder - Math.floor(imgNum / a), newFun);
	}
	
	// Initalize base function as the number of pixles every image should recieve.
	base = function(x){ return Math.floor(pxWidth / imgNum) };
	return builder(pxWidth % imgNum, base)
}


/**
 * Updates image and title/author info
 *
 * @param DOM domObj    jQuery DOM object of the gallery
 * @param DOM infoBar   jQuery DOM object of the gallerys info bar div
 * @param JSON img      JSON containing information about the image to update with
 * @return void
 */
changeImage = function(domObj, infoBar, img){
	domObj.css('background-image', "URL('"+img.image.replace('_m', '')+"')");
	infoBar.html("<h3>"+img.title+"</h3><h4>"+img.artist+"</h4>");
}


/**
 * Adds the required HTML to the user provided div.
 * This incudes setting up rollover zones and event listeners.
 *
 * @param DOM domObj       jQuery DOM object of the gallery
 * @param JSON[] imgList   Array of image information
 * @return void
 */
renderGallery = function(domObj, imgList){
	// Get function to map image indexes to pixle values
	var distribution = distributeimages(imgList.length, domObj.width());
	
	var hoverContainer = $("<div class='rContainer'></div>");
	var infoContainer = $("<div class='info'></div>");
	infoContainer.css('top', -(domObj.height()-15))
	
	domObj.append(hoverContainer);
	domObj.append(infoContainer);
	
	$(imgList).each(function(i, img){
		// add rollover element for image with a width set to that calculated in distributeimages()
		var hoverTemp = "<div class='rollover' style='width:"+distribution(i+1)+"px;'><\/div>"
		var elm = $(hoverTemp);
		hoverContainer.append(elm);
		
		// Set up event listeners
		elm.click(function(){ window.open(img.url, '_blank'); });
		elm.mouseover(function(){ changeImage(domObj, infoContainer, img); });
		
		changeImage(domObj, infoContainer, img); // This is lazy but it ends up loading the last image
	});
}


/**
 * Recieves remote image information and initalizes each gallery after the page loads
 */
$(document).ready(function(){<commit_msg>Display first image in set instead of the last.<commit_after>/**
 * Reformates returning json object into a format we define.
 *
 * @param JSON json 
 * @return JSON
 */
flickrParser = function(json){
	var imageList = []
	$(json.items).each(function(i, image){
		imageList.push({
			'title':image.title,
			'artist':image.author,
			'url':image.link,
			'image':image.media.m});
	})
	return imageList;
}


/**
 * Distributes the number of pixles in a gallery between the images of that gallery.
 * For use as the width of the rollover div that activates each image.
 *
 * @param int imgNum    Number of images in current gallery
 * @param int pxWidth   Width of Current gallery
 * @return funtion(x)   Function takes an index 'x' and returns number of pixles assigned to that index
 */
distributeimages = function(imgNum, pxWidth){
	builder = function(remainder, acumFun){
		if(remainder == 0)
			return acumFun;
		
		// Get the interval of images to skip before adding another pixle.
		// Ceil prevents adding too many.
		var a = Math.ceil(imgNum / remainder)
		
		// Create a new anonymouse function that returns the sum pixles asigned at other intervals with
		// 1 added if the index 'x' is within the current interval as well.
		var newFun = function(x){ return acumFun(x) + (x % a == 0) }
		
		// Update remainder by removing pixles taken care of by this iteration
		// while recusivly adding more layers untill remainder is 0.
		return builder(remainder - Math.floor(imgNum / a), newFun);
	}
	
	// Initalize base function as the number of pixles every image should recieve.
	base = function(x){ return Math.floor(pxWidth / imgNum) };
	return builder(pxWidth % imgNum, base)
}


/**
 * Updates image and title/author info
 *
 * @param DOM domObj    jQuery DOM object of the gallery
 * @param DOM infoBar   jQuery DOM object of the gallerys info bar div
 * @param JSON img      JSON containing information about the image to update with
 * @return void
 */
changeImage = function(domObj, infoBar, img){
	domObj.css('background-image', "URL('"+img.image.replace('_m', '')+"')");
	infoBar.html("<h3>"+img.title+"</h3><h4>"+img.artist+"</h4>");
}


/**
 * Adds the required HTML to the user provided div.
 * This incudes setting up rollover zones and event listeners.
 *
 * @param DOM domObj       jQuery DOM object of the gallery
 * @param JSON[] imgList   Array of image information
 * @return void
 */
renderGallery = function(domObj, imgList){
	// Get function to map image indexes to pixle values
	var distribution = distributeimages(imgList.length, domObj.width());
	
	var hoverContainer = $("<div class='rContainer'></div>");
	var infoContainer = $("<div class='info'></div>");
	infoContainer.css('top', -(domObj.height()-15))
	
	domObj.append(hoverContainer);
	domObj.append(infoContainer);
	
	// Display first image
	changeImage(domObj, infoContainer, imgList[0]);
	
	$(imgList).each(function(i, img){
		// add rollover element for image with a width set to that calculated in distributeimages()
		var hoverTemp = "<div class='rollover' style='width:"+distribution(i+1)+"px;'><\/div>"
		var elm = $(hoverTemp);
		hoverContainer.append(elm);
		
		// Set up event listeners
		elm.click(function(){ window.open(img.url, '_blank'); });
		elm.mouseover(function(){ changeImage(domObj, infoContainer, img); });
	});
}


/**
 * Recieves remote image information and initalizes each gallery after the page loads
 */
$(document).ready(function(){
{'fraction_non_alphanumeric': 0.12356613910265718, 'fraction_numerical': 0.0033396253811528967, 'mean_word_length': 3.9518332135154566, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2788913', 'n_tokens_mistral': 2174, 'n_tokens_neox': 2021, 'n_words': 745}