$(function(){
    
    var subArrayObject = Array();
	var subArrayObjectA = Array();
	objArrayHtml = Array();
	var statusObject = null;
    
    $("#navi_main > ul > li > a").each(function(i){
        $(this).bind('mouseover mouseout', function(event){
            if(event.type=='mouseover'){
                
                statusObject = null;
				$(this).addClass("on");
				$(this).parent().find("*").each(function(i){
					objArrayHtml[i] = $(this).html();
				});
                
                $(this).parent().find("ul").slideDown('slow', function(){
					if (statusObject != null)
					{
						if (inArray(objArrayHtml, statusObject)==false)
						{
							$(this).parent().find("a").removeClass("on");
							$(this).slideUp();
						}
					}
				}).bind("mouseout", function(event){
					if (inArray(objArrayHtml, $(event.relatedTarget).html())==false)
					{
						$(this).parent().find("a").removeClass("on");
						$(this).slideUp();
					}
				});
                
            }else{
                if (inArray(objArrayHtml, $(event.relatedTarget).html())==false)
				{
					$(this).parent().find("ul").slideUp();
					$(this).removeClass("on");
				}
				statusObject = $(event.relatedTarget).html();
            }
        })
    });
});

function removeSpace(str){
	index = 0;
	while (str.indexOf(' ') != -1)
	{
		index = str.indexOf(' ');
		str1 = str.substring(0, index);
		str2 = str.substring(index+1);
		str = str1+str2;
	}

	str = str.replace(/(\r\n|\n)/g, "");

	return str;
}

function sleep(sec) { 
	var now = new Date();
	var exitTime = now.getTime() + (sec);
	while (true) {
		now = new Date();
		if (now.getTime() > exitTime) return;
	}
}

function inArray(arr, val) {
	for (var i = 0, len = arr.length; i < len; i++) {
		if(arr[i] === val) return true;
	}
	return false;
}

/*
	정규식
	test = $(event.relatedTarget).html();
	rerexp = /<DD.*?>|<\/DD>/gi;
	test = test.replace(rerexp, "");
	rerexp = /<DT.*?>*<\/A>/gi;
	test = test.replace(rerexp, "");
	test = test.replace("\\n", "");
	//alert(objArrayHtml);
	//alert(test);
*/
