// JavaScript Document

_cflag = false;
_bflag = false;
_pflag = false;
_cswitch = false;
_bswitch = false;
_pswitch = false;
_addedUrl = false;

var indexFlag = 0;

$(function(){

	if(location.href.match("index.html")||!(location.href.match("html"))){indexFlag = 1;
	}else{readParam();}
	
	if(indexFlag==1)initializeIndex();	//index.html only
	if(indexFlag==0)initialize();

	window.onload = function(){
		if(indexFlag==1)startFadeIn();	//index.html only 
		
		if(indexFlag==1){setTimeout("buttonFade()",2400);
		}else{buttonFade();} //delay index.html only
	
		if(indexFlag==1)setInterval( "slideSwitch()",8000 ); //index.html only
		buttonFunction();
	}
	
});

function renewUrl(){
	var num = _cflag+_bflag*2+_pflag*4;
	var idArray = new Array("campaign", "aw09", "style_pop", "ethos_pop", "handmade_pop","house_pop","ready_pop","furniture_pop","the_company");
	for(var i=0;i<idArray.length;i++){
		renewUrlOne(idArray[i],num);
	}
	_addedUrl=true;
}
function renewUrlOne(id ,num){
	id = "#" + id + " a"
	var url = $(id).attr("href");
	if(_addedUrl)url = url.split("?")[0];
	$(id).attr({href: url +"?"+num})

}

