// ------------------------------------------------------------------------------
//  common js
// ------------------------------------------------------------------------------
/*

   01........オンマウスイメージ
   02........スクロールするページトップへ
   03........jQueryでページ内スムーズスクロール
   04........jQuery:cmnTable first,last style
   05........jQuery:works
   06........jQuery:form
   
*/

// ------------------------------------------------------------------------------
// ***01 オンマウスイメージ***
// ------------------------------------------------------------------------------


function smartRollover() {
	if(document.getElementsByTagName) {
		var images = document.getElementsByTagName("img");
		for(var i=0; i < images.length; i++) {
			if(images[i].getAttribute("src").match("_off."))
			{
				images[i].onmouseover = function() {
					this.setAttribute("src", this.getAttribute("src").replace("_off.", "_on."));
				}
				images[i].onmouseout = function() {
					this.setAttribute("src", this.getAttribute("src").replace("_on.", "_off."));
				}
			}
		}
	}
}
if(window.addEventListener) {
	window.addEventListener("load", smartRollover, false);
}
else if(window.attachEvent) {
	window.attachEvent("onload", smartRollover);
}


// ------------------------------------------------------------------------------
// ***02 スクロールするページトップへ***
// ------------------------------------------------------------------------------

function getScrollLeft() { 
 if ((navigator.appName.indexOf("Microsoft Internet Explorer",0) != -1)) {

  /*WinIE6標準モード稼動オブジェクト差異対応
    WinIE6標準モードとそれ以外で、それぞれ稼動しているオブジェクトを取り出す*/
  docele=(document.compatMode=="CSS1Compat")?document.documentElement:document.body;

  return docele.scrollLeft;

 } else if (window.pageXOffset) {
  return window.pageXOffset;
 } else {
  return 0;
 }
}

function getScrollTop() { 
 if ((navigator.appName.indexOf("Microsoft Internet Explorer",0) != -1)) {

  /*WinIE6標準モード稼動オブジェクト差異対応
    WinIE6標準モードとそれ以外で、それぞれ稼動しているオブジェクトを取り出す*/
  docele=(document.compatMode=="CSS1Compat")?document.documentElement:document.body;
  
  return docele.scrollTop;

 } else if (window.pageYOffset) {
  return window.pageYOffset;
 } else {
  return 0;
 }
}

var pageScrollTimer;

function pageScroll(toX,toY,frms,cuX,cuY) { 
 if (pageScrollTimer) clearTimeout(pageScrollTimer);
 if (!toX || toX < 0) toX = 0;
 if (!toY || toY < 0) toY = 0;
 if (!cuX) cuX = 0 + getScrollLeft();
 if (!cuY) cuY = 0 + getScrollTop();
 if (!frms) frms = 6;

 if (toY > cuY && toY > (getAnchorPosObj('end','enddiv').y) - getInnerSize().height) toY = (getAnchorPosObj('end','enddiv').y - getInnerSize().height) + 1;
 cuX += (toX - getScrollLeft()) / frms; if (cuX < 0) cuX = 0;
 cuY += (toY - getScrollTop()) / frms;  if (cuY < 0) cuY = 0;
 var posX = Math.floor(cuX);
 var posY = Math.floor(cuY);
 window.scrollTo(posX, posY);

 if (posX != toX || posY != toY) {
  pageScrollTimer = setTimeout("pageScroll("+toX+","+toY+","+frms+","+cuX+","+cuY+")",16);
 }
}

function jumptop() { 
  pageScroll(0,0,3);
}


// ------------------------------------------------------------------------------
// ***03 jQueryでページ内スムーズスクロール***
// ------------------------------------------------------------------------------



// ------------------------------------------------------------------------------
// ***04 jQuery:cmnTable first,last style***
// ------------------------------------------------------------------------------

$(function(){
	$('div#mainArea table.cmn tr:first-child').addClass('first');
	$('div#mainArea table.cmn tr:last-child').addClass('last');
});


// ------------------------------------------------------------------------------
// ***05 jQuery:works***
// ------------------------------------------------------------------------------
//制作実績「事例詳細」ボタンロールオーバー処理

$(function(){
	$(".worksPage .entryBlock .capture").mouseover(function(e){
		$($(this).children('span')).css("display","block");
	});
	
	$(".worksPage .entryBlock .capture").mouseout(function(){
		$($(this).children('span')).css("display","none");
	});
	
});

//制作実績「類似事例」偶数奇数処理(MT側で処理できないものをフォロー)

$(function(){
	$(".worksPage.entryPage .entrySection .entryBlock:odd").addClass('even');
	$(".worksPage.entryPage .entrySection .entryBlock:even").addClass('odd');
}); 


// ------------------------------------------------------------------------------
// ***06 jQuery:form***
// ------------------------------------------------------------------------------
// フォームのフォーカス処理

$(function(){
	$("body.formPage #mainArea .formSection table td input,body.formPage #mainArea .formSection table td textarea").focus(function(){
		$(this).css("background","#f8f0b2");
	});
	$("body.formPage #mainArea .formSection table td input,body.formPage #mainArea .formSection table td textarea").blur(function(){
		$(this).css("background","#fff");
	});
});
