function initMain() 
{
	$('mbb').select('.mainBannerImg').each(function(img) {
		img.observe("mouseover", function(e) {
			var el = e.element();
			$$('.mainBannerImg').each(function(bimg) {
				bimg.setAttribute('src', bimg.getAttribute('src').replace(/_on\.gif/, '.gif'));
			});
			el.setAttribute('src', el.getAttribute('src').replace(/\.gif/, '_on.gif'));
			$('mainBanner').setAttribute('src', el.getAttribute('main'));
		});
	});
}

function initMenu(TopMenu, LeftMenu) {
	$('gnb').select('.mainMenuImg').each(function(img) {
		setFixed(img, 'menu_'+TopMenu+'.gif');
		img.observe('mouseover', menuOver);
		img.observe('mouseout', menuOut);
	});
	
	if (LeftMenu)
	{
		$$('.leftmenu').each(function(menu, index) {
			var LeftIndex = index + 1;
			if (LeftMenu == LeftIndex)
			{
				menu.removeClassName("leftmenu");
				menu.addClassName("leftmenu_on white b");
			}
			else
			{
				menu.observe("mouseover", function() {
					this.removeClassName("leftmenu");
					this.addClassName("leftmenu_on white b");
				});
				menu.observe("mouseout", function() {
					this.removeClassName("leftmenu_on white b");
					this.addClassName("leftmenu");
				});
			}
		});
	}
}


function setFixed(el, key) {
	var nowSrc = el.getAttribute('src');
	if (nowSrc.indexOf(key) >= 0) {
		el.setAttribute('src', nowSrc.replace(/\.gif/, '_on.gif'));
		el.setAttribute('fixed', 'true');
	}
}

function menuOver(e) {
	var el = e.element();
	var src = el.getAttribute('src');
	if ((src.indexOf('_on') < 0) && (el.getAttribute('fixed') != 'true'))
		el.setAttribute('src', src.replace(/\.gif/, '_on.gif'));
}

function menuOut(e) {
	var el = e.element();
	var src = el.getAttribute('src');
	if ((src.indexOf('_on') > 0) && (el.getAttribute('fixed') != 'true'))
		el.setAttribute('src', src.replace(/_on\.gif/, '.gif'));
}

function AutoBlur() {
	$$('a').each( function (el, index) {
		el.onfocus = function () { el.blur(); };
	});
}
Event.observe(window, 'load', AutoBlur, false);

function toggleFullMenu() {
	var id = 'fullmenu';
	var option = { duration: 0.2 };
	var btnimg = $('btnFullMenu').getAttribute('src');
	if ($(id).visible() === false) 
	{
		$('btnFullMenu').setAttribute('src', btnimg.replace('fullmenu', 'fullmenu2'));
		Effect.SlideDown(id, option);
	}
	else 
	{
		$('btnFullMenu').setAttribute('src', btnimg.replace('fullmenu2', 'fullmenu'));
		Effect.SlideUp(id, option);	
	}
}

/* form check */
function CheckFormValue(form)
{
	var els = Form.getElements(form);
	
	/* check required field */
	var chk = els.detect( function (el, index) {
		if (el.disabled)
			return false;
		else if ((el.getAttribute('isRequire') == 'true') && (el.value.gsub(/[ ]+/, '') == ''))
			return true;
	});
	if (chk != null)
	{
		OutCheckValueMsg(chk, chk.getAttribute('isRequireMsg'));
		return false;
	}
	
	/* check email field */
	var email_pattern = /^.+@[._a-zA-Z0-9-]+\.[a-zA-Z]*$/;
	var chk = els.detect( function (el, index) {
		if (el.disabled)
			return false;
		else if ((el.getAttribute('isEmail') == 'true') && !email_pattern.test(el.value))
			return true;
	});
	if (chk != null)
	{
		OutCheckValueMsg(chk, chk.getAttribute('isEmailMsg'));
		return false;
	}
	
	return true;
}
function OutCheckValueMsg(el, msg)
{
	alert(msg);
	if ((el.getStyle('display') != 'none') && !el.getAttribute('disabled') && (el.getAttribute('type') != 'hidden'))
		el.focus();
}

function SendForm(form_id, url)
{
	var form = document.forms[form_id];
	if (CheckFormValue(form))
	{
		form.action = url;
		form.submit();
	}
}



function ShowFamilySite()
{
	
	var FamilySiteBox = $('familysite');
	var BaseBox = $('BaseFamilySiteBox');
	var offset = BaseBox.cumulativeOffset();

	FamilySiteBox.setStyle({
		position: 'absolute',
		left: (offset[0] - $('footer').cumulativeOffset()[0]) + 'px',
		top: (offset[1] - 208) + 'px'
	});
	FamilySiteBox.show();
}

Event.observe(window.document, 'mousemove', function(e) {
	var FamilySiteBox = $('familysite');
	if (FamilySiteBox && !Position.within(FamilySiteBox, Event.pointerX(e), Event.pointerY(e)))
		FamilySiteBox.hide();
}, true);















var isBanner = {
	duration: 0.5,
	prev: 0,
	handleOver: function(index, event) {
		if (this.prev != index) {
			alert(event.element().getAttribute("src"));
			$$('.bigElement')[this.prev].hide();
			$$('.bigElement')[index].show();

			var smallElementPrev = $$('.smallElement')[this.prev];
			var smallElement = $$('.smallElement')[index];
			smallElementPrev.setAttribute(smallElementPrev.getAttribute("src").replace("_on", ""));
			//$$('.bigElement')[this.prev].setOpacity(0);
			//$$('.bigElement')[index].setOpacity(1);
			//new Effect.Opacity($$('.bigElement')[this.prev], {duration: this.duration, from: 1, to: 0});
			//new Effect.Opacity($$('.bigElement')[index], {duration: this.duration, from: 0, to: 1});
			this.prev = index;
		}
	},
	init: function() {
	
		var bigElement = $$('.bigElement');
		bigElement.each(function(item, index) {
			if (index == 0)
				item.show();
			else 
				item.hide();
			//item.setOpacity((index == 0) ? 1 : 0);
		});

		var smallElement = $$('.smallElement');
		smallElement.each(function(item, index) {
			item.observe("mouseover", function(e) {
				isBanner.handleOver(index, e);
			});
		});
	}	
};



