
(function($){

	$.fn.createMenu = function(opts)
	{
		return this.each(function(){
			if ($(this).find('ul').length) {
				$(this).addClass('dropdown');
				$(this).bind({
					mouseenter: function() {
						var submenu = $(this).find('ul');
						submenu.css({top: 0, left: 0});
						submenu.show();
						var pos = $(this).offset();
						pos.top += $(this).height();
						if (opts.container) {
							var maxLeft = opts.container.offset().left + opts.container.width() - 5;
							var currentLeft = pos.left + submenu.width();
							if (currentLeft > maxLeft)
								pos.left -= currentLeft - maxLeft;
						}
						submenu.css(pos);
						
					},
					mouseleave: function() {
						$(this).find('ul').hide();
					}
				})
			}
		});
	}
})(jQuery);

// imageText

(function($){

	var getURL = function(text)
	{
		text = encodeURIComponent(text);
		text = text.replace('!', '%21').replace('(', '%28').replace(')', '%29').replace('*', '%2A').replace("'", '%27');
		return encodeURIComponent(text);
	}

	$.fn.imageText = function()
	{
		return this.each(function(){
			match = this.className.match(/(?: |^)(\w+_)(?: |$)/);
			if (match) {
				$(this).replaceWith('<img src="image_txt/'+match[1]+getURL($(this).text())+'.gif" />');
			}
		});
	}

})(jQuery);

