//プログレスバーの速度（秒）
time=8;
//ボックスの親ボックスのid
vision="#top_vision";
//ボックスの幅
bw=972;
//infoBoxの開閉フラグ
doorFlg=true;
//画像パス
path="user_data/packages/default/img/top_vision/"
//ユーザーエージェント
ua=$.browser;
ie=ua.msie;


//動画の呼び出し
function getMovie(mp4,img,id,flg){
	if(flg){
            var bv_swfObj = new SWFObject(path+"player.swf", "bemoove", "320", "270", "9.0.110");
            bv_swfObj.addParam("allowscriptaccess", "always");
            bv_swfObj.addParam("allowfullscreen", "true");
            bv_swfObj.addParam("wmode", "transparent");
            bv_swfObj.addParam("menu", "false");
            bv_swfObj.addVariable("streamer", "rtmpt://bemoove.fcod.llnwd.net/a3184/o29/tc-ent");
            bv_swfObj.addVariable("file", mp4);
            bv_swfObj.addVariable("image", path+"movie/"+img);
            bv_swfObj.addVariable("type", "mp4");
            bv_swfObj.addVariable("autostart", "false");
            bv_swfObj.write(id);
	}else{
		document.write('<img src='+path+'"comingsoon.jpg" alt="Coming Soon">');
	}
}


$(document).ready(function(){
	c=new Counter();
	$("ul#top_vision").css("width",bw*c.total);
	$('p.counter').text(c.now+"/"+c.total);
	$('.next').live('click',initNext);
	$('.prev').live('click',initPrev);
	$('.btn_movie').live('click',function(){
		slydeBox(this);
	});
	$('.movie_wrap div').css({"display":"block"});
	progress();
});

//右ボックスのスライド制御
function slydeBox(e){
	door=e.parentNode.parentNode;
	dr=$(door).css("right");
	$('#progress_bar').stop();
	if(dr=="0px"&&doorFlg){
			$('.movie_wrap').css({"display":"block"});
			$(door).animate({ 
				right: "320px"
			}, 400 ,"linear",
			function(){
				doorFlg=false;
				$(e).css({'backgroundImage':'url('+path+'btn_movie_close.jpg)'});
			});
	}else if(dr=="320px"&&!doorFlg){
		$(door).animate({ 
			right: 0
		}, 400 ,"linear",
		function(){
			refreshIFrame();
			progress();
			doorFlg=true;
			$(e).css({'backgroundImage':'url('+path+'btn_movie.jpg)'});
			$('.movie_wrap').css({"display":"none"});
		});
	}else{
		return false;
	}
}



//プログレスバーの制御
function progress(){
	var w=$('#progress_bar').css('width');
	var my_time=1000*time;
	if(doorFlg){
		$('#progress_bar').animate({ 
				width: "514px"
		}, my_time ,'linear',
		function(){
			c.count('progress');
			});
	}else{
		var base=Math.floor(my_time/514);
		var n=w.indexOf('px');
		var my_w=w.substring(0,n-1);
		my_width=514-my_w;
		my_time=my_width*base;
		$('#progress_bar').animate({ 
				width: "514px"
		}, my_time ,'linear',
		function(){
			c.count('progress');
			});
	}
}

//ボタンの初期化
function initNext(){
  $('#progress_bar').stop();
  c.count('next');
}
function initPrev(){
  $('#progress_bar').stop();
  c.count('prev');
}


//カウンターの制御
function Counter(){
	now=1;
	this.total=$("#top_vision>li").length;//ボックスの数
	this.ec=$("#top_vision>li");//ボックスの子要素
	this.now=1;
	
	this.count=function(type){
		if(type=="next"){//nextボタンからのアクセス
			if(this.now!=this.total){
				this.now++;
				fadeOutBox(this.now);
				$("p.counter").text(this.now+"/"+this.total);	
			}else{
				this.now=1;
				fadeOutBox(this.now);
				$("p.counter").text(this.now+"/"+this.total);
			}
		}else if(type=="prev"){//prevボタンからのアクセス
			if(this.now!=1){
				this.now--;
				fadeOutBox(this.now);
				$("p.counter").text(this.now+"/"+this.total);	
			}else{
				this.now=this.total;
				fadeOutBox(this.total);
				$("p.counter").text(this.now+"/"+this.total);
			}
		}else if(type=="progress"){//プログレスバーからのアクセス
		
			if(this.now!=this.total){
				this.now++;
				fadeOutBox(this.now);
				$("p.counter").text(this.now+"/"+this.total);	
			}else{
				this.now=1;
				fadeOutBox(this.now);
				$("p.counter").text(this.now+"/"+this.total);
			}	
		}else{
				this.now++;
				fadeOutBox(this.now);
		}
	}//end count()
}


//フェードアウト
function fadeOutBox(n){
	$("#next").die('click',initNext);
	$("#prev").die('click',initPrev);
	$('#progress_bar').css({'width':'1px'});
	
	if(!ie){
		$("ul#top_vision").fadeTo('fast',0,
		  function(){
			fadeInBox(n);
		  });
	}else{
		$("ul#top_vision").fadeTo(100,0,
		  function(){
			fadeInBox(n);
		  });
	}
	
	if(!doorFlg){
		$(door).css({'right':0});
		doorFlg=true;
		$(btn).css({'backgroundImage':'url('+path+'btn_movie.jpg)'});
		doorFlg=true;
	}
}

//フェードイン
function fadeInBox(n){
	moveBox(n);
	$('#progress_bar').css({'width':'1px'});
	progress();
	$('.btn_movie').css({'backgroundImage':'url('+path+'btn_movie.jpg)'});
	
	if(!ie){
		$("ul#top_vision").fadeTo(100,1,
		  function(){
		$('#next').live('click',initNext);
		$('#prev').live('click',initPrev);
		  });
	}else{
		$("ul#top_vision").fadeTo(100,1,
		  function(){
		$('#next').live('click',initNext);
		$('#prev').live('click',initPrev);
		  });
	}
	
}

//コンテンツの移動
function moveBox(n){
	var n=n-1;
	$(vision).css({"marginLeft":"-"+bw*n+"px"});
}



function refreshIFrame() {
	if(!document.getElementsByTagName) return false;
	var iframeList = document.getElementsByTagName("iframe");
	for (var i = 0; i < iframeList.length; i++) {
		iframeList[i].src = iframeList[i].src;
	}
}