function initialize(){
	
	$("#the_brand img").css({top: "242px"});
		$("#style_pop img").css({top: "270px"});
		$("#ethos_pop img").css({top: "297px"});
	$("#product_work img").css({top: "270px"});
		$("#handmade_pop img").css({top: "301px"});
		$("#house_pop img").css({top: "328px"});
		$("#ready_pop img").css({top: "354px"});
		$("#furniture_pop img").css({top: "380px"});
	$("#the_company img").css({top: "296px"});
	$("#online_store img").css({top: "327px"});
	$("#contact img").css({top: "354px"});
	
	
	
	if(_cflag){
		$("#the_brand img").css({top: "271px"});
		$("#style_pop img").css({top: "299px"});
		$("#ethos_pop img").css({top: "326px"});
	 
	}else{
		$("#aw09 img").css({left: "108px"});
		$(".d img").css("opacity","0");
	}
	if(!_bflag){
		$("#style_pop img").css({left: "126px"});
		$("#ethos_pop img").css({left: "124px"});
		$(".e img").css("opacity","0");
	}
	if(!_pflag){
		$("#handmade_pop img").css({left: "54px"});
		$("#house_pop img").css({left: "63px"});
		$("#ready_pop img").css({left: "77px"});
		$("#furniture_pop img").css({left: "60px"});
		$(".f img").css("opacity","0");
	}
	if((!_cflag)&&(!_bflag)){
		$("#product_work img").css({top: "270px"});
		$("#handmade_pop img").css({top: "301px"});
		$("#house_pop img").css({top: "328px"});
		$("#ready_pop img").css({top: "354px"});
		$("#furniture_pop img").css({top: "380px"});
	}
	if((_cflag)&&(!_bflag)){
		$("#product_work img").css({top: "299px"});
		$("#handmade_pop img").css({top: "330px"});
		$("#house_pop img").css({top: "357px"});
		$("#ready_pop img").css({top: "383px"});
		$("#furniture_pop img").css({top: "409px"});
	}
	if((!_cflag)&&(_bflag)){
		$("#product_work img").css({top: "328px"});
		$("#handmade_pop img").css({top: "359px"});
		$("#house_pop img").css({top: "386px"});
		$("#ready_pop img").css({top: "412px"});
		$("#furniture_pop img").css({top: "438px"});
	}
	if((_cflag)&&(_bflag)){
		$("#product_work img").css({top: "357px"});
		$("#handmade_pop img").css({top: "388px"});
		$("#house_pop img").css({top: "415px"});
		$("#ready_pop img").css({top: "441px"});
		$("#furniture_pop img").css({top: "467px"});
	}
	if((!_cflag)&&(!_bflag)&&(!_pflag)){
		$("#the_company img").css({top: "296px"});
		$("#online_store img").css({top: "327px"});
		$("#contact img").css({top: "354px"});
	}
	if((_cflag)&&(!_bflag)&&(!_pflag)){
		$("#the_company img").css({top: "325px"});
		$("#online_store img").css({top: "356px"});
		$("#contact img").css({top: "383px"});
	}
	if((!_cflag)&&(_bflag)&&(!_pflag)){
		$("#the_company img").css({top: "354px"});
		$("#online_store img").css({top: "385px"});
		$("#contact img").css({top: "412px"});
	}
	if((!_cflag)&&(!_bflag)&&(_pflag)){
		$("#the_company img").css({top: "410px"});
		$("#online_store img").css({top: "441px"});
		$("#contact img").css({top: "468px"});
	}
	if((_cflag)&&(_bflag)&&(!_pflag)){
		$("#the_company img").css({top: "383px"});
		$("#online_store img").css({top: "414px"});
		$("#contact img").css({top: "441px"});
	}
	if((_cflag)&&(!_bflag)&&(_pflag)){
		$("#the_company img").css({top: "439px"});
		$("#online_store img").css({top: "470px"});
		$("#contact img").css({top: "497px"});
	}
	if((!_cflag)&&(_bflag)&&(_pflag)){
		$("#the_company img").css({top: "468px"});
		$("#online_store img").css({top: "499px"});
		$("#contact img").css({top: "526px"});
	}
	if((_cflag)&&(_bflag)&&(_pflag)){
		$("#the_company img").css({top: "497px"});
		$("#online_store img").css({top: "528px"});
		$("#contact img").css({top: "555px"});
	}
	if(!_cflag)$(".d").hide();
	if(!_bflag)$(".e").hide();
	if(!_pflag)$(".f").hide();
}
function buttonFunction(){
	$("#collection img").click(function(){
		if(_cswitch==false){
			_cswitch=true;
			if(_cflag == false){
				showCollection();
				_cflag = true;
			}else{
				hideCollection();
				_cflag = false;
			}
			renewUrl();
		setTimeout("_cswitch=false", 2000);
		}
	});
	$("#the_brand img").click(function(){
		if(_bswitch==false){
			_bswitch=true;
			if(_bflag == false){
				showBrand();
				_bflag = true;
			}else{
				hideBrand();
				_bflag = false;
			}
			renewUrl();
		setTimeout("_bswitch=false", 2000);
		}
	});
	$("#product_work img").click(function(){
		if(_pswitch==false){
			_pswitch=true;
			if(_pflag == false){
				showProduct();
				_pflag = true;
			}else{
				hideProduct();
				_pflag = false;
			}
			renewUrl();
		setTimeout("_pswitch=false", 2000);
		}
	});
}
function readParam(){
	
	var openFlag = location.href.split("?").pop();
	openFlag = Number(openFlag);
	//alert(openFlag);
	if(openFlag==undefined){return;}
	if(openFlag%2==1){
		_cflag=true;	
	}
	if((openFlag>>1)%2==1){
		_bflag=true;
	}
	if((openFlag>>2)%2==1){
		_pflag=true;
	}
	renewUrl();
}
function startFadeIn(){
	$("#menu").animate({opacity: 1.0}, 1500);
	//$("#stateoftheart").animate({left: '+=25px', opacity: 1.0}, 1000);
	setTimeout("$('#stateoftheart').animate({left: '+=25px', opacity: 1.0}, 1500);",1000);
	setTimeout("$('#campaign img').animate({left: '+=25px', opacity: 1.0}, 1000);",1800);
	setTimeout("$('#collection img').animate({left: '+=25px', opacity: 1.0}, 1000);",1900);
	setTimeout("$('#the_brand img').animate({left: '+=25px', opacity: 1.0}, 1000);",2000);
	setTimeout("$('#product_work img').animate({left: '+=25px', opacity: 1.0}, 1000);",2100);
	setTimeout("$('#the_company img').animate({left: '+=25px', opacity: 1.0}, 1000);",2200);
	setTimeout("$('#online_store img').animate({left: '+=25px', opacity: 1.0}, 1000);",2300);
	setTimeout("$('#contact img').animate({left: '+=25px', opacity: 1.0}, 1000);",2400);
	setTimeout("$('#collection_1').animate({opacity: 1.0}, 1500);",3500);
	setTimeout("$('#rightbar').animate({opacity: 1.0}, 1500);",3500);
	setTimeout("$('#slideshow img').animate({opacity: 1.0}, 500);",4500);
	setTimeout("$('#black').animate({opacity: 0.5}, 500);",5000);//for promotion
	setTimeout("$('#under').animate({opacity: 1.0}, 500);",5500);//for promotion
}

