/* -------------------------------------------

	画像のロールオーバー処理。
	
	画像名の末尾「_off」を自動で「_on」に書き換える。

------------------------------------------- */
function autoRollover()
{
	if(document.getElementsByTagName)
	{
		var url = document.URL;
		
		/* -------------------------------------
		
		グローバルナビのカレント処理。
		
		------------------------------------- */
		if(document.getElementById('gNavi'))
		{
			var gNavi = document.getElementById('gNavi');
			gNavi = gNavi.getElementsByTagName('a');
			
			if(url.indexOf('/diary/') >= 0){ gNavi[0].style.backgroundPosition = '0 100%'; }// リフォームの流れ
			if(url.indexOf('about.php') >= 0){ gNavi[1].style.backgroundPosition = '0 100%'; }// 水工房とは
			if(url.indexOf('staff.php') >= 0){ gNavi[2].style.backgroundPosition = '0 100%'; }// スタッフ
			if(url.indexOf('kodate') >= 0){ gNavi[3].style.backgroundPosition = '0 100%'; }// 戸建て
			if(url.indexOf('mansion') >= 0){ gNavi[4].style.backgroundPosition = '0 100%'; }// マンション
			if(url.indexOf('contact') >= 0){ gNavi[5].style.backgroundPosition = '0 100%'; }// 
		}
		
		/* -------------------------------------
		
		サイドナビ(戸建・マンション)のカレント処理。
		
		------------------------------------- */
		if(document.getElementById('sideNavi'))
		{
			var sideNavi = document.getElementById('sideNavi');
			sideNavi = sideNavi.getElementsByTagName('a');

			if(url.indexOf('kodate') >= 0){ sideNavi[0].style.backgroundPosition = '0 100%'; }// 戸建て
			if(url.indexOf('mansion') >= 0){ sideNavi[1].style.backgroundPosition = '0 100%'; }// マンション
			if(url.indexOf('/diary/') >= 0){ sideNavi[2].style.backgroundPosition = '0 100%'; }// /diary/
			if(url.indexOf('layout') >= 0){ sideNavi[3].style.backgroundPosition = '0 100%'; }// 間取り図
		}
		
		/* -------------------------------------
		
		サイドナビ(個別)のカレント処理。
		
		------------------------------------- */
		if(document.getElementById('listLink02'))
		{
			var listLink02 = document.getElementById('listLink02');
			listLink02 = listLink02.getElementsByTagName('a');
			
			if(url.indexOf('interest01.php') >= 0){ listLink02[0].style.backgroundPosition = '100% 0'; }
			if(url.indexOf('interest02.php') >= 0){ listLink02[1].style.backgroundPosition = '100% 0'; }
			
			if(url.indexOf('interest03.php') >= 0){ listLink02[2].style.backgroundPosition = '100% 0'; }
			if(url.indexOf('interest04.php') >= 0){ listLink02[3].style.backgroundPosition = '100% 0'; }
			
			if(url.indexOf('interest05.php') >= 0){ listLink02[4].style.backgroundPosition = '100% 0'; }
			if(url.indexOf('interest06.php') >= 0){ listLink02[5].style.backgroundPosition = '100% 0'; }
		}
		
		if(document.getElementById('listLink03'))
		{
			var listLink03 = document.getElementById('listLink03');
			listLink03 = listLink03.getElementsByTagName('a');
			
			if(url.indexOf('bathKitchen.php') >= 0){ listLink03[0].style.backgroundPosition = '100% 0'; }
			if(url.indexOf('livingKidsroom.php') >= 0){ listLink03[1].style.backgroundPosition = '100% 0'; }
			if(url.indexOf('others.php') >= 0){ listLink03[2].style.backgroundPosition = '100% 0'; }
		}
		
		if(document.getElementById('listLink04'))
		{
			if(url.indexOf('about.php') >= 0){ document.getElementById('page01').style.backgroundPosition = '100% 0'; }
			if(url.indexOf('staff.php') >= 0){ document.getElementById('page02').style.backgroundPosition = '100% 0'; }
			if(url.indexOf('reformFlow.php') >= 0){ document.getElementById('page03').style.backgroundPosition = '100% 0'; }
			
			if(url.indexOf('customer.php') >= 0){ document.getElementById('page04').style.backgroundPosition = '100% 0'; }
			if(url.indexOf('twoGeneration.php') >= 0){ document.getElementById('page05').style.backgroundPosition = '100% 0'; }
			if(url.indexOf('hikarireidan.php') >= 0){ document.getElementById('page07').style.backgroundPosition = '100% 0'; }
			if(url.indexOf('loan.php') >= 0){ document.getElementById('page08').style.backgroundPosition = '100% 0'; }
			
			if(url.indexOf('faq.php') >= 0){ document.getElementById('page06').style.backgroundPosition = '100% 0'; }
			
			if(url.indexOf('skeleton.php') >= 0){ document.getElementById('page09').style.backgroundPosition = '100% 0'; }
			if(url.indexOf('event.php') >= 0){ document.getElementById('page10').style.backgroundPosition = '100% 0'; }
			
			if(url.indexOf('check.php') >= 0){ document.getElementById('page12').style.backgroundPosition = '100% 0'; }
			
			if(url.indexOf('contact.php') >= 0){ document.getElementById('page13').style.backgroundPosition = '100% 0'; }
		}
	
		
		

		/* -------------------------------------
		
		imgタグにsrc属性がある場合の処理。
		
		------------------------------------- */
		var imageTags = document.getElementsByTagName("img");
		
		for(var i=0; i < imageTags.length; i++)
		{
			if(imageTags[i].getAttribute("src").match("_off."))
			{
				imageTags[i].onmouseover = function()
				{
					this.setAttribute("src", this.getAttribute("src").replace("_off.", "_on."));
				}
				
				imageTags[i].onmouseout = function()
				{
					this.setAttribute("src", this.getAttribute("src").replace("_on.", "_off."));
				}
			}// end if
		}// enf for
		
		/* -------------------------------------
		
		inputタグにsrc属性がある場合の処理。
		
		------------------------------------- */
		var inputSrcTags = document.getElementsByTagName("input");
		
		for(var j=0; j < inputSrcTags.length; j++)
		{
			if(inputSrcTags[j].getAttribute("src"))
			{
				if(inputSrcTags[j].getAttribute("src").match("_off."))
				{
					inputSrcTags[j].onmouseover = function()
					{
						this.setAttribute("src", this.getAttribute("src").replace("_off.", "_on."));
					}
					
					inputSrcTags[j].onmouseout = function()
					{
						this.setAttribute("src", this.getAttribute("src").replace("_on.", "_off."));
					}
				}
			}
		}
	}// end if
}

