var sub_menu_open = false;
var sub_menu_line = -1;
var timer = -1, timer2 = -1, timer3 = -1;
var img_dir = "./img/sub/";
var img = [
	{sub : "sub_mame", menu : ["sub_pull_yougo", "sub_pull_buy", "sub_pull_rent"]},
	{sub : "sub_yakudachi", menu : ["sub_pull_multi", "sub_pull_hikkoshi", "sub_pull_loan"]},
	{sub : "sub_yomu",menu : ["sub_pull_blog"/*, "sub_pull_smile"*/]},
	{sub : "sub_shittoku", menu : ["sub_pull_machimusubi"/*, "sub_pull_4cityinfo"*/]},
	{sub : "sub_osusume", menu : ["sub_pull_site"]}
];

var submenu_init = 37;
var submenu_height = 202;
var animation_height = 37;

ua = navigator.userAgent;
if(ua.match(/Windows/) && ua.match(/MSIE [56]/)){
	animation_height = 60;
	submenu_init = 60;
	submenu_height = 225;
}

function initSubMenu(){
	animation_height = submenu_init;
	Element.hide($('SubMenuOpen'));
	sub_menu_open = false;
}

function hideSubMenu(){
	if(sub_menu_open == true && timer == -1 && timer3 == -1){
		timer = setTimeout("closeSubMenu()", 1000);
		overSubMenu(-1);
	}
}

function closeSubMenu(){
	timer == -1;
	if(sub_menu_open == true && timer3 == -1){
		animation_height = submenu_height;
		timer3 = setInterval("closeAnimation()", 10);
	}
}

function showSubMenu(n){
	if(!sub_menu_open){
		$('SubMenuOpen').style.height = submenu_init + 'px';

		if($('SubMenuOpen').style.display == 'none'){
			Element.hide($('SubMenuClose'));
			Element.show($('SubMenuOpen'));
		}

		clearTimeout(timer);
		timer = -1;
		clearTimeout(timer3);
		timer3 = -1;
		sub_menu_open = true;

		if(animation_height != submenu_height){
			timer2 = setInterval("openAnimation()", 10);
		}
	}
	if(n != -1){
		overSubMenu(n);
	}
}

function overSubMenu(n){
	if(sub_menu_line != -1){
		$('Sub_' + sub_menu_line).src = img_dir + img[sub_menu_line].sub + '_down.gif';
		for(var i = 0; i < img[sub_menu_line].menu.length; i++){
			$('Sub_' + sub_menu_line + '_' + i).src = img_dir + img[sub_menu_line].menu[i] + '_down.gif';
		}
	}
	if(n != -1){
		clearTimeout(timer);
		timer = -1;
		sub_menu_open = true;

		$('Sub_' + n).src = img_dir + img[n].sub + '.gif';
		for(var i = 0; i < img[n].menu.length; i++){
			$('Sub_' + n + '_' + i).src = img_dir + img[n].menu[i] + '.gif';
		}
	}
	sub_menu_line = n;
}

function openAnimation(){
	animation_height += 10
	if(animation_height >= submenu_height){
		clearTimeout(timer2);
		timer2 = -1;
		animation_height = submenu_height;
		sub_menu_open = true;
	}
	$('SubMenuOpen').style.height = animation_height + 'px';
}

function closeAnimation(){
	animation_height -= 10
	if(animation_height <= submenu_init){
		clearTimeout(timer3);
		timer3 = -1;
		animation_height = submenu_init;
		Element.hide($('SubMenuOpen'));
		Element.show($('SubMenuClose'));
		overSubMenu(-1);
		sub_menu_open = false;
	}
	$('SubMenuOpen').style.height = animation_height + 'px';
}