/*
 * jQuery WG Image Hover plug-in 1.0
 * Copyright (c) 2008 Roberto Lee (WebGenerator.nl)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 * Date: 2011-05-05
 * Rev: 1
 *
 * FOR FLIPPING IMAGES ON MOUSEOVER. ACTIVE IMAGES USES A POSTFIX IN THE FILENAME.
 *
 * REQUIREMENTS:
 *
 *
 *
 *
 *
 *
 *
 */
 (function($){
     $.fn.extend({
         WG_Image_Hover: function(options) {
	        var defaults = {
				activepostfix: "hover",
				cb: function(){}
	        };
	        var options = $.extend(defaults, options);

            return $(this).each(function(idx) {
				if($(this).is('*'))
				{
					var htmlelem = $(this);
			    	var fullpath = (htmlelem.attr('src'));
			    	var ext = fullpath.split('.').pop();
			    	var filename = fullpath.substring(0, fullpath.length - ext.length - 1);
			    	var filename_normal = fullpath.replace("_"+options.activepostfix+".",".");
			    	var filename_hover = filename + '_'+options.activepostfix+'.' + ext;

					//PRELOAD
					//var imagenormal =  $('<img />').attr('src', filename_normal);
					//var imagehover =  $('<img />').attr('src', filename_hover);


				    htmlelem.mouseover(function(){
				      	htmlelem.attr('src', filename_hover);
				      	//htmlelem.replaceWith(imagehover);
				    }).mouseout(function(){
				    	htmlelem.attr('src', filename_normal);
				    	//imagehover.replaceWith(imagenormal);
				    });
					options.cb.call();
				}
            });
		}
    });
})(jQuery);

/*
EXAMPLE USAGE
$("a[title^='--'] img, a[alt^='--'] img, a.flip img, img.hoverable, img[alt^='--']").WG_Image_Hover({'activepostfix':'active'});



*/
