// リンク設定
function linkTo() {
var links = document.getElementsByTagName("a");
var linksLen = links.length;
//var lbc = ["","","","","",""];
for (var i=0; i < linksLen; i++) {
	if (links[i].className.match("launched")) {
		links[i].onclick = function() {
		window.open(this.href,'_blank');
		return false;
		}
//	} else if (links[i].className.match("topop")) {
//		links[i].onclick = function() {
//		var target = lbc[2]+lbc[0]+lbc[3]+lbc[1]+lbc[5];
//		opw(target,'popup',420,540,20,20);
//		return false;
//		}
	}
};
}

/*
	Standards Compliant Rollover Script
	Author : Daniel Nolan
	http://www.bleedingego.co.uk/webdev.php
	変数名など変更した箇所有り
	ロールオーバー画像のファイル名をfilename_over.[jpg,gif]拡張子とする
*/

//画像置き換え
function initRollovers() {
	if (!document.getElementById) return;
	var chimgLoad = new Array();
	var defSrc;
	var chImages = document.getElementsByTagName('img');

	for (var i = 0; i < chImages.length; i++) {
		if (chImages[i].className == 'imgover') {
			var src = chImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'),src.length);
			var hsrc = src.replace(ftype, '_over'+ftype);
			
			chImages[i].setAttribute('hsrc', hsrc);
			
			chimgLoad[i] = new Image();
			chimgLoad[i].src = hsrc;
			
			chImages[i].onmouseover = function() {
				defSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}
			
			chImages[i].onmouseout = function() {
				if (!defSrc) defSrc = this.getAttribute('src').replace('_over'+ftype,ftype);
				this.setAttribute('src',defSrc);
			}
		}
	}
}

//Google Maps Footer
function initialize() {
	var okuhiraPos = new google.maps.LatLng(34.559759, 135.549386);
	var mapOptions = {
		zoom: 17,
		center: okuhiraPos,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	var okuhiraMapFooter = new google.maps.Map(document.getElementById("mapFooter"), mapOptions);

	var marker = new google.maps.Marker({
		position: okuhiraPos,
		title: "奥平工業"
	});
	marker.setMap(okuhiraMapFooter);
}

//window.onload = function () {}

$(function(){
initRollovers();
linkTo();
initialize();

//文字サイズ設定
	$("#okuhiraContent").css("font-size",$.cookie('fsize'));
	mfont($.cookie('fsize'));
	$("#fsmall").click(function(){mfont("85%");});
	$("#fmiddle").click(function(){mfont("100%");});
	$("#fbig").click(function(){mfont("120%");});
	$("#fsmall,#fmiddle,#fbig").hover(
		function(){
			$(this).css("cursor","pointer");
		},
		function(){
			$(this).css("cursor","default");
		}
	);

// ページ先頭へのスムーススクロール設定
	$('a[href=#top]').click(function(){
		$('html,body').animate({ scrollTop: 0 }, 1200);
		return false;
	});

	$('a[href^=#cad-],a[href^=#actual-],a[href^=#about-]').click(function() {
//		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')&& location.hostname == this.hostname) {
		var $target = $(this.hash);
		$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			if ($target.length) {
			var targetOffset = $target.offset().top;
			$('html,body').animate({scrollTop: targetOffset}, 1000);
			return false;
			}
//		}
	});

//コピーライト西暦書き換え
	var dObj = new Date();
	var d_year = dObj.getFullYear();
	$("#okuhiraCopyright").html("Copyright &copy; "+d_year+" OKUHIRA Co.,Ltd. All Rights Reserved.");

});

//文字サイズ変更
function mfont(size){
	if (size == "85%"){
		$("#fsmall").addClass("current");
		$("#fmiddle,#fbig").removeClass("current");
	}else if(size == "100%"){
		$("#fmiddle").addClass("current");
		$("#fsmall,#fbig").removeClass("current");
	}else if(size == "120%"){
		$("#fbig").addClass("current");
		$("#fsmall,#fmiddle").removeClass("current");
	}else if(size == null){
		$("#fmiddle").addClass("current");
		$("#fsmall,#fbig").removeClass("current");
		size = "100%";
	}

	$("#okuhiraContent").css("font-size",size);
	$.cookie("fsize",size,{expires:90,path:'/'});
}

/*function udfont(size){
	var udsize = ($.cookie('fsize') == null)? 100+size+"%" : parseInt($.cookie('fsize'))+size+"%";
	$("#okuhiraContent").css("font-size",udsize);
	$.cookie("fsize",udsize,{expires:90,path:'/'});
}*/

//ポップアップウィンドウ
function opw(theURL,winName,winW,winH,topPos,leftPos) {
var ua = navigator.userAgent;
if(ua.indexOf('Safari') != -1) {
	//winH = winH + 10;
	topPos = topPos + 20;
} else {
	topPos = topPos;
}
features = "toolbar=no,menubar=no,status=yes,scrollbars=yes,resizable=yes,width="+winW+",height="+winH+",top="+topPos+",left="+leftPos;
Middle = window.open(theURL,winName,features);
Middle.focus();
}

//ポップアップウィンドウ 各種設定
function opwfea(theURL,winName,features) {
window.open(theURL,winName,features);
}

