//EDL added file 7/18/11

// starting the scripts on page load: EDL added captions on 7/18/11. copied from ips.common.js written by IanW.
$(document).ready(function() {
		
	// Automatically add captions to images marked with a captions class
	// See jQuery capty plugin below
	$('.img-left-caption').capty({ animation: 'fixed' });
	$('.img-right-caption').capty({ animation: 'fixed' });
	$('.img-center-caption').capty({ animation: 'fixed' });
	
});

/**
 * jQuery Capty - A Caption Plugin - http://wbotelhos.com/capty
 * ---------------------------------------------------------------------------------
 *
 * jQuery Capty is a plugin that creates captions over the images.
 *
 * Licensed under The MIT License
 *
 * @version         0.2.1
 * @since           12.18.2010
 * @author          Washington Botelho dos Santos
 * @documentation   wbotelhos.com/capty
 * @twitter         twitter.com/wbotelhos
 * @license         opensource.org/licenses/mit-license.php MIT
 * @package         jQuery Plugins
 *
 * Usage with default values:
 * ---------------------------------------------------------------------------------
 * $('#capty').capty();
 *
 * <img id="capty" src="image.jpg" alt="Super Mario Bros.&reg;" width="150" height="150"/>
 *
 * This plugin has been modified for the purposes of this website.
 *
 */

;(function($) {

	$.fn.capty = function(settings) {
		var options = $.extend({}, $.fn.capty.defaults, settings);

		if (this.length == 0) {
			debug('Selector invalid or missing!');
			return;
		} else if (this.length > 1) {
			return this.each(function() {
				$.fn.capty.apply($(this), [settings]);
			});
		}

		var $this		= $(this),
			name		= $this.attr('name'),
			$caption	= $('<div class="' + options.cCaption + '"/>'),
			$elem		= $this;

		if ($this.attr('alt').length == 0) { return; }

		if ($this.parent().is('a')) {
			$elem = $this.parent();
		}

		// class should be one of: 
		// img-left-caption, img-right-caption, img-center-caption
		var img_align;
		var pad_left = "8px";
		var pad_right = "8px";
		if ($this.hasClass('img-right-caption')) { 
			img_align = 'right'; 
			pad_right = "0";
		}
		else if ($this.hasClass('img-center-caption')) { 
			img_align = 'center'; 
		}
		else if ($this.hasClass('img-left-caption')) { 
			img_align = 'left'; 
			pad_left = '0'; 
		}

		var $image		= $elem.wrap('<div class="' + options.cImage + '"/>').parent(),
			$wrapper	= $image.wrap('<div style="float: '+img_align+'; padding-top: 0; padding-bottom: 0; padding-left: '+pad_left+'; padding-right: '+pad_right+'; border: none"><div class="' + options.cWrapper + '"/>').parent();

		// Take the CSS width of the image and add to it to give the
		// div a little space.
		var div_width = parseInt($this.css('width'));
		div_width = div_width + 24;
		div_width = div_width + "px";

		$wrapper.css({
			float:		'left',
			width:		div_width
		});


		$caption.css({
			padding:	'6px'
		})

		.click(function(evt) {
			evt.stopPropagation();
		})
		.appendTo($wrapper);

		if (name) {
			var $content = $(name);

			if ($content.length) {
				$content.appendTo($caption);
			} else {
				$caption.html('<span style="color: #F00;">Content invalid or missing!</span>');
			}
		} else {
			$caption.html($this.attr('alt'));
		}

		if (options.prefix) {
			$caption.prepend(options.prefix);
		}

		if (options.sufix) {
			$caption.append(options.sufix);
		}

		if (options.animation == 'slide') {
			$wrapper.hover(
				function() {
					$caption.animate({ top: (-1 * options.height) }, { duration: options.speed, queue: false });
				},
	    		function() {
					$caption.animate({ top: 0 }, { duration: options.speed, queue: false });
				}
	    	);
		} else if (options.animation == 'fade') {
			$caption.css({
				opacity:	0,
				top:		(-1 * options.height) + 'px'
			});

			$wrapper.hover(
				function() {
					$caption.stop().animate({ opacity: options.opacity }, options.speed);
				},
	    		function() {
					$caption.stop().animate({ opacity: 0 }, options.speed);
				}
	    	);
		} else if (options.animation == 'fixed') {
			$caption.css('top', (-1 * options.height) + 'px');
		} else {
			debug($this.attr('id') + ': invalid animation!');
		}

		return $this;
	};

	function debug(message) {
		if (window.console && window.console.log) {
			window.console.log(message);
		}
	};

	$.fn.capty.defaults = {
		animation:	'slide',
		cCaption:	'ips-caption',
		cImage:		'',
		cWrapper:	'capty-wrapper',
		height:		30,
		opacity:	.7,
		prefix:		'',
		speed:		200,
		sufix:		''
	};

})(jQuery);


