﻿/* ------------------------------------
jQuery 用
------------------------------------ */
$(document).ready(function() {


/* ------------------------------------
クラスを付けた要素の内包img要素をロールオーバー
class="onmouse" : 内のimg要素をロールオーバー
class="noaction" : 付加したimg要素のロールオーバーを中止
clann="now" : 付加したimg要素を常にオン状態
------------------------------------ */
var targetImage = $(".onmouse img").get();
var targetInput = $(".onmouse input").get();
var targetClass = $.merge(targetImage, targetInput);

var add = "_on";
var ac = "_ac";

var overReg = new RegExp("^(.+)(\\.[a-z]+)$");
var outReg = new RegExp("^(.+)" + add + "(\\.[a-z]+)$");

var preload = new Array();

for (var i=0; i<targetClass.length; i++){
	preload[i] = new Image();
	preload[i].src = targetClass[i].getAttribute("src").replace(overReg, "$1" + add + "$2");
	
	if(targetClass[i].className=="now" || targetClass[i].className=="noaction") {
		targetClass[i].src = targetClass[i].getAttribute("src").replace(overReg, "$1" + ac + "$2");
	}else{
		targetClass[i].onmouseover = function() {
			this.src = this.getAttribute("src").replace(overReg, "$1" + add + "$2");
		}
		targetClass[i].onmouseout = function() {
			this.src = this.getAttribute("src").replace(outReg, "$1$2");
		}
	}
}



/* ------------------------------------
大中小！
------------------------------------ */
//下層用
if($("#textSize")[0]) {
	var rels = $.cookie('btn01');
	var relm = $.cookie('btn02');
	var rell = $.cookie('btn03');

	var tars = $("#small a img");
	var tarm = $("#middle a img");
	var tarl = $("#large a img");

	if(rels=="kore"){
		tars[0].src = tars[0].getAttribute("src").replace(overReg, "$1" + add + "$2");
		tars.attr("rel","kore");
		tarl.attr("rel","nonemark");
		tarm.attr("rel","nonemark");
	}else if(rell=="kore"){
		tarl[0].src = tarl[0].getAttribute("src").replace(overReg, "$1" + add + "$2");
		tars.attr("rel","nonemark");
		tarl.attr("rel","kore");
		tarm.attr("rel","nonemark");
	}else{
		tarm[0].src = tarm[0].getAttribute("src").replace(overReg, "$1" + add + "$2");
		tars.attr("rel","nonemark");
		tarl.attr("rel","nonemark");
		tarm.attr("rel","kore");
		relm = "kore";
	}
	
	
	
	tars.hover(
	  function () {
	  		var srel = tars.attr("rel");
	  		if(srel!=="kore") {
		    	this.src = this.getAttribute("src").replace(overReg, "$1" + add + "$2");
				tars.click(function(){
			  		var srel = tars.attr("rel");
						tars.attr("rel","kore");
						tarm.attr("rel","nonemark");
						tarl.attr("rel","nonemark");
						
						tarm[0].src = tarm[0].getAttribute("src").replace(outReg, "$1$2");
						tarl[0].src = tarl[0].getAttribute("src").replace(outReg, "$1$2");
						
						//それぞれのクッキー
						$.cookie('btn01',tars.attr("rel"),{expires:30,path:'/'});
						$.cookie('btn02',tarm.attr("rel"),{expires:30,path:'/'});
						$.cookie('btn03',tarl.attr("rel"),{expires:30,path:'/'});
				});
		    }
	  },
	  function () {
	  		var srel = tars.attr("rel");
	  		if(srel!=="kore") {
		    	this.src = this.getAttribute("src").replace(outReg, "$1$2");
		    }
	  }
	);



	tarm.hover(
	  function () {
	  		var mrel = tarm.attr("rel");
	  		if(mrel!=="kore") {
		    	this.src = this.getAttribute("src").replace(overReg, "$1" + add + "$2");
		    	tarm.click(function(){
						tars.attr("rel","nonemark");
						tarm.attr("rel","kore");
						tarl.attr("rel","nonemark");
						
						tars[0].src = tars[0].getAttribute("src").replace(outReg, "$1$2");
						tarl[0].src = tarl[0].getAttribute("src").replace(outReg, "$1$2");

						//それぞれのクッキー
						$.cookie('btn01',tars.attr("rel"),{expires:30,path:'/'});
						$.cookie('btn02',tarm.attr("rel"),{expires:30,path:'/'});
						$.cookie('btn03',tarl.attr("rel"),{expires:30,path:'/'});
				});
		    }
	  },
	  function () {
	  		var mrel = tarm.attr("rel");
	  		if(mrel!=="kore") {
		    	this.src = this.getAttribute("src").replace(outReg, "$1$2");
		    }
	  }
	);



	tarl.hover(
	  function () {
	  		var lrel = tarl.attr("rel");
	  		if(lrel!=="kore") {
		    	this.src = this.getAttribute("src").replace(overReg, "$1" + add + "$2");
				tarl.click(function(){
			  		var lrel = tarl.attr("rel");
						tars.attr("rel","nonemark");
						tarm.attr("rel","nonemark");
						tarl.attr("rel","kore");
						
						tars[0].src = tars[0].getAttribute("src").replace(outReg, "$1$2");
						tarm[0].src = tarm[0].getAttribute("src").replace(outReg, "$1$2");

						//それぞれのクッキー
						$.cookie('btn01',tars.attr("rel"),{expires:30,path:'/'});
						$.cookie('btn02',tarm.attr("rel"),{expires:30,path:'/'});
						$.cookie('btn03',tarl.attr("rel"),{expires:30,path:'/'});
				});
		    }
	  },
	  function () {
	  		var lrel = tarl.attr("rel");
	  		if(lrel!=="kore") {
		    	this.src = this.getAttribute("src").replace(outReg, "$1$2");
		    }
	  }
	);

}else{
//TOP用
	var rels = $.cookie('btn01');
	var relm = $.cookie('btn02');
	var rell = $.cookie('btn03');

	var tars = $("#ssize");
	var tarm = $("#msize");
	var tarl = $("#lsize");

	if(rels=="kore"){
		tars[0].src = tars[0].getAttribute("src").replace(overReg, "$1" + add + "$2");
		tars.attr("rel","kore");
		tarl.attr("rel","nonemark");
		tarm.attr("rel","nonemark");
	}else if(rell=="kore"){
		tarl[0].src = tarl[0].getAttribute("src").replace(overReg, "$1" + add + "$2");
		tars.attr("rel","nonemark");
		tarl.attr("rel","kore");
		tarm.attr("rel","nonemark");
	}else{
		tarm[0].src = tarm[0].getAttribute("src").replace(overReg, "$1" + add + "$2");
		tars.attr("rel","nonemark");
		tarl.attr("rel","nonemark");
		tarm.attr("rel","kore");
		relm = "kore";
	}
	
	
	
	tars.hover(
	  function () {
	  		var srel = tars.attr("rel");
	  		if(srel!=="kore") {
		    	this.src = this.getAttribute("src").replace(overReg, "$1" + add + "$2");
				tars.click(function(){
			  		var srel = tars.attr("rel");
						tars.attr("rel","kore");
						tarm.attr("rel","nonemark");
						tarl.attr("rel","nonemark");
						
						tarm[0].src = tarm[0].getAttribute("src").replace(outReg, "$1$2");
						tarl[0].src = tarl[0].getAttribute("src").replace(outReg, "$1$2");
						
						//それぞれのクッキー
						$.cookie('btn01',tars.attr("rel"),{expires:30,path:'/'});
						$.cookie('btn02',tarm.attr("rel"),{expires:30,path:'/'});
						$.cookie('btn03',tarl.attr("rel"),{expires:30,path:'/'});
				});
		    }
	  },
	  function () {
	  		var srel = tars.attr("rel");
	  		if(srel!=="kore") {
		    	this.src = this.getAttribute("src").replace(outReg, "$1$2");
		    }
	  }
	);



	tarm.hover(
	  function () {
	  		var mrel = tarm.attr("rel");
	  		if(mrel!=="kore") {
		    	this.src = this.getAttribute("src").replace(overReg, "$1" + add + "$2");
		    	tarm.click(function(){
						tars.attr("rel","nonemark");
						tarm.attr("rel","kore");
						tarl.attr("rel","nonemark");
						
						tars[0].src = tars[0].getAttribute("src").replace(outReg, "$1$2");
						tarl[0].src = tarl[0].getAttribute("src").replace(outReg, "$1$2");

						//それぞれのクッキー
						$.cookie('btn01',tars.attr("rel"),{expires:30,path:'/'});
						$.cookie('btn02',tarm.attr("rel"),{expires:30,path:'/'});
						$.cookie('btn03',tarl.attr("rel"),{expires:30,path:'/'});
				});
		    }
	  },
	  function () {
	  		var mrel = tarm.attr("rel");
	  		if(mrel!=="kore") {
		    	this.src = this.getAttribute("src").replace(outReg, "$1$2");
		    }
	  }
	);



	tarl.hover(
	  function () {
	  		var lrel = tarl.attr("rel");
	  		if(lrel!=="kore") {
		    	this.src = this.getAttribute("src").replace(overReg, "$1" + add + "$2");
				tarl.click(function(){
			  		var lrel = tarl.attr("rel");
						tars.attr("rel","nonemark");
						tarm.attr("rel","nonemark");
						tarl.attr("rel","kore");
						
						tars[0].src = tars[0].getAttribute("src").replace(outReg, "$1$2");
						tarm[0].src = tarm[0].getAttribute("src").replace(outReg, "$1$2");

						//それぞれのクッキー
						$.cookie('btn01',tars.attr("rel"),{expires:30,path:'/'});
						$.cookie('btn02',tarm.attr("rel"),{expires:30,path:'/'});
						$.cookie('btn03',tarl.attr("rel"),{expires:30,path:'/'});
				});
		    }
	  },
	  function () {
	  		var lrel = tarl.attr("rel");
	  		if(lrel!=="kore") {
		    	this.src = this.getAttribute("src").replace(outReg, "$1$2");
		    }
	  }
	);

}



/* ------------------------------------
読み取り専用のテキストボックスの値をフォーカス時にセレクト
------------------------------------ */
$("[readonly]").focus(function(){this.select();});


/* ------------------------------------
別窓リンク
rel="external" を付加した a要素は別窓
------------------------------------ */
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName("a");
for (var i=0; i<anchors.length; i++) {
	var anchor = anchors[i];
	if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
		anchor.target = "_blank";
	}
}

});

/* ------------------------------------
関数
------------------------------------ */
/* ------------------------------------
ポップアップウィンドウ
 onclick="openWindow(this.href,800,600,'yes','yes','yes','yes','yes');return false;"
------------------------------------ */
function openWindow(openurl,a,b,c,d,e,f,g) {
	var aa = a || "850";
	var bb = b || "700";
	var cc = c || "yes";
	var dd = d || "yes";
	var ee = e || "yes";
	var ff = f || "yes";
	var gg = g || "yes";
    var w = window.open(
    		openurl,
    		'mywindow',
    		'width=' + aa +
    		',height=' + bb +
    		',location=' + cc +
    		',menubar=' + dd +
    		',toolbar=' + ee +
    		',scrollbars=' + ff +
    		',resizable=' + gg
    		);
    w.focus();
}
/* ------------------------------------
テキストエリアの最大文字数
------------------------------------ */
function limitchk(target,maxlength) {
    if ( target.value.length > maxlength ) {
        alert("最大全角"+ maxlength + "字以内で入力してください");
        target.value = target.value.substr(0,maxlength);
    }
    target.focus();
}

