// =================================
//
// fadeBox
//
// =================================
$(function(){
	$(".fadeBox ul li:first-child").css('display' , 'block');
	var MAX = $(".fadeBox ul li").length;
	var height = $(".fadeBox ul li:first-child img").height();
	$(".fadeBox").css("height" , height);
	if(MAX > 1){
		$(
			fadeImage = setTimeout("imageFade('1')",4000)
		);
   }
   var imgObj = $(".fadeBox ul li:first-child").html();
});
function imageFade(NO)
{
	clearTimeout(fadeImage);
	var imageLength = $(".fadeBox ul li").length;
	$(".fadeBox ol li").removeClass("on");
	$(".fadeBox ul li").fadeOut();
	var nextNO = ++NO;
	$(".fadeBox ul li.fade"+ nextNO).fadeIn();
	$(".fadeBox ol li.fade"+ nextNO).addClass("on");

	if(NO != imageLength)
	{
		fadeImage = setTimeout("imageFade('"+nextNO+"')",4000);
	}
	else
	{
		fadeImage = setTimeout("imageFade('0')",4000);
	}
}

function swapImage(area , src)
{
	$(area + ' img').attr('src', src);
}


// =================================
//
// viewMap (google map表示)
//
// =================================
function viewMap(name,address,gmap,img)
{
	var gmapWidth = "400";
	var gmapheight = "400";
	var gmapTag = '<iframe width="'+ gmapWidth +'" height="'+ gmapheight +'" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.co.jp/maps?f=q&amp;source=s_q&amp;hl=ja&amp;geocode=&amp;q='+ gmap +'&amp;output=embed&amp;iwloc=B"></iframe>';
	var mapImgTag = '<img src="'+ img +'" width="'+ gmapWidth +'" height="'+ gmapheight +'" alt="'+ name +'" />';
	if(gmapTag != '')
	{
		var map = gmapTag;
	}
	else
	{
		var map = mapImgTag;
	}
	$('body').append('<div class="overRay"></div>');
	$('.overRay').css({
		"background":"#000000",
		"opacity":"0.20",
		"width":"100%",
		"height":$('.wrapper').height(),
		"position":"absolute",
		"top":"0",
		"left":"0"
	});
	$(".overRay").fadeIn();
	$('body').append('<div class="gmap">'+ map +'<p><strong>'+ name +'</strong><br />'+ address +'</p><p class="close"><a href="javascript:lightBoxfadeOut('+"'"+'.overRay'+"'"+','+"'"+'.gmap'+"'"+');"><img src="/u/pc/images/common/lightbox-btn-close.gif" width="66" height="22" alt="CLOSE" /></a></p></div>');
	$('.gmap').css({
		"position":"absolute",
		"top":parseInt(($(window).height() - gmapheight)/2 + $(window).scrollTop()) + "px",
		"left":($(window).width() - gmapWidth+parseInt(16))/2 + "px",
		"background":"#FFFFFF",
		"border":"3px solid #666666",
		"z-index":"1001",
		"display":"none",
		"width":gmapWidth + "px",
		"padding":"5px",
		"font-size":"75%"
	});
	$('.gmap p').css({
		"line-height":"1.8"
	});
	$('.gmap p.close').css({
		"text-align":"right"
	});
	$(".gmap").fadeIn();
	$(".overRay").click(function(event){
		lightBoxfadeOut('.overRay','.gmap');
	});
}

function lightBoxfadeOut(bg, box){
	$(bg).fadeOut();
	$(box).fadeOut();
	setTimeout("lightBoxRemove('"+ bg +"','"+ box +"')",500);
}
function lightBoxRemove(bg, box){
	$(bg).remove();
	$(box).remove();	
}


