﻿// JavaScript Document

var urlNews = "xml/information.xml";			// news用 
var urlNewAll = "xml/newarrival_pc.xml";		// 新着用 
var urlStyle = "xml/styling.xml";			// 新着Styling用
var urlIcon = "xml/newicon.xml"				// バナー用

var fadeTime = 1500;	//ミリ秒
var delayTime = 6000;	//ミリ秒

var _flg = false;		// カーソルONフラグ
var _feadFlg = false;	// フェード中フラグ

$(document).ready(
	function (){
		
		bodyFlg = $("body").attr('id');
		
		switch(bodyFlg){
		case "top":
			topInit();
			break;
		}
		
	initRollOverFead("a img");
});

initRollOverImages = function(elm){ // rollover共通処理  _on.拡張子
    $(elm).mouseover(function(){
        $(this).attr("src",$(this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_on$2"))
    }).mouseout(function(){
        $(this).attr("src",$(this).attr("src").replace(/^(.+)_on(\.[a-z]+)$/, "$1$2"));
    })
} 
initRollOverFead = function(elm2){ // rollover共通フェード処理 
	if(_feadFlg == false ){
		$(elm2).mouseover(function(){
			$(this).fadeTo("fast", 0.7);
			_flg = true;
		}).mouseout(function(){
			$(this).fadeTo("fast", 1);
			_flg = false;
		})
	}
} 
function gotoTop(){
	$("html, body").animate({scrollTop: "0px"}, 300);
}


//----------- ページ別関数 ------------//



/*--------------- TOP ------------------*/

function topInit()
{
topAnimationInit();
	
	$.ajax({
	type 	 : "GET",
	url  	 : urlNews,
	dataType : "xml",
    success  : function(data){
		
			$("item",data).each(function(i){
			if(i >= 4) return;
						
			$(".upBox ul li")[i].innerHTML = this.getAttribute("date");
			$(".upBox ul li")[i].innerHTML += '　　<a href="news/#news'+i+'">'+ $(this).find("title").text()+'</a>';
			})
		}
	});	
	
	$.ajax({
	type 	 : "GET",
	url  	 : urlIcon,
	dataType : "xml",
    success  : function(data){
		
			$("newicon",data).each(function(i){
			var path = $(this).find("onlineImg").text();
			
			src = $(".bnr_online .bg");
			$(src).html('<img src="'+path+'" width="280" height="110">');
			})
		}
	});	
	
	$.ajax({
	type 	 : "GET",
	url  	 : urlStyle,		// STYLING
	dataType : "xml",
    success  : function(data){
		
			$("item",data).each(function(i){
			if(i >= 2) return;
			
			if(i==0){
				$(".stylingBox .date").html('LAST UPDATE '+this.getAttribute("date"));
			}
			
			var srcStyle = this.getAttribute("thum_top");
			ii= i+1;
			$($(".stylingBox .imgBox .thumb")[i]).html('<img class="stylingImg'+ii+'" src="'+srcStyle+'" width="137" height="190" />');
			})
		}
	});
	
	$.ajax({
	type 	 : "GET",
	url  	 : urlNewAll,		// PICKUP ITEM
	dataType : "xml",
    success  : function(data){
		
			$("item",data).each(function(m){
			if(m >= 2) return;
			
			if(m==0){
				$YY = this.getAttribute("date").slice(0, 4);
				$MM = this.getAttribute("date").slice(4, 6);
				$DD = this.getAttribute("date").slice(6, 8);				
				$(".pickupBox .date").html('LAST UPDATE '+$YY+'.'+$MM+'.'+$DD);
			}
			
			var srcPickup = this.getAttribute("image_top");					// 対象部分新規src
			mm= m+1;
			$($(".pickupBox .imgBox .thumb")[m]).html('<img class="pickupImg'+mm+'" src="'+srcPickup+'" width="137" height="190" />');			
			})
		}
	});
	
	initRollOverImages(".bnrBox p a img");
	initRollOverFead(".rolloverAlpha img");
	initRollOverFeadTOP1(".waku .stylingImg1");
	initRollOverFeadTOP2(".waku .stylingImg2");
	initRollOverFeadTOP3(".waku .pickupImg1");
	initRollOverFeadTOP4(".waku .pickupImg2");
}

initRollOverFeadTOP1 = function(waku1){ // rollover共通フェード処理
    $(waku1).mouseover(function(){
        $(".thumb .stylingImg1").fadeTo("fast", 0.7);
    }).mouseout(function(){
        $(".thumb .stylingImg1").fadeTo("fast", 1);
    })
} 
initRollOverFeadTOP2 = function(waku2){ // rollover共通フェード処理
    $(waku2).mouseover(function(){
        $(".thumb .stylingImg2").fadeTo("fast", 0.7);
    }).mouseout(function(){
        $(".thumb .stylingImg2").fadeTo("fast", 1);
    })
} 
initRollOverFeadTOP3 = function(waku3){ // rollover共通フェード処理
    $(waku3).mouseover(function(){
        $(".thumb .pickupImg1").fadeTo("fast", 0.7);
    }).mouseout(function(){
        $(".thumb .pickupImg1").fadeTo("fast", 1);
    })
} 
initRollOverFeadTOP4 = function(waku4){ // rollover共通フェード処理
    $(waku4).mouseover(function(){
        $(".thumb .pickupImg2").fadeTo("fast", 0.7);
    }).mouseout(function(){
        $(".thumb .pickupImg2").fadeTo("fast", 1);
    })
} 


function topAnimationInit()
{	
	var _max;
	var _id = 1;
	
	_max = $(".mainVis img").length;
	for(var i=1; i<_max; i++){
		$($(".mainVis img")[i]).hide();
	}
	
	fadeTimer = setInterval(function loopFead()
	{
		if(_flg == false){
			_feadFlg = true;
			if(_id==0){
				preID = _max-1;
			}else if(_id==_max){
				_id = 0;
				preID = _max-1;
			}else{
				preID = _id-1;
			}
			$($(".mainVis img")[preID]).fadeOut(fadeTime);
			$($(".mainVis img")[_id]).fadeIn(fadeTime,function(){_feadFlg = false;});
			
			_id++;	
		}
	}, delayTime);
}


