// UTF-8
/**
 * jquery.lu_ddmenu.js
 * Copyright (c) 2011 LockUP
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 * 
 *
*/
(function(jQuery) {
var show_class_name;
var speed;
var isDisplay = false;

jQuery.fn.lu_ddmenu = function(options){
	var op = jQuery.extend({
		cname : "lu_showMenu",
		left : "10px",
		top : "auto",
		speed : "fast"//noneの場合はカットイン
	},options);
	show_class_name=op.cname;
	speed = op.speed;
	var idName = this.selector;
	jQuery('head').append('<style type="text/css">'+idName+' dd {display:none;z-index:1000}'+idName+' dl.'+show_class_name+' {position:relative}'+idName+' dl.'+show_class_name+' dd{position:absolute;top:'+op.top+';left:'+op.left+'}</style>');
	
	jQuery(idName+" dt a").mouseover(function(e){
		if($(e.target).parent().parent().attr('class')==show_class_name){return}
		if(isDisplay){
			hide(idName);
		}
		show(this,idName);
	});
	jQuery(idName+" dd").mouseleave(function(e){
		if($(e.relatedTarget).parent().parent().attr('class')==show_class_name){
			return;
		}else{
			hide(idName);
		}
	});
	jQuery(this).mouseleave(function(){
		hide(idName);
	});
};


function show(target,idName){
	if(speed=="none"){
		jQuery(target).parents(idName+" li dl").attr({'class':show_class_name}).find('dd').show();
	}else{
		jQuery(target).parents(idName+" li dl").attr({'class':show_class_name}).find('dd').fadeIn(speed);
	}
	
	isDisplay=true;
}

function hide(idName){
	jQuery(idName+" dl."+show_class_name).attr({'class':''}).find('dd').hide();
	isDisplay=false;
}

})(jQuery);
