/*------------------------
character
------------------------*/
//loading text
function loadcomp() {
	$('.loading').empty();
}

function character() {
	var currentNum = 1,
	cls = {                       //classまとめ
		menu : ".charabox_menu",    //メニューが入るbox
		menu_move : ".charabox_menu_move",    //メニューとして動くbox
		ico  : ".charabox_menu div a",     //キャラアイコン
		main : ".charabox_main div div",//キャラ説明画像
		move : ".charabox_move",    //動くbox
		current : "current",       //キャラアイコン現在位置
		prev : ".prev",             //戻る
		next : ".next"              //進む
	},
	setting = {
		charaid : "#chara",         //キーにするキャラ画像のhref,id
		menu_width: 595,            //メニューの幅
		main_height:446,            //キャラ画像の高さ
		ico_length: $('.charabox_menu a').size(),//キャラの表示数
		ico_width : 56,             //アイコンの幅
		ico_height: 67,             //アイコンの高さ
		spd       : 250             //表示切替スピード
	};
	voiceshow();
	$(cls.ico).click(function(e){ icoClick(e,$(this)); });
	$(cls.prev).click(function(e){ prev_next(e,$(this),"prev"); });
	$(cls.next).click(function(e){ prev_next(e,$(this),"next"); });
	$(cls.move).css("top","0px");
	$(cls.ico+'[href="'+setting.charaid+currentNum+'"]').addClass(cls.current);
	function prev_next(e,$this,mode){
		loadcomp();
		e.preventDefault();
		var myclass = $this.attr("class");
		if(mode=="prev"){
			currentNum --;
			currentNum = (currentNum<1)? 1 : currentNum;
			moveImg(currentNum);
		}else{
			currentNum ++;
			currentNum = (currentNum>=setting.ico_length)? setting.ico_length : currentNum;
			moveImg(currentNum);
		};
		bgPos();
	};
	function icoClick(e,$this){
		e.preventDefault();
		currentNum = $this.attr("href").split(setting.charaid)[1];
		moveImg(currentNum);
	};
	function moveImg(currentNum){
		$('.voicebox').hide();
		moveMenu();
		$(cls.ico).removeClass(cls.current);
		$(cls.ico+'[href="'+setting.charaid+currentNum+'"]').addClass(cls.current);
		var tarPos = -((currentNum-1)*setting.main_height)+"px";
		$(cls.move).animate({
			top : tarPos
		},setting.spd,function(){voiceshow()});
	};
	function moveMenu(){
		var menuPos = -(setting.ico_width*(currentNum-1));
		$(cls.menu_move).animate({
			left : menuPos
		},setting.spd);
	};
	//background
	function bgPos() {
		$.each($(".charabox_menu a"),function() {
			//main image
			$('#chara'+$(this).text()).css('background','url("/angelic/common/images/chara_detail_'+$(this).text()+'.jpg") left top no-repeat transparent');
			var mypos = ($(this).text()-1)*56;

			(!$(this).hasClass('current'))?$(this).css('background-position','-'+mypos+'px top'):$(this).css('background-position','-'+mypos+'px bottom');

			$(this).hover(function(){
				//hover
				$(this).css('background-position','-'+mypos+'px bottom');
			},function(){
				//out
				if(!$(this).hasClass('current'))$(this).css('background-position','-'+mypos+'px top');
			});
		});
	};
	//voice
	function voiceshow() {
		if($('.charabox_menu a[class=current]').text()!=22) {
			$('.voicebox').show();
		} else {
			$('.voicebox').hide();
		}
	}
	$('.voicebox a').click(function() {
		//chara num
		var charanum = $('.charabox_menu a[class=current]').text();
		//voice num
		var voicenum = $(this).attr('class').split('e')[1];
		voiceplay(charanum,voicenum);
	});
	function voiceplay(chara,voice) {
		$('.loading').html('読み込み中...');
		var filename = 'chara'+chara+'_'+voice;
		var so = new SWFObject("/angelic/common/swf/voice.swf?file="+filename, "voice_swf", "1", "1", "8", "#000000");
		so.addParam("base", "/angelic/common/voice/");
		so.addParam("quality", "high");
		so.addParam("wmode", "transparent");
		so.addParam("scale", "noscale");
		so.write("voiceplay");
	}
	bgPos();
}
