
var pageCoords;
var clientCoords;
var scrollPosi_x;
$(document).ready(function(){

	if($.browser.msie && parseInt($.browser.version) <= 6){
		$("#loader").css("display","none");
		$("body").prepend("<div id='noie6'></div>");
		$("#noie6").append("<p>ご閲覧をご希望の場合はInternet Explorer 7以上あるいはその他のブラウザをご利用ください。</p>");
		$("#noie6").append("<a href='http://mizuhonet.jp' title='株式会社ミズホネット' target='_blank'>株式会社ミズホネット</a>");
		return false;
	}
	
	$("#wrapper").mousemove(function(e){
		pageCoords = "( " + e.pageX + ", " + e.pageY + " )";
		clientCoords = "( " + e.clientX + ", " + e.clientY + " )";
	});
	
	// Menu
	$('a.smove[href^=#]').click(function(){
		var target;
		target = $( $(this).attr('href') );
		if (target.length == 0) {
			return;
		}
		
		// move
		if (smartScroll.scrolling) { return false; }
		idName = $(this).attr("href");
		idLen = idName.length;
		idNum = parseInt( idName.substr(idLen-1, idLen) );
		idName = idName.substr(1, idLen-2);
		if( idNum == 1 ){
			idName = "top";
		} else {
			idName = idName + String(idNum-1);
		}
		smartScroll.start(idName);
/*
		// move
		rightSpace = 950;
		moveLeftPosition = target.offset().left - ($(window).width() - rightSpace)/2;
		if( target.attr("id") == "page_1" ){
			rightSpace = $(window).width()/$("#wrapper").width();
			moveLeftPosition = target.offset().left - rightSpace;
alert( moveLeftPosition );
		}
		$('html, body').stop(true, false).animate({
				scrollLeft: moveLeftPosition
			}
			, 1500
			, "easeOutCubic"
		);
*/
		return false;
	});
	
	// go Top
	$('a.rollover img').hover(function(){
		if(!$.browser.msie) {
			$(this).animate({
				opacity: 0.8
			}, 200);
		}
	},
	function(){
		if(!$.browser.msie) {
			$(this).animate({
				opacity: 1
			}, 200);
		}
	});


	//--------------------------------------------------------------------------------
	// メニュー非表示
	$('#menu_area a.bt_menu').toggle(
		function(){
			// Open
			$('#menu_area').animate({
				right: 0 + "px"
			}, 1000, "easeOutCubic");
			// Button Change
			$(this).attr("title","閉じる");
			$(this).find("img.open").css("display","none");
			$(this).find("img.close").css("display","inline");
			return false;
		}
		,function(){
			// Close
			$('#menu_area').animate({
				right: -95 + "px"
			}, 1000, "easeOutCubic");
			// Button Change
			$(this).attr("title","開く");
			$(this).find("img.close").css("display","none");
			$(this).find("img.open").css("display","inline");
			return false;
		}
		
	);
	
	
	//--------------------------------------------------------------------------------
	// page 1 Contents Change
	$("#page_1 a.view_message").click(
		function () {
			if($.browser.msie) {
				// IE
				$('#top_logo').stop(true, false).animate(
				{
					top: -300 + "px"
				},
				{
					duration: 1000
					, easing: "easeOutQuad"
					, complete: function()
					{
						$(this).css("display","none");
						$('#top_message').css("display","block");
						$('#top_message').stop(true, false).animate({
								top: 80 + "px"
							}
							, 1500
							, "easeOutExpo"
							, function(){
								$("#page_1 a.logo_return").css( "display", "inline" );
							}
						);
					}
				});
				
				$(this).css("display","none");
			} else {
				// ETC
				$('#top_logo').stop(true, false).animate(
				{
					opacity: 0
					, top: -300 + "px"
				},
				{
					duration: 1000
					, easing: "easeOutQuad"
					, complete: function()
					{
						$('#top_message').stop(true, false).animate({
										top: 80 + "px"
										,opacity: 1
						}
						, 1500
						, "easeOutExpo"
						, function()
						{
							logo_return = $("#page_1 a.logo_return");
							logo_return.css( "opacity", 0 );
							logo_return.css( "display", "inline" );
							logo_return
								.animate({
										opacity: 1
									}
									, 800
									, "easeOutExpo"
								);
						});
					}
				});
				$(this)
					.animate({
							opacity: 0
						}
						, 800
						, "easeOutExpo"
						, function(){
							$(this).css( "display", "none" );
						}
					);
			}
			return false;
		}
	);
	
	
	$("#page_1 a.logo_return").click(
		function () {
			if($.browser.msie) {
				// IE
				$('#top_message').stop(true, false).animate(
				{
					top: -400 + "px"
				},
				{
					duration: 1000
					, easing: "easeOutQuad"
					, complete: function()
					{
						$(this).css("display","none");
						$("#top_logo").css("display","block");
						$('#top_logo').stop(true, false).animate({
								top: 220 + "px"
							}
							, 1500
							, "easeOutExpo"
							, function(){
								$("#page_1 a.view_message").css( "display", "inline" );
							}
						);
					}
				});
				
				$(this).css("display","none");
			} else {
				// ETC
				$('#top_message').stop(true, false).animate(
				{
					opacity: 0
					, top: -300 + "px"
				},
				{
					duration: 1000
					, easing: "easeOutQuad"
					, complete: function()
					{
						$('#top_logo').stop(true, false).animate({
										top: 220 + "px"
										,opacity: 1
						}
						, 1500
						, "easeOutExpo"
						, function()
						{
							view_message = $("#page_1 a.view_message");
							view_message.css( "opacity", 0 );
							view_message.css( "display", "inline" );
							view_message
								.animate({
										opacity: 1
									}
									, 800
									, "easeOutExpo"
								);
						});
					}
				});
				$(this)
					.animate({
							opacity: 0
						}
						, 800
						, "easeOutExpo"
						, function(){
							$(this).css( "display", "none" );
						}
					);
			}
			return false;
		}
	);




//--------------------------------------------------------------------------------
// Service
//--------------------------------------------------------------------------------
	nowServiceClassName = "";
	$('#page_2 #service_list a').click(function(){
		nowServiceClassName = $(this).attr("class");
		if($.browser.msie) {
			// IE
			$("#service_list").css( "display","none" );
			$("#page_2 ." + nowServiceClassName).css( "display","block" );
			$("#page_2 .bt_prev_servicelist").css( "display","block" );
		} else {
			// etc
			$("#service_list")
				.animate({
					opacity: 0
				}
				, 800
				, "easeOutExpo"
				, function()
				{
					$(this).css( "display","none" );
					
					$("#page_2 ." + nowServiceClassName).css( "opacity",0 );
					$("#page_2 ." + nowServiceClassName)
						.css( "display","block" )
						.animate({
							opacity: 1
						}, 800, "easeOutExpo");
					$("#page_2 .bt_prev_servicelist").css( "opacity",0 );
					$("#page_2 .bt_prev_servicelist")
						.css( "display","block" )
						.animate({
							opacity: 1
						}, 800, "easeOutExpo");
				}
			);
		}
		
		return false;
	});
	
	$('#page_2 .bt_prev_servicelist').click(function(){
		if($.browser.msie) {
			// IE
			$("#page_2 div." + nowServiceClassName).css( "display","none" );
			$("#service_list").css( "display","block" );
			$(this).css( "display","none" );
		} else {
			// etc
			$("#page_2 div." + nowServiceClassName)
				.animate({
						opacity: 0
					}
					, 800
					, "easeOutExpo"
					, function()
					{
						$(this).css( "display","none" );
						
						$("#service_list")
							.css( "display","block" )
							.animate({
								opacity: 1
							}, 800, "easeOutExpo");
					}
				);
			
			$(this).hide("easeOutExpo");
		}
		return false;
	});
	
	
	
	//--------------------------------------------------------------------------------
	// Works
	//--------------------------------------------------------------------------------
	angle = 12; // 角度
	wakuHeight = parseInt($("#page_4 .works_area").css("height"));
	
	divHeight = 0;
	$("#page_4 .works_list li").each(function(){
		divHeight += $(this).height();
	});
	
	function moveAnimation( posiTop )
	{
		posiLeft = posiTop * (0.2 + (angle/90)*0.1);
		$("#page_4 .back_oblique").stop(false,true).animate({
			top: posiTop + "px"
			,right: posiLeft + "px"
		}
		,"fast"
		,"swing" );
	}


	function divMoveUpDown( moveSpeed, checkFlag )
	{
		objTop = parseInt($("#page_4 .back_oblique").css("top"));
		if( checkFlag === true ){
			// Down
			topMax = (divHeight - wakuHeight) * -1;
			if( (objTop - moveSpeed) <= topMax ){
				posiTop = topMax;
			} else {
				posiTop = objTop - moveSpeed;
			}
		} else {
			// Up
			if( (objTop + moveSpeed) >= 0 ){
				posiTop = 0;
			} else {
				posiTop = objTop + moveSpeed;
			}
		}
		
		moveAnimation( posiTop );
	}
	
	// Mouse Wheel
	$('#page_4 .works_area').mousewheel(function(event, delta) { 
		if(delta > 0){
			// UP
			divMoveUpDown( 50, false );
		} else {
			// DOWN
			divMoveUpDown( 50, true );
		}
	});
	
	// Button Down
	$("#page_4 a.list_down").click(function(){
		return false;
	});
	$("#page_4 a.list_down").mousedown(function(){
		
		(function(){
			divMoveUpDown( 50, true );
			var tk = setTimeout( arguments.callee, 80 );
			$(document).one('mouseup', function(){
				clearTimeout(tk);
			});
		})();
		return false;
	});
	
	// Button Up
	$("#page_4 a.list_up").click(function(){
		return false;
	});
	$("#page_4 a.list_up").mousedown(function(){
		(function(){
			divMoveUpDown( 50, false );
			var tk = setTimeout( arguments.callee, 80 );
			$(document).one('mouseup', function(){
				clearTimeout(tk);
			});
		})();
		return false;
	});
	
	// LIST
	heightSpace = 30;
	$("#page_4 .works_list li").css("position","absolute");
	$("#page_4 .works_list li").each(function(){
		posiTop = $(this).index()*heightSpace;
		$(this).css( "top", posiTop + "px" );
		posiLeft = posiTop * (0.2 + (angle/90)*0.1) * -1;
		$(this).css( "left", posiLeft + "px" );
	});
	
	
	// 一覧サムネイル
	if(!$.browser.msie){
		// IE以外
		$("#page_4 .thumimg_area").css({
			"opacity": 0
			,"display": "block"
		});
	}
	$("#page_4 .works_list li a").hover(
		function()
		{
			thumClassName = $(this).attr("href");
			thumClassObj = $("#page_4 .thumimg_area img."+thumClassName);
			if( !thumClassName || thumClassObj[0] == undefined ){
				return false;
			}
			thumClassObj.css("display","inline");
			if($.browser.msie){
				$("#page_4 .thumimg_area img").css("display","none");
				$("#page_4 .thumimg_area img").css("z-index","-1");
				$("#page_4 .thumimg_area img."+thumClassName).css("display","inline");
				$("#page_4 .thumimg_area img."+thumClassName).css("z-index","10");
				$("#page_4 .thumimg_area").css("display","block");
			} else {
				$("#page_4 .thumimg_area").stop(false, true).animate({
						opacity: 1
					}
					, 1000
					, "easeOutExpo"
				);
			}
		}
		,function()
		{
			thumClassName = $(this).attr("href");
			if(!thumClassName){
				return false;
			}
			if($.browser.msie){
				$("#page_4 .thumimg_area").css("display","none");
				$("#page_4 .thumimg_area img."+thumClassName).css("display","none");
			} else {
				$("#page_4 .thumimg_area").stop(false, true).animate({
						opacity: 0
					}
					, 1000
					, "easeOutExpo"
					,function(){
					}
				);
				$("#page_4 .thumimg_area img."+thumClassName).css("display","none");
			}
		}
	);
	
	// loading
	$("#page_4").prepend('<div class="loading text_center"></div>');
	$("#page_4 div.loading").each(function(){
		$(this).append('<p><img src="'+templateUrl+imgPath+'loading_net.gif" /></p>');
		$(this).append('<p><img src="'+templateUrl+imgPath+'text_ani_loading.gif" /></p>');
	});
	
	
	// Works View
	$("#page_4 .works_list li a").click(function(){
		aRel = $(this).attr("rel");
		works_area = $("#page_4 .works_area");
		if($.browser.msie){
			works_area.css("display","none");
			$("#page_4 div.loading").css("display","block");
			// 情報を取得して格納する
			getAjaxIdPostInfo( aRel );
		} else {
			$("#page_4 div.loading").css("opacity","0");
			$("#page_4 div.loading").css("display","block");
			works_area.animate({
					opacity: 0
				}
				, 500
				, "easeOutExpo"
				,function()
				{
					$(this).css("display","none");
					$("#page_4 div.loading").animate({
							opacity: 1
						}
						, 500
						, "easeOutExpo"
					);
					
					// 情報を取得して格納する
					getAjaxIdPostInfo( aRel );
				}
			);
		}
		$("#page_4 .thumimg_area").css("display","none");
		
		
		return false;
	});
	
	// Prev
	$("#page_4 .pager a.prev").click(function(){
		postId = $(this).attr("href");
		clickPrevNext( postId );
		return false;
	});
	// Next
	$("#page_4 .pager a.next").click(function(){
		postId = $(this).attr("href");
		clickPrevNext( postId );
		return false;
	});
	
	// Back List
	$("#page_4 .pager a.back").click(function(){
		if($.browser.msie){
			$("#page_4 .pager").css("display","none");
			$("#page_4 .works_detail").css("display","none");
			$("#page_4 .works_area").css("display","block");
			// Thum Img
		} else {
			// list
			$("#page_4 .works_area").css("opacity","0");
			$("#page_4 .works_area").css("display","block");
			$("#page_4 .works_area").animate({
					opacity: 1
				}
				, 500
				, "easeOutExpo"
			);
			
			// pager
			$("#page_4 .pager").animate({
					opacity: 0
				}
				, 500
				, "easeOutExpo"
				,function(){
					$(this).css("display","none");
				}
			);
			
			// detail
			$("#page_4 .works_detail").animate({
					opacity: 0
				}
				, 500
				, "easeOutExpo"
				,function(){
					$("#page_4 .works_detail").css("display","none");
				}
			);
			// Thum Img
			$("#page_4 .thumimg_area").css("display","block");
			
			// スクロールをリセット
			expScrollReset()
		}
		return false;
	});
	

	
	
	//--------------------------------------------------------------------------------
	// Contact
	//--------------------------------------------------------------------------------
	// Check Select
	$("#page_5 ul.query_list li").click(function(){
		$("#page_5 ul.query_list li").each(function(){
			$(this).removeClass("select");
		});
		
		$(this).addClass("select");
	});
	// Submit
	//$("#page_5 #contact_form").click(function(){
	$("#page_5 #contact_submit").click(function(){
		query_item = $("#page_5 ul.query_list li.select img").attr("alt");
		question = $('#page_5 textarea#question').val();
		if( query_item == undefined ){
			alert( "質問項目を選択して下さい" );
			return false;
		}
		if( question == "" ){
			alert( "お問い合わせ内容を入力して下さい" );
			return false;
		}

		// about:blankとしてOpen
		var target = 'MIZUHONET';
		window.open("about:blank", target);
		
		// formを生成
		var form = document.createElement("form");
		form.action = 'https://ssl51.heteml.jp/mizuhonet/contact/index.php';
		form.target = target;
		form.method = 'post';

		// input-hidden生成と設定
		var qs = 
		[
			{type:'hidden',name:'query_item',value:query_item}
			,{type:'hidden',name:'question',value:question}
		];

		for(var i = 0; i < qs.length; i++)
		{
			var ol = qs[i];
			var input = document.createElement("input");
			for(var p in ol) 
			{
				input.setAttribute(p, ol[p]);
			}
			form.appendChild(input);
		}
		
		// formをbodyに追加して、サブミットする。その後、formを削除
		var body = document.getElementsByTagName("body")[0];
		body.appendChild(form);
		form.submit();
		body.removeChild(form);



/*
		$.newOpenWindow({
			option: {
				width : 200
				,height : 200
				,scrollbars : "yes"
			}
			,href: "http://google.co.jp"
			,focus : true
		});
*/
		return false;
	});
	

	
	//--------------------------------------------------------------------------------
	// マウスホイールの切り替え
	//--------------------------------------------------------------------------------
	$("#wheelchange a.w_vertical").click(
		function()
		{
			// 横ホイール：Off
			$(window).unbind('mousewheel', horizontalScroll.setup);
			window.onmousewheel = document.onmousewheel = null;
			
			$(this).css("display","none");
			$("#wheelchange a.w_horizon").css("display","block");
			
			return false;
		}
	);
	$("#wheelchange a.w_horizon").click(
		function()
		{
			// 横ホイール：On
			$(window).mousewheel(horizontalScroll.setup);
			window.onmousewheel = document.onmousewheel = horizontalScroll.setup;
			
			$(this).css("display","none");
			$("#wheelchange a.w_vertical").css("display","block");
			
			return false;
		}
	);
	
	//--------------------------------------------------------------------------------
	// Social Button
	//--------------------------------------------------------------------------------
	$('.mixi_check').socialbutton('mixi_check', {
		key: 'f950a86529cee939e74d4f719769e64bd8dcf60b',
		button: 'button-5',
		url: 'http://mizuhonet.com'
	});
	$('.tweet').socialbutton('twitter');
	$('.facebook').socialbutton('facebook_like',{
		layout: "box_count"
	});
});


