(function($) {
	$.fn.rollover = function(options) {

		var opts = $.extend({}, $.fn.rollover.defaults, options);

		return this.each(function() {
			//  do something with $(this).
			//  this is where all of the core plug in code belongs

			//Preload the rollovers (I think this works :) )	
			var preloaded;
			preloaded = $('<img src='+$(this).attr('rollsrc')+'>');

			
			var target;

			//If rollover configured by element attributes, then set it up
			if (!opts.targets) {

				$(this).hover(  
					function () {

						if (typeof($(this).attr('rolltarget')) == 'undefined' ) {
							target = $(this);
						} else {
							target = $($(this).attr('rolltarget'));
						}
	
						$(this).attr('originalSrc', $(this).attr('src'));
						target.attr('src', $(this).attr('rollsrc'));
					}, 
					function () {
						target.attr('src', $(this).attr('originalSrc'));
					}

				);

			//If rollover configured by passed in options, then set those up 
			} else {

				$(this).hover(  

					function () {
						for (var propertyName in opts.targets) {
							if (opts.targets[propertyName].src) {
								$(propertyName).attr('originalSrc', $(propertyName).attr('src'));
								$(propertyName).attr('src', opts.targets[propertyName].src);
							} else {
								if (typeof(	opts.targets[propertyName].inFunction) == 'function') {
									opts.targets[propertyName].inFunction($(propertyName));
								}
							}
						}
					}, 
					function () {
						for (var propertyName in opts.targets) {
							if (opts.targets[propertyName].src) {
								$(propertyName).attr('src', $(propertyName).attr('originalSrc'));
							} else {
								if (typeof(	opts.targets[propertyName].outFunction) == 'function') {
									opts.targets[propertyName].outFunction($(propertyName));
								}
							}
						}
					}

				);


			}

		});
	};
	  
	// default options - these are used of none others are specified
	$.fn.rollover.defaults = {
	};


	//  invoke the function we just created passing it
	//  the jQuery object
})(jQuery);
