// Receive anchor link and determine LightBox parameters
function lightBabel(a){
	var lightBabel = [
		{
			id: 'portfolioImage',
			// $1=prefix, $2=collection, $3=series, $4=filename (without ext), $5='.'+extension, $6=$extension
			srcRegex: /^(.*)\/portfolio\/images\/([^\/]+)\/([^\/]+)\/([^\/]+)(\.(jpe?g|gif|png))$/,
			// $1=prefix, $2=collection, $3=series, $4=filename (without ext)
			hrefRegex: /^(.*)\/portfolio\/([^\/]+)\/([^\/]+)\/([^\/]+)\/large\/?$/,
			
			getParameters: function(a, img){	
				if (img){
					var srcParts = img.src.split('/');
					var filename = srcParts.pop();
					var largeSrc = srcParts.join('/') + '/large/' + filename;
					var title = img.alt;
					
					return {src:largeSrc, title:title};
				}
			}
		}
	];
	
	var imgs = a.getElementsByTagName('img');
	var img = (imgs.length > 0) ? imgs[0] : null;
	
	var lightType = lightBabel.find(function(lightType){
		var aMatch = a.href.match(lightType.hrefRegex);
		var imgMatch = (img) ? img.src.match(lightType.srcRegex) : true;
		return (aMatch && imgMatch);
	});
	
	return (lightType) ? lightType.getParameters(a, img) : null;
}






// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

// OBJECT EXTENSIONS
Object.extend(Array.prototype, { 
	// Search objects within an array for a specified property-value or method-result
	// optional arg: asArray [boolean] - to return an array of objects. Default: false
	getBy: function(property, value){
		if (arguments.length > 2)
			{
				if (arguments[2])
					{
						var asArray = true;
						var returnArray = [];
					}
			}
			
		if (typeof asArray == 'undefined')
			{ var asArray = false; }
		
		
		for (var i=0; i<this.length; i++)
			{
				if (typeof this[i] != 'object')
					{ continue; }
				
				switch (typeof this[i][property]){
					case 'undefined':
					break;
					
					case 'function':
					if (this[i][property]() == value)
						{
							if (asArray) { returnArray.push(this[i]); }
							else { return this[i]; }
						}
					break;
						
					default:
					if (this[i][property] == value)
						{
							if (asArray) { returnArray.push(this[i]); }
							else { return this[i]; }
						}
					break;
				}
			}
		
		if (asArray)
			{ return (returnArray.length > 0) ? returnArray : null; }
		else
			{ return null; }
	},
	
	getById: function(id){
		return this.getBy('id', id);
	}
});