function showCollection(){
		$('.a img').animate({top: '+=29px'}, 1000);
		$(".d").show();
		setTimeout("$('.d img').animate({left: '+=25px', opacity: 1.0}, 1000);",1000);
}

function hideCollection(){
		setTimeout("$('.a img').animate({top: '-=29px'}, 1000);",1000);
		$('.d img').animate({left: '-=25px', opacity: 0.0}, 1000);
		setTimeout("$('.d').hide();",1000);
}

function showBrand(){
		$('.b img').animate({top: '+=58px'}, 1000);
		$(".e").show();
		setTimeout("$('.e img').animate({left: '+=25px', opacity: 1.0}, 1000);",1000);
}

function hideBrand(){
		setTimeout("$('.b img').animate({top: '-=58px'}, 1000);",1000);
		$('.e img').animate({left: '-=25px', opacity: 0.0}, 1000);
		setTimeout("$('.e').hide();",1000);
}
function showProduct(){
		$('.c img').animate({top: '+=114px'}, 1000);
		$(".f").show();
		setTimeout("$('.f img').animate({left: '+=25px', opacity: 1.0}, 1000);",1000);
}
function hideProduct(){
		setTimeout("$('.c img').animate({top: '-=114px'}, 1000);",1000);
		$('.f img').animate({left: '-=25px', opacity: 0.0}, 1000);
		setTimeout("$('.f').hide();",1000);
}
function buttonFade(){
	$("#menu img:not(#sub_collection img)").hover(function(){
       $(this).fadeTo("normal", 0.6); // マウスオーバーで透明度を60%にする
    },function(){
       $(this).fadeTo("normal", 1.0); // マウスアウトで透明度を100%に戻す
    });
}
function slideSwitch() {
    var $active = $('#slideshow img.active');

    if ( $active.length == 0 ) $active = $('#slideshow img:last');

    var $next =  $active.next().length ? $active.next()
        : $('#slideshow img:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1500, function() {
            $active.removeClass('active last-active');
    });
}
function initializeIndex(){
	$('#menu').css("opacity","0");
	$('#black').css("opacity","0");//for promotion
	$('#under').css("opacity","0");//for promotion
	$('img').css("opacity","0");
	$('#collectionFlow img').css("opacity","1");
	$("#aw09").hide();
	$("#style_pop").hide();
	$("#ethos_pop").hide();
	$("#handmade_pop").hide();
	$("#house_pop").hide();
	$("#ready_pop").hide();
	$("#furniture_pop").hide();
	
	//$("#menu").css({left: "-25px"});
	$("#stateoftheart").css({left: "5px"});
	$("#campaign img").css({left: "104px"});
	$("#collection img").css({left: "104px"});
		$("#aw09 img").css({left: "108px"});
	$("#the_brand img").css({left: "99px", top: "242px"});
		$("#style_pop img").css({left: "126px", top: "270px"});
		$("#ethos_pop img").css({left: "124px", top: "297px"});
	$("#product_work img").css({left: "77px", top: "270px"});
		$("#handmade_pop img").css({left: "54px", top: "301px"});
		$("#house_pop img").css({left: "63px", top: "328px"});
		$("#ready_pop img").css({left: "77px", top: "354px"});
		$("#furniture_pop img").css({left: "60px", top: "380px"});
	$("#the_company img").css({left: "86px", top: "296px"});
	$("#online_store img").css({left: "90px", top: "327px"});
	$("#contact img").css({left: "116px", top: "354px"});
	
	
}