// ==================================================================
//
// $.spec.newsSlide  トップニュースのスライド
// $.spec.imageFade   メインイメージのフェード表示
//
// ==================================================================
(function($) {
	$(function(){
		//$.spec.newsSlide(1,300,4000);
		$.spec.imageFade(1,4000,"start");
		//$.spec.bnrSlideView(1,4000,"start");
		$.spec.LinkImageHightLight();
	});
	$.spec = {
		newsSlide: function(i,s,to)
		{
			if(i != 1)
			{
				clearTimeout(NewsSlide);
				var NewsMax = $("dl#slideNews dd li").length;
				if(NewsMax > 1)
				{
					var NewsAreaTop = $("dl#slideNews dd ul").css("top").replace(/([0-9]+)px/ , "$1")
					var Move = parseInt(NewsAreaTop - $("dl#slideNews dd li").height());
					var addNews = $("dl#slideNews dd ul li#news"+ parseInt(i-1)).html();
					$("dl#slideNews dd ul").append('<li id="news'+ parseInt(NewsMax + 1)+'">'+ addNews +'</li>');
					$("dl#slideNews dd ul").animate(
						{top: Move +"px"},
						s
					);
				}
			}
			if(NewsMax > 1)
			{
				var nextNO = parseInt(++ i);
				NewsSlide = setTimeout("$.spec.newsSlide('"+nextNO+"','"+s+"','"+to+"')",to);
			}
		},
		imageFade: function(i,to,s)
		{
			var imageLength = $(".fadeBox ul li").length;
			if(s != "start")
			{
				clearTimeout(fadeImage);
				$(".fadeBox ol li").removeClass("on");
				$(".fadeBox ul li").fadeOut();
				$(".fadeBox ul li.fade"+ i).fadeIn();
				$(".fadeBox ol li.fade"+ i).addClass("on");
				var nextNO = ++i;
			}
			else
			{
				$(".fadeBox ul li:first-child").css('display' , 'block');
				var nextNO = 2;
			}
			if(imageLength > 1)
			{
				if(i != parseInt(imageLength + 1))
				{
					fadeImage = setTimeout("$.spec.imageFade('"+nextNO+"','"+to+"')",to);
				}
				else
				{
					fadeImage = setTimeout("$.spec.imageFade('1','"+to+"')",to);
				}
			}
		},
		bnrSlideView: function(i,to,s)
		{
			var imageLength = $(".topImage ul li").length;
			var areaHeight = $(".topImage").height();
			if(s == "start")
			{
				var bnrSlideViewBtn = '<ol class="bnrSlideViewBtn">';
				for(var j=1; j<=imageLength; j++)
				{
					if(j == 1)
					{
						bnrSlideViewBtn = bnrSlideViewBtn + '<li class="bnrSlideViewBtn'+ j +'"><a href="javascript:bnrSlideViewBtn('+ j +','+ to +');" class="on">'+ j +'</a></li>';
					}
					else
					{
						bnrSlideViewBtn = bnrSlideViewBtn + '<li class="bnrSlideViewBtn'+ j +'"><a href="javascript:bnrSlideViewBtn('+ j +','+ to +');">'+ j +'</a></li>';
					}
				}
				bnrSlideViewBtn = bnrSlideViewBtn + '</ol>';
				$(".topImage").append(bnrSlideViewBtn);
				$(".topImage ol.bnrSlideViewBtn").css({
					'position': 'absolute',
					'z-index': '100',
					'bottom' : '10px',
					'right'  : '10px'
				});
				$(".topImage ol.bnrSlideViewBtn li").css({
					'margin': '0',
					'list-style': 'none'
				});
				$(".topImage ol.bnrSlideViewBtn li a").css({
					"width": '20px',
					"height": '20px',
					'margin-top': '5px',
					"text-align" : "center",
					"display" : "block",
					'font-size': '120%',
					'font-weight': 'bold',
					'text-decoration': 'none',
					'line-height': '1.5',
					'border' : '1px solid #CCCCCC'
				});
			}	
			if(s != "start")
			{
				clearTimeout(slideAction);
				var imageLength = $(".topImage ul li").length;
				var imageWidth = $(".topImage ul li#image"+ parseInt(i-1) +" img").width();
				var left = parseInt(i-1) * parseInt(-imageWidth);
				$(".topImage ul").animate({ left: left } , 600);
				$(".topImage ol.bnrSlideViewBtn li a").removeClass();
				var n = ++i;
				if(parseInt(i-1) <= imageLength)
				{
					$(".topImage ol.bnrSlideViewBtn li.bnrSlideViewBtn"+parseInt(n-1)+" a").addClass("on");
				}
				else
				{
					$(".topImage ol.bnrSlideViewBtn li.bnrSlideViewBtn1 a").addClass("on");
				}
			}
			else
			{
				var n = 2;	
			}
			if(imageLength > 1)
			{
				if(n > imageLength)
				{
					slideAction = setTimeout("$.spec.bnrSlideView('1','"+to+"')",to);
				}
				else
				{
					slideAction = setTimeout("$.spec.bnrSlideView('"+n+"','"+to+"')",to);
				}
			}
		},
		LinkImageHightLight : function()
		{
			$("a img.hightLight").mouseover(function(){
				$(this).parents("a").css({
					"display": 'block',
					"background": '#000000'
				});
				$(this).animate({opacity: "0.75"},100);
			});
			$("a img.hightLight").mouseout(function(){
				$(this).animate({opacity: "1"},100);
			});
		}
	};
})(jQuery);
function bnrSlideViewBtn(i,to)
{
	clearTimeout(slideAction);
	var imageLength = $(".topImage ul li").length;
	var imageWidth = $(".topImage ul li#image"+ parseInt(i-1) +" img").width();
	var left = parseInt(i-1) * parseInt(-imageWidth);
	$(".topImage ul").animate({ left: left } , 600);
	$(".topImage ol.bnrSlideViewBtn li a").removeClass();
	$(".topImage ol.bnrSlideViewBtn li.bnrSlideViewBtn"+i+" a").addClass("on");
	var n = ++i;
	if(imageLength > 1)
	{
		if(n > imageLength)
		{
			slideAction = setTimeout("$.spec.bnrSlideView('1','"+to+"')",to);
		}
		else
		{
			slideAction = setTimeout("$.spec.bnrSlideView('"+n+"','"+to+"')",to);
		}
	}
}


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


// =================================
//
// 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();	
}


