$.fn.hm=function() {
	var $li=$(this).find("> ul > li"); var $sli=$li.find("> ul > li"); var tID; var flag="";
	return this.each(function() {
		$li.hover(
			function() {
				if ($(this).find("> ul").is("ul")) {
					if (flag!=""&&flag!=$(this)) { hSub(); flag=$(this); $(this).addClass("on"); }
					else { flag=$(this); $(this).addClass("on"); }
				}
				else { 
				if (flag!=""&&flag!=$(this)) { hSub(); flag=$(this); $(this).addClass("on"); }
					else { flag=$(this); $(this).addClass("on"); }
				}
			},
			function() {
				if ($(this).find("> ul").is("ul")) { tID=setTimeout(hSub,500); }
				else { $(this).removeClass("on"); flag=""; }
			}
		);
		// hover submenu
		$sli.hover(function() { $(this).addClass("on"); },function() { $(this).removeClass("on"); });
	});
	function hSub() { clearTimeout(tID); $(flag).removeClass("on"); flag=""; }
};
$.fn.book=function() {
	var $bk=$(this).find("> div"); var id=$(this).find(".activ").attr("id").replace("book",""); var thisID=0;
	var flag=true;
	$bk.click(function() {
		if (flag) {
			thisID=$(this).attr("id").replace("book",""); flag=false;
			if (id!=thisID&&thisID!=0) {
				$("#book"+id).removeClass("activ"); $("#book"+thisID).addClass("activ");
				$("#book-text"+id).animate({opacity:0},200,function() {
					$(this).css({display:"none"});
					id=thisID;
					$("#book-text"+thisID).css({display:"block",opacity:0}).animate({opacity:1},200,function() { flag=true; });
				});
			}
		}
	});
};
$.fn.pic=function() {
	return this.each(function() {
		if ($(this).hasClass("img-l")||$(this).hasClass("img-r")) {
			tit=$(this).attr("title");
			ifloat=$(this).hasClass("img-l")?"left":"right";
			ipd=$(this).hasClass("img-l")?"padding-right:20px;":"padding-left:20px;";
			html="";
			html+='<div class="pic-note" style="float:'+ifloat+';'+ipd+'width:'+$(this).width()+'px;">';
			html+='<img src="'+$(this).attr("src")+'">'+tit;
			html+='</div>';
			var $div=$(this).before(html); $(this).remove();
		}
	});
};
$(function() { $("#hmenu").hm(); if ($("#bookmark").is("#bookmark")) $("#bookmark").book(); $("img").pic(); });
