﻿
/////////////////////////////jbecool.jMyHover///////////////////////////////
/*
author:jerry
history:
v1.0 jerry 鼠标悬停时自动切换背景、自动发光或变暗

使用方法：
例子：<div class="becool_jMyHover" type="image" bg="bg1,bg2"/>
其中bg1,bg2为class样式名称，bg1为原始的样式，bg2为鼠标悬停后的样式

例子：<div class="becool_jMyHover" type="lighter" light="-0.5"><img src="bg2.png"/></div>
其中light设定发光样式，为正数时发白光，为负数时发黑光，范围为“0-1”
*/
(function ($) {
    $.fn.jMyHover = function () {
        this.each(function () {
			if($(this).attr("type")=="image")
			{
				var bg1=$(this).attr("bg").split(",")[0];
				var bg2=$(this).attr("bg").split(",")[1];
				$(this).hover(
					function () {
						$(this).removeClass(bg1);
						$(this).addClass(bg2);
					},
					function () {
						$(this).removeClass(bg2);
						$(this).addClass(bg1);
					});
			}
			
			if($(this).attr("type")=="lighter")
			{
				var light = parseFloat($(this).attr("light")) || 0.5;
				var a = (1.0 - Math.abs(light));

				if (light > 0)
					$(this).css("background-color", "white");
				else
					$(this).css("background-color", "black");

				$(this).find("img").hover(
					function () {
						$(this).fadeTo('normal', a);
					}, 
					function () {
						$(this).fadeTo('normal', 1.0);
					});
			}
        });
    }
})(jQuery);

$(function () {
    $(".becool_jMyHover").jMyHover();
});


