/* Go Top */

function backToTop() {
    var x1 = x2 = x3 = 0;
    var y1 = y2 = y3 = 0;

    if (document.documentElement) {
        x1 = document.documentElement.scrollLeft || 0;
        y1 = document.documentElement.scrollTop || 0;
    }

    if (document.body) {
        x2 = document.body.scrollLeft || 0;
        y2 = document.body.scrollTop || 0;
    }

    x3 = window.scrollX || 0;
    y3 = window.scrollY || 0;

    var x = Math.max(x1, Math.max(x2, x3));
    var y = Math.max(y1, Math.max(y2, y3));

    window.scrollTo(Math.floor(x / 1.3), Math.floor(y / 1.3));

    if (x > 0 || y > 0) {
        window.setTimeout("backToTop()", 25);
    }
}



/* ロールオーバー */

(function(){
   // ページ遷移時に透明にする用
   var rolloverImages = [];
   
   function setRollOver2(){
     if(!document.images){return;}
	 var tags = ["img","input"];
     var imgs = document.images;
     var insert = [];
     for(var i=0,len=imgs.length; i<len; i++){
       var splitname = imgs[i].src.split('_ot.');
       if(splitname[1]){
         var rolloverImg = document.createElement('img','input');
         rolloverImages.push(rolloverImg);
         rolloverImg.src = splitname[0]+'_ov.'+splitname[1];
         var alpha = 0;
         rolloverImg.currentAlpha = alpha;
         rolloverImg.style.opacity = alpha/100;
         rolloverImg.style.filter = 'alpha(opacity='+alpha+')';
         rolloverImg.style.position = 'absolute';

         //ロールオーバー・アウト処理それぞれを設定
         addEvent(rolloverImg,'mouseover',function(){setFader(this,100);});
         addEvent(rolloverImg,'mouseout',function(){setFader(this,0);});

         // 後で追加するために追加場所と共に保存しておく
         // この時点で追加するとdocument.imagesが書き換わって不都合
         insert[insert.length] = {position:imgs[i],element:rolloverImg};
       }
     }
     // ↑で作ったロールオーバー画像を追加
     for(i=0,len=insert.length; i<len ;i++){
       var parent = insert[i].position.parentNode;
       parent.insertBefore(insert[i].element,insert[i].position);
     }

     // ページ遷移時にはフェード状態をクリアする
     addEvent(window,'beforeunload', clearRollover);
   }

   // 指定要素を指定透明度にするためのフェードアニメを設定する関数
   function setFader(targetObj,targetAlpha){
     targetObj.targetAlpha = targetAlpha;
     if(targetObj.currentAlpha==undefined){
       targetObj.currentAlpha = 100;
     }
     if(targetObj.currentAlpha==targetObj.targetAlpha){
       return;
     }
     if(!targetObj.fading){
       if(!targetObj.fader){
         targetObj.fader = fader;
       }
       targetObj.fading = true;
       targetObj.fader();
     }
   }

   // アルファ値をターゲット値に近づける関数
   // ターゲット値になったら終了
   function fader(){
     this.currentAlpha += (this.targetAlpha - this.currentAlpha)*0.2;
     if(Math.abs(this.currentAlpha-this.targetAlpha)<1){
       this.currentAlpha = this.targetAlpha;
       this.fading = false;
     }
     var alpha = parseInt(this.currentAlpha);
     this.style.opacity = alpha/100;
     this.style.filter = 'alpha(opacity='+alpha+')';
     if(this.fading){
       var scope = this;
       setTimeout(function(){fader.apply(scope)},30);
     }
   }
   
   // すべてのロールオーバー画像をを透明にする関数（遷移時用）
   function clearRollover(){
     for(var i=0,len=rolloverImages.length; i<len; i++){
       var image = rolloverImages[i];
       image.style.opacity = 0;
       image.style.filter = 'alpha(opacity=0)';
     }
   }

   // イベントを追加する関数
   function addEvent(eventTarget, eventName, func){
     if(eventTarget.addEventListener){
       // モダンブラウザ
       eventTarget.addEventListener(eventName, func, false);
     }else if(window.attachEvent){
       // IE
       eventTarget.attachEvent('on'+eventName, function(){func.apply(eventTarget);});
     }
   }
   addEvent(window,'load',setRollOver2);
 })();
 
 
 /* ロールオーバーinput用 */
 $(function () { 
        $(':image').each(function () { 
                var ofSrc = $(this).attr('src'); 
                var ovSrc = ofSrc.replace('_ot.', '_ov.'); 
                $(this).hover(function () { 
                        $(this).attr('src', ovSrc); 
                }, function () { 
                        $(this).attr('src', ofSrc); 
                }); 
        }); 
});

 

/* タブ */
function tabChange(){
var tabobj = document.getElementsByTagName('a');
for(var i=0; i < tabobj.length; i++){
if(tabobj[i].className == 'tab_A'){
	tabobj[i].onclick = function(){
	tab_h('women','url(images/women_select_ot.jpg)');
	tab_b('tab1');
	saveCookie('women','women_select_ot','tab1');
	return false;
	}
}else if(tabobj[i].className == 'tab_B'){
	tabobj[i].onclick = function(){
	tab_h('men','url(images/men_select_ot.jpg)');
	tab_b('tab2');
	saveCookie('men','men_select_ot','tab2');
	return false;
	}
}
}
}
tab_head = getCookie("tab_head");
if(tab_head == ""){
	tab_head = "women";
}else{
	document.cookie = tab_head;
}
tab_head_img = getCookie("tab_head_img");
if(tab_head_img == ""){
	tab_head_img = "women_select_ot";
}else{
	document.cookie = tab_head_img;
}
tab_body = getCookie("tab_body");
if(tab_body == ""){
	tab_body = "tab1";
}else{
	document.cookie = tab_body;
}
function saveCookie(tab_h,tab_i,tab_b){
	setCookie("tab_head",tab_h);
	setCookie("tab_head_img",tab_i);
	setCookie("tab_body",tab_b);
	document.cookie = tab_h;
	document.cookie = tab_i;
	document.cookie = tab_b;
}
function setCookie(key,val){
	store = key+"="+escape(val)+";";
	store += "expires=Fri, 31-Dec-2030 23:59:59;";
	store += "path = /";
	document.cookie = store;
}
function getCookie(key){
	store = document.cookie+";";
	hangar = store.indexOf(key,0);
	if(hangar != -1){
		store = store.substring(hangar,store.length);
		start = store.indexOf("=",0);
		end = store.indexOf(";",start);
		return(unescape(store.substring(start+1,end)));
		}
	return("");
}
function addEvent(init) {
	if (window.addEventListener) {
		window.addEventListener("load",init, false);
	} else if (window.attachEvent) {
		window.attachEvent("onload",init);
	}
}
var tab_head_img_path = 'url(images/'+tab_head_img+'.jpg)';
addEvent(function(){ tabChange(); tab_h(tab_head,tab_head_img_path); tab_b(tab_body); });
function tab_h(tabh,tabi) {
	document.getElementById('women').style.backgroundImage = 'url(images/women_unselect_ot.jpg)';
	document.getElementById('men').style.backgroundImage = 'url(images/men_unselect_ot.jpg)';
if(tabh) {
	document.getElementById(tabh).style.backgroundImage = tabi;
	}
}
function tab_b(tabb) {
	document.getElementById('tab1').style.display = 'none';
	document.getElementById('tab2').style.display = 'none';
if(tabb) {
	document.getElementById(tabb).style.display = 'block';
	}
}
