$().ready(function() {
	
	/**
	 * スライドショーの動作をセット
	 *
	 *
	 */
	var timer = 6000; // 1000分の1秒単位
	var img_count = $('#top_images').children('img').length;
	var setIndex = 0;
	$('#top_images').children('img').each(function(i) {
		if(i==setIndex) { return true; }
		$(this).hide();
	});
	
	setInterval(function() {
		$('#top_images').children('img').eq(setIndex).fadeOut(2000);
		if(setIndex==(img_count - 1)) { setIndex = 0; }
		else { setIndex++; }
		$('#top_images').children('img').eq(setIndex).fadeIn(2000);
	}, timer);




	
	/**
	* タブメニューの動作をセット
	*
	*
	*/
	$('a', $('ul.tab')).each(function() {
		$(this).click(function() {
			var tab_type, _this, box_type;
			_this = $(this); // thisを保持
			tab_type = _this.attr('class');
			box_type = tab_type.replace('tab-menu-', '');
			if($('.'+box_type, $('div#selecttab-box')).css('display') == 'none') {
				$('img', $('ul.tab')).each(function() {
					var this_class, li, li_class;
					this_class = $(this).closest('a').attr('class');
					// クリックした種類
					if(tab_type == this_class) {
						li = $(this).closest('li');
						li_class = li.attr('class').replace(this_class+'-', '');
						if(li_class == 'on') li.show();
						if(li_class == 'off') li.hide();
					}else {
						li = $(this).closest('li');
						li_class = li.attr('class').replace(this_class+'-', '');
						if(li_class == 'on') li.hide();
						if(li_class == 'off') li.show();
					}
				});
				$('.tab-contents').each(function() {
					if($(this).css('display') == 'none') { return true; }
					$(this).fadeOut('normal', function() {
						$('.'+box_type, $('div#selecttab-box')).fadeIn('normal');
					});
				});
			}
		});
	});


	/** 
	 * タブメニュー内の吹き出しの動作をセット
	 *
	 *
	 *
	 */
	$('.pop-fukidashi').hide();
	$('a.fukidasi-event').each(function() {
		$(this).bind('mouseover', function(){
			var timer = 0;
			var timerID;
			var openType;
			var interval = 300; // 1/1000秒単位 で何秒間マウスをかぶせると動作するか。

			openType = $(this).data('fukidasi-type');
			timerID = setInterval(function() {
				clearInterval(timerID);
				$('#fukidashi_'+openType).fadeIn('normal');
			}, interval);
			// マウスイベントを削除する
			$(this).bind('mouseout', function() {
				clearInterval(timerID);
				if($('#fukidashi_'+openType).css('display') != 'none') {
					$('#fukidashi_'+openType).fadeOut('normal');
				}
			});
		});
	});
});

