/*
----------------------------------------------------------------
	JavaScript for mu-MU WEB Site
----------------------------------------------------------------
	version			1.00
	last update		2011/01/28
	author			Yoshihisa Kato/YAH!-cyberstudio
----------------------------------------------------------------
	This script is prohibited to use outside mu-MU WEB SITE
	http://www.mu-mu.info/
--------------------------------------------------------------------------
*/
var muMU={

	/*header tween*/
	hSlideCount:1,
	hSlideStops:10000,
	hSlideFlags:0,

	headerSlide:function(){
		if($('hi1')){
			for(var i=2;i<=4;i++){
				var tgImage=$("hi"+i);
				CD_core.setAlpha(tgImage,0);
			}
			this.hSlideFlags=setInterval("muMU.headerSlideFade()",this.hSlideStops);
		}
	},

	headerSlideFade:function(){
		var tgImage=$("hi"+this.hSlideCount);
		CD_core.swapDepths(tgImage,this.hSlideCount);

		this.hSlideCount++;
		if(this.hSlideCount==5)this.hSlideCount=1;
		tgImage=$("hi"+this.hSlideCount);

		CD_core.swapDepths(tgImage,5);
		CD_tween.Add("hi"+this.hSlideCount,'null','null',1,'null',18,'de',"complete:muMU.headerSlideInit();");
	},
	
	headerSlideInit:function(){	
		var tgImage=((this.hSlideCount-1)==0)?$("hi4"):$("hi"+(this.hSlideCount-1));
		CD_core.setAlpha(tgImage,0);
	},

	//top Concept
	loadConcept:function(){
		var URL="concept.html";
		if(CD.UA.os=="iOS"){
			CD_popup.Open(URL,"new",'');
			location.href="index.html";
			//return false;
		}else{
			var docs=CD_core.createObject('div','conceptDoc','conceptDoc',$('indexHeaderImage'),0);
			CD_ajax.Send(URL,'conceptDoc','','complete:muMU.extendConceptLayer()');
			return false;
		}
		return false;
	},

	extendConceptLayer:function(){
		CD_extendDiv.Set('conceptDoc',conceptOnly);
	},


	/*layerPopup*/
	loadLayerPopup:function(){
		var anchors=document.getElementsByTagName("a");
		for(var i=0;i<anchors.length;i++){
			if(anchors[i].getAttribute('rel') && anchors[i].getAttribute('rel').indexOf('layerPopup')!=-1){
				if(anchors[i].className=="popupsOnly"){
					anchors[i].onclick=function(){
						muMU.showLayerPopup(this,"popupsOnly");
						return false;
					}
				}else{
					anchors[i].onclick=function(){
						if(CD.UA.os!="iOS"){
							muMU.showLayerPopup(this,"scrollOnly");
							return false;
						}else{
							this.target="_blank";
							return true;
						}
					}
				}
			}
		}
	},

	showLayerPopup:function(obj,contentTypes){
		if($('viewerArea'))$('viewerArea').style.visibility="hidden";
		var URL=obj.getAttribute('href');
		var Shade=CD_core.createObject('div','screenShade','screenShade','',0);
		CD_core.setPosition(Shade,"width",CD_core._documentWidth());
		CD_core.setPosition(Shade,"height",CD_core._documentHeight());
		var PopupT=CD_core.createObject('div','popupT','popupLayer','',0);

		Shade.style.zIndex=10;
		PopupT.style.zIndex=20;
		var CloseA=CD_core.createObject('div','popupClose','popupClose','',1);
		var CloseB=CD_core.createObject('img','closeBut','','',1);
		CloseB.setAttribute('src','/image/popup/close.gif');
		CloseB.setAttribute('alt','');
		var PopupB=CD_core.createObject('div','popupB','popupContent','',1);
		var PopupC=CD_core.createObject('div','popupC','','',1);

		PopupB.appendChild(PopupC);
		CloseA.appendChild(CloseB);
		PopupT.appendChild(CloseA);
		PopupT.appendChild(PopupB);

		//CD_extendDiv.Set('popupC',window[contentTypes]);
		CD_core.setFixedPosition(PopupT,'center',CD_core._scrollY()+(CD_core._windowHeight()-600)/2);

		if(contentTypes=="scrollOnly"){
			CD_ajax.Send(URL,'popupC','','complete:muMU.extendLayerContent()');
		}else{
			CD_ajax.Send(URL,'popupC','','');
		}

		CD_core.addEvent(CloseB,"click",function closeLayer(e){
			muMU.hideLayerPopup();
		});

		CD_core.addEvent(CloseB,"mouseover",function(e){
			$('closeBut').style.cursor="pointer";
		});

		CD_core.addEvent(window,"resize",function resizeMove(e){
			if($('popupT')){
				CD_core.setFixedPosition(PopupT,'center',CD_core._scrollY()+(CD_core._windowHeight()-600)/2);
			}
			if($('screenShade')){
				CD_core.setPosition('screenShade',"width",CD_core._documentWidth());
				CD_core.setPosition('screenShade',"height",CD_core._documentHeight());
			}
		});

		CD_core.addEvent(window,"scroll",function scrollMove(e){
			if($('popupT')){
				CD_core.setFixedPosition(PopupT,'center',CD_core._scrollY()+(CD_core._windowHeight()-600)/2);
			}
			if($('screenShade')){
				CD_core.setPosition('screenShade',"width",CD_core._documentWidth());
				CD_core.setPosition('screenShade',"height",CD_core._documentHeight());
			}
		});

		return false;
	},

	hideLayerPopup:function(){
		if($('viewerArea')){
			$('viewerArea').style.visibility="visible";
			if(CD.UA.asn=="sf"){
				$('panoWindow').contentWindow.location.reload();
			}
		}
		var Parent=$('popupT').parentNode;
		Parent.removeChild($('popupT'));
		Parent.removeChild($('screenShade'));
		CD_core.delEvent(window,"scroll",muMU.showLayerPopup.scrollMove);
		CD_core.delEvent(window,"resize",muMU.showLayerPopup.resizeMove);
	},

	extendLayerContent:function(){
		CD_extendDiv.Set('popupContentMain',scrollOnly);
	},

	/*sound*/

	startSound:function(){
		if(!$("soundObj")){
			var music='/sound/sound.mp3';
			var Sound=CD_core.createObject('div','soundObj','soundObj','',0);
//			if(CD.UA.asn!="sf")Sound.style.display="none";
			Sound.style.position="absolute";
			Sound.style.top="-9999px";
			Sound.style.left="-9999px";

			if(CD.UA.os=="Mac" || CD.UA.os=="iOS"){
				CD_embed.Set('soundObj','QuickTime',7,music,100,100,'AUTOPLAY=true,LOOP=true');
			}else{
				CD_embed.Set('soundObj','WindowsMedia',9,music,100,100,'autostart=true');
			}
			CD_core.setAttribute($('soundMenu'),'class','soundMenuOn');
			CD_core.setCookie('soundSwitch','on',1,'/');
			$('soundMenu').onclick=function(){
				muMU.stopSound();
			}
		}
	},

	stopSound:function(){
		if($("soundObj"))document.body.removeChild($('soundObj'));
		CD_core.setAttribute($('soundMenu'),'class','soundMenuOff');
		CD_core.setCookie('soundSwitch','off',1,'/');
		$('soundMenu').onclick=function(){
			muMU.startSound();
		}
	},

	/*layerSwitch*/
	showLayer:function(objID){
		$(objID).style.display="block";
	},

	hideLayer:function(objID){
		$(objID).style.display="none";
	}


}

