/*
	Lightbox JS: Fullsize Image Overlays 
	by Lokesh Dhakar - http://www.huddletogether.com

	For more information on this script, visit:
	http://huddletogether.com/projects/lightbox/

	Extremely modified (read: removed most of the unnecessary code)
	to simply swap images and captions
	
	**NOTE: This version does not use href to locate the image to swap.
	Image titles are passed in the rel.

*/

//
// pause(numberMillis)
// Pauses code execution for specified time. Uses busy code, not good.
// Code from http://www.faqts.com/knowledge_base/view.phtml/aid/1602
//


(function($)
{
	//target must be an <a> element
	
	$.fn.imgSwap = function(options)
	{
		var main_opts = $.extend({}, $.fn.imgSwap.defaults, options);
		
		return this.each(function(targetCounter)
		{
			var _$this = $(this);
			
			// build element specific options
			// if metadata plugin is present, extend main_opts, otherwise just use main_opts
      		var opts = $.meta ? $.extend({}, main_opts, $this.data()) : main_opts;
			
			//simplify the vars into regular globals
			var relValue = opts._relValue;
			var imgDir = opts._imgDir;
			
			_$this.mouseover(function()
			{
				var myRel = $(this).attr('rel');
				
				if(myRel.match(relValue)) //see if relValue is inside the rel, ex: 'swap'
				{
					//store rel value minus relValue
					//ex: if original rel='swapConsult+arcConsult01.gif', myRel='Consult+arcConsult01.gif'
					myRel = myRel.replace(relValue, "");
					
					//find location of '+' character
					var splitTerms = myRel.split("+");
					
					//store id of image to swap with
					var idToSwap = splitTerms[0];
					//$.log('idToSwap = ' + idToSwap);
					
					//get the image src to swap with
					var srcToSwap = splitTerms[1];
					//$.log('srcToSwap = ' + srcToSwap);
					
					var $idToSwap = $('#' + idToSwap);
					//$.log('$idToSwap = ' + $idToSwap);
					
					srcToSwap = imgDir + srcToSwap; //add entire file path
					
					$idToSwap.attr('src', srcToSwap);
				}
			});
		});
	};
	
	//
	//plugin defaults
	//
	$.fn.imgSwap.defaults =
	{
		_relValue: "swap", // these 2 variable determine popup's distance from the cursor
		_imgDir: "assets/images/"  // you might want to adjust to get the right result		
	};
	
})(jQuery);