/*
Movie Walker JavaScript - jQuery title.css
http://movie.walkerplus.com/
 *
Copyright (c) KADOKAWA MARKETING ALL RIGHTS RESERVED.
 *
Created: Yuya Amano - 2009-07-13 16:51
Revision: -
*/

//映画館エリアリスト
(function ($) {
	$.fn.areaList = function(){
		var animation = false;
		var targObj = $('#theaterList_wrap');
		var targetBoxLists = $('.theaterBox');
		targObj.parent('div').css({
			'overflow' : 'hidden',
			'position' : 'relative'
		});
		targObj.css({
			position : 'relative',
			top: '0px',
			left: '0px'
		});
		var animFlag = false
		if(targetBoxLists.length > 5){
			animFlag = true
		}

		if(animFlag){
			//上へ下へのリンクを追加
			targetBoxLists.contents('h2').append('<span class="areaUp">&nbsp;</span><span class="areaDown">&nbsp;</span>');
			$('.theaterBox h2 span').mouseover(function(){
				$(this).addClass('hover');
			}).mouseout(function(){
				$(this).removeClass('hover');
			}).css('cursor','pointer').click(function(){
				var temp = $(this);
				var curNum = parseInt(temp.parents('.theaterBox').attr('id').replace('t',''));
				var nextNum;
				var animPos;
				if(temp.hasClass('areaUp')){
					nextNum = curNum - 1;
					animPos =  $('#t'+nextNum).height() + $('#theaterList_wrap').position().top;
				}else if(temp.hasClass('areaDown')){
					nextNum = curNum + 1;
					animPos =  ($('#t'+curNum).height() - $('#theaterList_wrap').position().top) * -1;
				}
				//最上位、最下位のエレメント
				if(nextNum < 1){ animPos = 0; }
				if(nextNum > $('.theaterBox').length) { animPos = 0; }
				//うごかしちゃう時
				targObj.animate({top: animPos}, 500);
			});
		}

		var maxH = targObj.height();

		$('[id^=tsList_]').click(function(){
			var id = '#' + $(this).attr('id').replace('tsList_','');
			moveToTop(id);
			return false;
		});

		$('[id^=tList_]').click(function(){
			var id = '#' + $(this).attr('id').replace('tList_','');
			moveTo(id,this);
			return false;
		});

		function moveToTop(id){
			var targ = $(id);
			targetBoxLists.removeClass('active');
			targ.addClass('active');

			var targPos = parseInt(targ.position().top);
			var animPos = targPos * -1;
			targObj.stop();
			targObj.animate({top: animPos}, 1000);
		}

		function moveTo(id,selfElem){
			var targ = $(id);
			targetBoxLists.removeClass('active');
			targ.addClass('active');
			if(animFlag){
				var contPos = parseInt($(selfElem).position().top);
				var targPos = parseInt(targ.position().top) + 7;
				var animPos = (targPos - contPos) * -1;
				var v = Math.abs( Math.abs(parseInt(targObj.position().top)) - Math.abs(animPos) );
				if(v > 250){
					targObj.css('opacity','0.3');
				}
				targObj.animate({top: animPos}, 500, null, function(){
					targObj.css('opacity','1');
				});
			}
		}
	}
})(jQuery);






$(document).ready(function(){
	$(document).areaList();
});

