var thisPath = function(e) {
	var name = e.tagName;
	if(!!name && name.toUpperCase()=='SCRIPT') return e;
	var c = e.lastChild;
	return (!!c) ? thisPath(c) : null;
};
thisPath = thisPath(document);
thisPath = !thisPath ? window.location : thisPath.getAttribute('src') || window.location;
thisPath = thisPath.replace(/(\\|\/)[^\\\/]*$/, '/');

jQuery(document).ready(function($){
	$('#contents .main .column .list-article .box').hover(function(){
		$(this).css('background-color','#FFFFCC');
	},function(){
		$(this).css('background-color','#f4f4f4');
	});

	$('#m_img_index_areamap area').each(function(i){
		$(this).click(function(){
			var lag = 100;
			var speed = 300;
			var n = 0;
			$('input[name=state]').val($(this).attr('href').replace('#',''));
			$('.areamap img').attr('src',thisPath+'../images/img_index_areamap_a'+(i+1)+'.jpg');
			$('.visual-search #box-step-1').fadeOut(200,function(){
				$('.visual-search #box-step-2 ul li')
				.css("opacity","0").css("left","20px")
				.each(function(){
					$(this).stop().delay(n*lag).animate({left:"0",opacity:"1"},{duration:speed,easing:"swing"});
					n++;
				}).parent().parent().css('display','block');
			});
			return false;
		});
	}).parent().parent().append('<input type="hidden" name="state" />');
	/*
	$("#box-step-2 ul li a").fancybox({
		'width'		: '8',
		'height'	: '100%',
	        'autoScale'	: true,
	        'transitionIn'	: 'fade',
		'transitionOut'	: 'fade',
		'type'		: 'iframe'
	});
	*/

    $('#checkCapital').click(function(e){
        check('#checkCapital', '#capital');
    });

    $('#checkArea').click(function(e){
        check('#checkArea', '#area');
    });
});

function setPrefecture(value)
{
	$('#prefecture').val(value);

	$('#nav_area').attr('href', '/index.php/index/area?pref=' + $('#prefecture').val());
	$('#nav_station').attr('href', '/index.php/index/rosen?pref=' + $('#prefecture').val());
	$('#nav_category').attr('href', '/index.php/index/category?pref=' + $('#prefecture').val());

	Shadowbox.clearCache();
	Shadowbox.setup();
}

function setPrefectureForHope(value)
{
	$('#prefecture').val(value);
}

function postStep(mode){
	$('#mode').val(mode);
	$('form[name=regist]').submit();
}

function check(parent, target)
{
	$(target + ' li input[name="id[]"]').attr('checked', $(parent).attr('checked'));
}


function goSummary(id)
{
	document.location = '/bukken/summary?id=' + id;
}

