/* SEPTEM 一般サイトトップページ用スクリプト */

(function($){
	/* IE6〜8判別 */
	var isIE6 = (typeof window.addEventListener == 'undefined' && typeof document.documentElement.style.maxHeight == 'undefined');
	var ltIE8 = (typeof window.addEventListener == "undefined" && typeof document.getElementsByClassName == "undefined");
	var isIE8 = (ltIE8)&&(!isIE6);
	var supportPageShow = false;

	$(document).ready(function(){

		/* ロード時、リサイズ時にレイアウト調整 */
		setLayout();
		$(window).bind('resize',setLayout);

		/* ページが表示された際にイメージのアニメーションを開始 */
		if(window.onpageshow===null){
			$(window).bind('pageshow',showProduct);
		}else{
			$(window).bind('load',showProduct);
		}

		/* ナビゲーションボタンのフェード効果 */
		$('#navi li a').each(function(){
			$(this)
				.append('<img class="ov_img" src="'+$(this).css('backgroundImage').match(/url\((.*)\)/)[1].replace(/[\'\"]/g,'')+'" />')
				.hover(
					function(){
						var bodyID = $('body').attr('id');
						var naviID = $(this).attr('id');
						if((bodyID == 'home' && naviID == 'navi00')||
							(bodyID == 'whatnew' && naviID == 'navi01')||
							(bodyID == 'about' && naviID == 'navi02')||
							(bodyID == 'catalog' && naviID == 'navi03')||
							(bodyID == 'voice' && naviID == 'navi04')||
							(bodyID == 'faq' && naviID == 'navi05')||
							(bodyID == 'login' && naviID == 'navi06'))
						{
							return false;
						}else{
							$(this).css('backgroundPosition','left bottom');
							$(this).children('img').stop(true).fadeTo(150,1);
							return false;
						}
					},
					function(){
						$(this).children('img').stop(true).fadeTo(300,0);
						return false;
					}
				)
				.bind('touchstart',function(){startY = endY = event.touches[0].pageY})
				.bind('touchmove',function(){endY = event.touches[0].pageY})
				.bind('touchend',function(){
					if(endY-startY<15){document.location = this.href;}
				});
		});

	});

	/* レイアウト調整 */
	function setLayout(){
		/*setTimeout(function(){window.scroll(0,1)},100);*/
		var tmpMargin = Math.max(Math.round(($(window).height()-$('#wrapper').height())/2),0);
		$('body').css({paddingTop:tmpMargin+'px'});
	}

	/* イメージの表示効果 */
	function showProduct(){
		$('#main_image').stop(true).hide();
		$('.product').stop(true).hide();
		var num = Math.round(Math.random()*5);
		if(num<1) num = 1;
		$('#main_image').fadeIn(800,'swing',function(){
			if(!isIE8){
				$('#prod0'+num).fadeIn(800);
			}else{
				$('#prod0'+num).slideDown();
			}
		});
	}
})(jQuery);

