function transportLayerHide() {
	$(this).fadeOut();
	$(this.aObj).removeClass('XenoMouseOver');
	this.aObj = null;
}

function yahooAllCategoryFirstOpen() {
	$(this).unbind('click', yahooAllCategoryFirstOpen);
	$('#yahooAllCategoryLayer a.close').click(function() {
		$('#yahooAllCategoryButton').click();
		return false;
	});
	$.get('/yahoo/allcategories_html', function(data, statusText) {
		$('#yahooAllCategoryLayer div.box').html(data);
		$('#yahooAllCategoryLayer dd').mouseenter(function() {
			$('div.categoryLayer', this).fadeIn();
		}).mouseleave(function() {
			$('div.categoryLayer', this).fadeOut();
		});
	}, 'html');
	$(this).toggle(function() {
		$(this).addClass('XenoMouseOver');
		$('#yahooAllCategoryLayer').show();
		$('#yahooAllSearch select').hide();
		return false;
	}, function() {
		$(this).removeClass('XenoMouseOver');
		$('#yahooAllCategoryLayer').hide();
		$('#yahooAllSearch select').show();
		return false;
	}).click();
	return false;
}

$(function() {
/* /include/top/topmenu.tpl.html */
	$('a[name=transportLink]').click(function(event) {
		this.blur();
		var layer = $('#transportLayer')[0];
		if($(this).hasClass('XenoMouseOver')) {
			$(layer).each(transportLayerHide);
			$(this).removeClass('XenoMouseOver');
			return false;
		}
		if(layer.aObj) {
			$(layer.aObj).removeClass('XenoMouseOver');
		}
		layer.aObj = this;
		var offset = $(this).offset();
		offset.top += $(this).height();
		$(layer).css({'left':offset.left,'top':offset.top});
		$(this).addClass('XenoMouseOver');
		$('#transportLayer').fadeIn();
		return false;
	});
	$('#transportLayer').mouseleave(transportLayerHide);

/* /include/top/searchbar.tpl.html */
	$('#transUrl').submit(function() {
		dt.DownShow(this.url.value);
		return false;
	});
	$('#transSearch').each(function() {
		var form = this;
		$(this.site).change(function() {
			switch(this.value) {
				case 'yahoojp':
					$(this.form).addClass('yahoojp').removeClass('rakuten');
					break;
				case 'rakuten':
					$(this.form).addClass('rakuten').removeClass('yahoojp');
					break;
			}
		});
		$(this.p).keydown(function(event) {
			if(event.keyCode == 13) {
				event.stopPropagation();
				return false;
			}
		});
		$(this).submit(function() {
			
		});
	});

/* /yahoo/url.tpl.html */
	$('#thisURL').submit(function() {
		location.href = '/yahoo.s/' + urlencode(this.url.value);
		return false;
	});
	
/* /yahoo/allcategories.tpl.html */
	$('#yahooAllCategoryButton').bind('click', yahooAllCategoryFirstOpen).each(function() {
		if(this.rel == 'opened') $(this).click();
	});

	$('#searchZip').autocomplete({
		'source':'/zip/kr',
		'minLength':2,
		'select':function(event, ui) {
			this.form.zipcode.value = ui.item.zipcode;
			this.form.addr.value = ui.item.addr;
			this.form.addr_remain.focus();
		}
	}).everyTime(500, function() {
		$(this).trigger('keydown');
	});

	$('#searchZipJp').autocomplete({
		'source':'/zip/jp',
		'minLength':5,
		'select':function(event, ui) {
			this.form.zipcode.value = ui.item.zipcode;
			this.form.addr.value = ui.item.addr;
			this.form.addr_remain.focus();
		}
	}).everyTime(500, function() {
		$(this).trigger('keydown');
	});
});
