﻿(function($){
	$.fn.TopMenu =function(){
		var _options = $.extend({
			mouseover : null,
			mousemove : null,
			mouseout  : null
		},arguments[0]);
		var _this = this.find("ul");
		this.find("ul").css({position:'absolute',opacity:0.5,zIndex:500,margin:0,padding:0,listStyle:'none'}).hide();
		this.each(function(i){
			if($(this).children("ul").children("li").is(':first')){  
				$(this).bind('mousemove',function(e){
					if($.isFunction(_options.mousemove))
						_options.mousemove.apply(this,[_this,e]);				  
				});
				$(this).hover(
					function(e){
						if($.isFunction(_options.mouseover))
							_options.mouseover.apply(this,[_this,e]);
						$(this).find("ul").stop(true,true).slideDown("fast");
					},
					function(e){
						if($.isFunction(_options.mouseout))
							_options.mouseout.apply(this,[_this,e]);
						$(this).find("ul").stop(true,true).slideUp("fast");
					}
				)
			}
		})
	}
	$.fn.TopMenuBG = function($options){
		var _options = $.extend({
			x : 100,
			y : 25,
			s : 0
		},$options);
		var _this = this;
		_this.each(function(i){
			$(this).css({backgroundPosition:'0px -'+(_options.y*i)+'px'})
				.hover(function(){
					$(this).css({backgroundPosition:'-'+_options.x+'px -'+(_options.y*i)+'px'});
				},function(){
					$(this).css({backgroundPosition:'0px -'+(_options.y*i)+'px'});
					_select(_options);
				});
		});
		_select(_options);
		function _select(_options){
			if(_options.s==-1) return;
			$(_this[_options.s]).css({backgroundPosition:'-'+_options.x+'px -'+(_options.y*_options.s)+'px'});
		}
	}
})(jQuery);