CD_core.setEvent(function(){
	if($('indexHeaderImage')){
		var Search=location.search;
		if(CD.UA.os!="iOS"){
			$('indexHeaderImage').innerHTML='';
			var Src="flash/index.swf"+Search;
			CD_embed.Set('indexHeaderImage','Flash',9,Src,1024,618,'')
		}else{
			if(Search){
				muMU.loadConcept();
			}else{
				var code='<img src="image/index/image_01.jpg" width="1024" height="618" id="hi1" class="headerImages" style="-webkit-user-select:none;user-select:none;" /><img src="image/index/image_02.jpg" width="1024" height="618" id="hi2" class="headerImages" style="-webkit-user-select:none;user-select:none;" /><img src="image/index/image_03.jpg" width="1024" height="618" id="hi3" class="headerImages" style="-webkit-user-select:none;user-select:none;" /><img src="image/index/image_04.jpg" width="1024" height="618" id="hi4" class="headerImages" style="-webkit-user-select:none;user-select:none;" />';
				$('indexHeaderImage').innerHTML=code;
			}
		}
	}

	muMU.loadLayerPopup();
	muMU.headerSlide();

	if(CD_core.getCookie('soundSwitch')!='off'){
		muMU.startSound();
	}else{
		muMU.stopSound();
	}
});

