
// class="rollover"でロールオーバー

function initRollovers() {
  if (!document.getElementById) return
  
  var aPreLoad = new Array();
  var sTempSrc;
  var aImages = document.getElementsByTagName('img');
  var imputBtn = document.getElementsByTagName('input');

  for (var i = 0; i < aImages.length; i++) {    
    if (aImages[i].className == 'rollover') {
      var src = aImages[i].getAttribute('src');
      var ftype = src.substring(src.lastIndexOf('.'), src.length);
      var hsrc = src.replace(ftype, '_on'+ftype);

      aImages[i].setAttribute('hsrc', hsrc);
      
      aPreLoad[i] = new Image();
      aPreLoad[i].src = hsrc;
      
      aImages[i].onmouseover = function() {
        sTempSrc = this.getAttribute('src');
        this.setAttribute('src', this.getAttribute('hsrc'));
      }  
      
      aImages[i].onmouseout = function() {
        if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_on'+ftype, ftype);
        this.setAttribute('src', sTempSrc);
      }
    }
  }

  for (var i = 0; i < imputBtn.length; i++) {    
    if (imputBtn[i].className == 'rollover') {
      var src = imputBtn[i].getAttribute('src');
      var ftype = src.substring(src.lastIndexOf('.'), src.length);
      var hsrc = src.replace(ftype, '_on'+ftype);

      imputBtn[i].setAttribute('hsrc', hsrc);
      
      aPreLoad[i] = new Image();
      aPreLoad[i].src = hsrc;
      
      imputBtn[i].onmouseover = function() {
        sTempSrc = this.getAttribute('src');
        this.setAttribute('src', this.getAttribute('hsrc'));
      }  
      
      imputBtn[i].onmouseout = function() {
        if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_on'+ftype, ftype);
        this.setAttribute('src', sTempSrc);
      }
    }
  }
}


// ランダムに背景色を変え、背景色にあわせて会社名画像を入れ替える（トップページのみ）

function chgColor() {
	if(document.getElementById('CHGBG')) {
	var chgTgt = document.getElementById('CHGBG');
		bg = new Array();	//背景色
		bg[0] = "#515151";	//グレー
		bg[1] = "#1a448b";	//青
		bg[2] = "#9b1420";	//赤
		bg[3] = "#ee9e0e";	//オレンジ
		img = new Array();	//会社名画像
		img[0] = "/img/home/txt_name_gry.gif";
		img[1] = "/img/home/txt_name_blue.gif";
		img[2] = "/img/home/txt_name_red.gif";
		img[3] = "/img/home/txt_name_ylw.gif";
		n = Math.floor(Math.random()*bg.length);
		document.getElementById('CHGBG').style.backgroundColor = bg[n];
		document.getElementById('CNAME').setAttribute('src',img[n]);
	}
}

// 矢印画像をランダムに入れ替える（トップページのみ）

function chgArrow() {
	if(document.getElementById('RDMARROW')) {
		var chgArw = document.getElementById('RDMARROW');
		var aLength = 7;	//画像の数
		n2 = Math.floor(Math.random()*aLength);
		var aSrc = '/img/home/arrow0' + n2 + '.gif';
		document.getElementById('RDMARROW').setAttribute('src',aSrc);
	}
}

// 複数のfunctionをonloadで実行する

function FuncDepot() {
  this._bullets = [];
  this.load = function(f) { try {
    this._bullets[this._bullets.length] = f;
  } catch(e) {} };
  this.shot = function() { try {
    for(var i = 0; i < this._bullets.length; this._bullets[i++]());
  } catch(e) {} };
}
var OnloadFunc = new FuncDepot();
window.onload = function() { OnloadFunc.shot(); };

OnloadFunc.load(initRollovers);
OnloadFunc.load(chgColor);
OnloadFunc.load(chgArrow);
OnloadFunc.load(heightSet);


// フッタをウィンドウの下部に固定する

function heightSet() {
	var pf = navigator.platform.charAt(0);
	var idMain = document.getElementById("MAIN");
	var footerHeight = 110;
	var someMargin = 0;
	var totalFoot = footerHeight + someMargin;
	
	var usrAgt = navigator.userAgent.toLowerCase();
	var appVer = navigator.appVersion;
	var isIe = usrAgt.indexOf("msie") != -1;
	var isIe7 = usrAgt.indexOf("msie 7") != -1;
	var isIe8 = usrAgt.indexOf("msie 8") != -1;
	var isFf = usrAgt.indexOf("firefox") != -1;
	var isFf1 = usrAgt.indexOf("firefox/1.0") != -1;
	
	if(isIe) {
		if(pf!="M") {
			if(isIe7) {
				idMain.style.minHeight = document.documentElement.clientHeight - totalFoot;
				}
			else {
				if(isIe8) {idMain.style.minHeight = document.documentElement.clientHeight - totalFoot;}
				else {idMain.style.height = document.documentElement.clientHeight - totalFoot;}
				}
		}
	}
	else {idMain.style.minHeight = window.innerHeight - totalFoot -0 +"px";}
}
//window.onload=heightSet;
window.onresize=heightSet;


$(function(){
	// #で始まるアンカーをクリックした場合に処理
	$('a[href^=#]').click(function() {
		// スクロールの速度
		var speed = 300;// ミリ秒
		// アンカーの値取得
		var href= $(this).attr("href");
		// 移動先を取得
		var target = $(href == "#" || href == "" ? 'html' : href);
		// 移動先を数値で取得
		var position = target.offset().top;
		// スムーススクロール
		$($.browser.safari ? 'body' : 'html').animate({scrollTop:position}, speed, 'swing');
		return false;
	});

	$('#CONT img').each(function(){
		$(this).removeAttr('width')
		$(this).removeAttr('height');
	});

	$('.headerSmall dt').hover(
		function () {
			$(this).css("cursor","pointer");
		},
		function () {
			$(this).css("cursor","default");
		}
	);

	$('.headerSmall dt').click(function () {
		$('.headerSmall ul').slideToggle(200);
	});

	$('.headerSmall ul li a').click(function () {
		$('.headerSmall ul').hide();
	});

	if ($(window).width() <= 480) {
		$('.addthis_toolbox').addClass('addthis_32x32_style');
	}

	$(window).resize(function(){
		if ($(window).width() <= 480) {
			$('.addthis_toolbox').addClass('addthis_32x32_style');
		} else {
			$('.addthis_toolbox').removeClass('addthis_32x32_style');
		}
	})


});