if(window.addEventListener)
{
	window.addEventListener("load", autoRollover, false);
}
else if(window.attachEvent)
{
	window.attachEvent("onload", autoRollover);
}

/* ===========================

	Move to page top
	
	for firefox3.6
	
	Not for iphone

=========================== */
function Back()
{
	if(document.documentElement){ y1 = document.documentElement.scrollTop || 0; }
	if(document.body){ y2 = document.body.scrollTop || 0; }
	
	y3 = window.scrollY || 0;
	
	var y = Math.max(y1, Math.max(y2, y3));
	
	window.scrollTo(0, y / 1.4);//移動量調整

	if(y > 1)
	{
		window.setTimeout(function()
		{
			Back();
		}, 10);//リピート速度調整 msc
	}
}


$(function()
{
	$('.pagetop, .pagetopType01, .pagetopType02, .pagetopType03, .pagetopMiddle').find('a').click(function()
	{
		Back();
		return false;
	});
	/* ====================
	
	favorite
	
	==================== */
	var favorite = $('.favorite');
	
	if( navigator.userAgent.indexOf('IE') == -1 )
	{
		favorite.css({ display : 'none' });
	}
	else
	{
		favorite.click(function( e )
		{
		  e.preventDefault();
		  window.external.addFavorite( document.URL, document.title );
		});
	}
})

