// JavaScript Document

(function($){

	$(document).ready(function(){
		
		// Picture Rootote
		Picture_Rootote();
		function Picture_Rootote(){
			// 初期設定
			var mainbox = '.picture_box';
			var picturelist = '.picture_list';
			var thumblist = '.thumb_list';
			
			// 切り替わり時間
			var time = 3000;
			
			var pic_number = $(mainbox + ' ' + picturelist + ' li').length;
			var	 n =1;
			$(mainbox + ' ' + picturelist + ' li').hide();
			$(mainbox + ' ' + picturelist + ' li').eq(0).show();
			$(mainbox+' '+thumblist+' li').eq(0).addClass('active');
			

			// 画像ローテション処理
			function rootote(){
				if ( n >= pic_number ){ n = 0 };
				//alert (n +" "+ pic_number);
				$(mainbox + ' ' + picturelist + ' li').fadeOut(300);
				$(mainbox + ' ' + picturelist + ' li').eq(n).fadeIn(300);
				$(mainbox+' '+thumblist+' li').removeClass('active');
				$(mainbox+' '+thumblist+' li').eq(n).addClass('active');

				n = ++n;
			};
			var id = setInterval(rootote,time);
			
			// サムネイルクリック

			$(mainbox+' '+thumblist).css({bottom:'-69px'});
			$(mainbox).hover(
				function(){ $(this).children(thumblist).stop().animate({bottom:'0px'},300);return false(); },
				function(){ $(this).children(thumblist).stop().animate({bottom:'-69px'},500);return false(); }
			)
			
			$(mainbox+' '+thumblist+' li').click(
				function(){
					clearInterval(id);
					click_number = $(mainbox+' '+thumblist+' li').index(this);
					//alert(test);
					n = click_number;
					rootote();
					id = setInterval(rootote,time);
				}
			);

		};
		
		// ロールオーバー
		$('.rollover').hover(
			function(){
				$(this).stop();		
				$(this).fadeTo(200,0);	
				return false;
			},
			function(){
				$(this).stop();		
				$(this).fadeTo(300,1);		
				return false;
			}
		);
		
		// コンテンツインデックス用ロールオーバー
		$('#content .contents_index_box01 ul li a').hover(
			function(){
				$(this).stop();		
				$(this).children(".contents_index01").fadeTo(200,0);	
				return false;
			},
			function(){
				$(this).stop();		
				$(this).children(".contents_index01").fadeTo(300,1);		
				return false;
			}
		);

		// サイドバーロールオーバー
		$('.sidebar_box01 ul li a').hover(
			function(){
				$(this).stop().animate({ backgroundColor:"#E6F2FF" },100);
				return false;
			},
			function(){
				$(this).stop().animate({ backgroundColor:"#ffffff" },300);		
				return false;
			}
		);
		
		// font size change
		font_size_change();
		function font_size_change(){
			// 初期値設定
				// 初期文字サイズ(px)
				var default_fontsize = 12;
				// 最小基本文字サイズ(px)
				var minimum_fontsize = 8;
				// 最大基本文字サイズ(px)
				var maximum_fontsize = 18;
				// 拡大数(px)
				var fontchange_size = 1
				// 保存期間（日数）
				var cookie_reserve_day = 14

			// サブルーチン処理
				// クッキー書き込み処理
				function setcookie(){
					$.cookie('font_size_cookie',font_size,{ expires: cookie_reserve_day , path:'/' });
				};
	
				// フォントサイズをbodyに反映
				function setfontsize(){
					if ( font_size < minimum_fontsize ){
						font_size = minimum_fontsize;
					} else if ( font_size > maximum_fontsize ){
						font_size = maximum_fontsize;
					};
					//alert (font_size);
					$("body").css('fontSize',font_size);
				};
			
			// 初期処理
			var font_size = 0;
			font_size = Number($.cookie('font_size_cookie'));
			if ( font_size == 0 ){
				var font_size = default_fontsize;
			};
			setfontsize();
			
			// イベント処理
			$(".fontsize dt").dblclick(
				function(){
					font_size = default_fontsize;
					setfontsize();
					setcookie();
					return false;
				}
			);
			$(".fontsize .large").click(
				function(){
					font_size = font_size + fontchange_size;
					setfontsize();
					setcookie();
					return false;
				}
			);
			$(".fontsize .small").click(
				function(){
					font_size = font_size - fontchange_size;
					setfontsize();
					setcookie();
					return false;
				}
			);
		};
		
		// flatheight
		$('.flatHeights').flatHeights();

		// set year in copyrights.
		$('#footer .copy').html('COPYRIGHT &copy;1998-'+ (new Date().getFullYear() || '2009') +' Komaden Corporation All rights reserved');
		
		$(".close_button").click(
			function(){
				window.close();
				return false;
			}
		);
		
		$(".print_button").click(
			function(){
				window.print();
				return false;
			}
		);
		
		$(".popup").click(
			function(){
				window.open(this.href,'_blank',' status=no, toolbar=no, location=no, menubar=no, scrollbars=yes, resizable=yes, width=600');
				return false;
			}
		);

		//-- for IE6 but not IE7, Moz, Safari, Opera...
		if (typeof document.body.style.maxHeight == "undefined") {
		try {
		document.execCommand('BackgroundImageCache', false, true);
		} catch(e) { /* unless it's not IE6... */ }
		} // if

	});

})(jQuery);


