$(document).ready(function(){
	var hoverS = 500;
	var btnFlag = false;
	var openFlag = true;
	var menuFlag = false;
	
	var timerID = setTimeout(function(){
		if (openFlag && !menuFlag) {
			$('#footWrap').slideUp(hoverS / 2, openBtnChange);
		}
	}, 2000);
	
	//ipad
	if ($.os.name == "iphone" || $.os.name == "ipad" || $.os.name == "ipod") {
		$('#brandList a').addClass('closed').click(function(){
			if ($(this).hasClass("closed")) {
				$(this).addClass('opened');
				$('#brandList a').not($(this)).each(function(){
					$(this).removeClass('opend');
					$(this).removeClass('closed');
					$(this).addClass('closed');
				})
				$(this).removeClass('closed');
				$(this).parent().stop().animate({
					'height': '297px'
				}, {
					duration: hoverS,
					easing: 'swing',
					complete: function(){
						$(this).find('.logo').fadeIn(hoverS);
					}
				});
				$(this).parent().find('h2').stop().fadeTo(hoverS, 1);
				
				$('#brandList li').not($(this).parent()).each(function(){
					$(this).find('h2').stop().fadeTo(hoverS, 0);
					$(this).stop().animate({
						'height': '87px'
					}, {
						duration: hoverS * 1.2,
						easing: 'swing'
					});
					$(this).find('.logo').fadeOut(hoverS);
				});
				return false;
			}
		});
	} else {
		//brandList
		var hoverID;
		$('#brandList li').hover(function(){
			clearTimeout(hoverID);
			$(this).stop().animate({
				'height': '297px'
			}, {
				duration: hoverS,
				easing: 'swing',
				complete: function(){
					$(this).find('.logo').fadeIn(hoverS);
				}
			});
			if (jQuery.support.opacity) {
				$(this).find('h2').stop().fadeTo(hoverS, 1);
			} else {
				$(this).find('h2').show();
			}
			
			$('#brandList li').not(this).each(function(){
				if (jQuery.support.opacity) {
					$(this).find('h2').stop().fadeTo(hoverS, 0);
				} else {
					$(this).find('h2').hide();
				}
				$(this).stop().animate({
					'height': '87px'
				}, {
					duration: hoverS * 1.05,
					easing: 'swing'
				});
			});
		}, function(){
			clearTimeout(hoverID);
			$(this).stop().animate({
				'height': '129px'
			}, {
				duration: hoverS * 1.05,
				easing: 'swing'
			});
			
			$(this).find('.logo').fadeOut(hoverS);
			
			$('#brandList li').not(this).each(function(){
				$(this).stop().animate({
					'height': '129px'
				}, {
					duration: hoverS,
					easing: 'swing'
				});
				if (jQuery.support.opacity) {
					$(this).find('h2').stop().fadeTo(hoverS, 1);
				}
			});
			if (!jQuery.support.opacity) {
				hoverID = setTimeout(function(){
					$('#brandList li').find('h2').show();
				}, hoverS / 2);
			}
		});
	}
	
	$('#openBtn').click(function(){
		openBtnClick();
		$('#footWrap').stop().slideToggle(hoverS / 2);
		openFlag = !openFlag;
	}).hover(function(){
		btnFlag = true;
	}, function(){
		btnFlag = false;
	});
	
	$('#footer').hover(function(){
		menuFlag = true;
		clearTimeout(timerID);
	}, function(){
		menuFlag = false;
		if (openFlag) {
			timerID = setTimeout(function(){
				if (!btnFlag && openFlag && !menuFlag) {
					$('#footWrap').slideUp(hoverS / 2, openBtnChange);
				}
			}, 2000);
		}
	});
	
	
	
	function openBtnChange(){
		var src;
		if (btnFlag) {
			src = ($('#openBtn img').attr('src') === '/_common/images/footer/btn_close_on.gif') ? '/_common/images/footer/btn_open_on.gif' : '/_common/images/footer/btn_close_on.gif';
			$('#openBtn img').attr('src', src);
		} else {
			src = ($('#openBtn img').attr('src') === '/_common/images/footer/btn_close_off.gif') ? '/_common/images/footer/btn_open_off.gif' : '/_common/images/footer/btn_close_off.gif';
			$('#openBtn img').attr('src', src);
		}
		openFlag = !openFlag;
	}
	function openBtnClick(){
		var src = ($('#openBtn img').attr('src') === '/_common/images/footer/btn_close_on.gif') ? '/_common/images/footer/btn_open_on.gif' : '/_common/images/footer/btn_close_on.gif';
		$('#openBtn img').attr('src', src);
	}
});

