$(document).ready(function(){
//Ajax Loading
	$('#ajaxload').ajaxStart(function(){
		$(this).show();
	}).ajaxStop(function(){
		$(this).hide() ;
	});
	
//Body高度
	if(parseInt(navigator.appVersion)>3) 
	{
		if(navigator.appName=="Netscape") 
		{
			body = window.innerHeight;
		}
		if(navigator.appName.indexOf("Microsoft")!=-1) 
		{
			body = document.documentElement.clientHeight;
		}
	}
	
	if( body < $('#container').height() )
	{
		body = $('#container').height() ;
	}
	
//Ajax內頁
	$('.strategyPage').click(function(){
		$('#StrategyZone').load( 'strategy.php?item=' + $(this).attr('thisitem') ) ;
		return false ;
	}) ;
	$('.identityPage').click(function(){
		$('#IdentityZone').load( 'identity.php?item=' + $(this).attr('thisitem') ) ;
		return false ;
	}) ;
	$('.eyeshotPage').click(function(){
		$('#EyeshotZone').load( 'eyeshot.php?item=' + $(this).attr('thisitem') ) ;
		return false ;
	}) ;
	
	
	

	$('.NPword a').click(function(){
		$('.toggleMenu').parent().next().slideUp('fast') ;
		$('.toggleMenu').attr('style','') ;
		if( $(this).attr('table') == 'strategy' )
		{
			$('#StrategyZone').load( $(this).attr('href') ).slideDown('slow',function(){
				var $body = (window.opera) ? (document.compatMode == "CSS1Compat" ? $('html') : $('body')) : $('html,body');
				$body.animate({
					scrollTop: 172
				}, 600);
				topNp = 172 + $('#strategyMenu').height() ;
				imgHeightNp = body - 172 ;
				imgHNp = $(this).height() ;
				moveHNp = topNp + 28 + imgHNp ;
					
				$('#repeat').css({
					'top' : topNp ,
					'height' : imgHeightNp ,
					'background-position': "0px -" + topNp + "px" 
				}).animate({ 'top' : moveHNp } , 'fast') ;
			}) ;
		}
		if( $(this).attr('table') == 'identity' )
		{
			$('#IdentityZone').load( $(this).attr('href') ).slideDown('slow',function(){
				var $body = (window.opera) ? (document.compatMode == "CSS1Compat" ? $('html') : $('body')) : $('html,body');
				$body.animate({
					scrollTop: 250
				}, 600);
				topNp = 250 + $('#identityMenu').height() ;
				imgHeightNp = body - 250 ;
				imgHNp = $(this).height() ;
				moveHNp = topNp + 28 + imgHNp ;
					
				$('#repeat').css({
					'top' : topNp ,
					'height' : imgHeightNp ,
					'background-position': "0px -" + topNp + "px" 
				}).animate({ 'top' : moveHNp } , 'fast') ;
			}) ;
		}
		if( $(this).attr('table') == 'eyeshot' )
		{
			$('#EyeshotZone').load( $(this).attr('href') ).slideDown('slow',function(){
				var $body = (window.opera) ? (document.compatMode == "CSS1Compat" ? $('html') : $('body')) : $('html,body');
				$body.animate({
					scrollTop: 430
				}, 600);
				topNp = 430 + $('#identityMenu').height() ;
				imgHeightNp = body - 430 ;
				imgHNp = $(this).height() ;
				moveHNp = topNp + 28 + imgHNp ;
					
				$('#repeat').css({
					'top' : topNp ,
					'height' : imgHeightNp ,
					'background-position': "0px -" + topNp + "px" 
				}).animate({ 'top' : moveHNp } , 'fast') ;
			}) ;
		}
		return false ;
	}) ;
//contact moverOver
	$('.seedMsg').hover(function(){
		$('> input' ,this).attr('src' , './images/smsg_over.gif') ;
	},function(){
		$('> input' ,this).attr('src' , './images/smsg.gif') ;
	}) ;
	
	
//頁面縮合
	$('.toggleMenu').click(function(){
		var menuid = $(this).attr('id') ;
		var scrolly = 0 ;
		var mag = '' ;
		switch (menuid)
		{
		case "introductionMenu" :
			scrolly = 115 ;
			if(window.XMLHttpRequest)
			{
				mbg = 'background:url(./images/mbg1.png)' ;
			}
			else
			{
				mbg = "_background:none;_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true', sizingMethod='scale', src='images/mbg1.png' );" ;
			}
			break ;
		case "strategyMenu" :
			scrolly = 172 ;
			if(window.XMLHttpRequest)
			{
				mbg = 'background:url(./images/mbg2.png)' ;
			}
			else
			{
				mbg = "_background:none;_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true', sizingMethod='scale', src='images/mbg2.png' );" ;
			}
			//重Load列表
			if( $('#IdentityZone').children().attr('class') == 'jList')
			{
				$('#IdentityZone').load( 'identity_list.php' ) ;
			}
			if( $('#EyeshotZone').children().attr('class') == 'eyeBimg' )
			{
				$('#EyeshotZone').load( 'eyeshot_list.php' ) ;
			}

			break ;
		case "identityMenu" :
			scrolly = 250 ;
			if(window.XMLHttpRequest)
			{
				mbg = 'background:url(./images/mbg2.png)' ;
			}
			else
			{
				mbg = "_background:none;_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true', sizingMethod='scale', src='images/mbg2.png' );" ;
			}
			//重Load列表
			if( $('#StrategyZone').children().attr('class') == 'jList')
			{
				$('#StrategyZone').load( 'strategy_list.php' ) ;
			}
			if( $('#EyeshotZone').children().attr('class') == 'eyeBimg' )
			{
				$('#EyeshotZone').load( 'eyeshot_list.php' ) ;
			}

			break ;
		case "solutionMenu" :
			scrolly = 345 ;
			if(window.XMLHttpRequest)
			{
				mbg = 'background:url(./images/mbg1.png)' ;
			}
			else
			{
				mbg = "_background:none;_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true', sizingMethod='scale', src='images/mbg1.png' );" ;
			}
			break ;
		case "clientMenu" :
			scrolly = 387 ;
			if(window.XMLHttpRequest)
			{
				mbg = 'background:url(./images/mbg1.png)' ;
			}
			else
			{
				mbg = "_background:none;_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true', sizingMethod='scale', src='images/mbg1.png' );" ;
			}
			break ;
		case "eyeshotMenu" :
			scrolly = 430 ;
			if(window.XMLHttpRequest)
			{
				mbg = 'background:url(./images/mbg1.png)' ;
			}
			else
			{
				mbg = "_background:none;_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true', sizingMethod='scale', src='images/mbg1.png' );" ;
			}

			//重Load列表
			if( $('#StrategyZone').children().attr('class') == 'jList')
			{
				$('#StrategyZone').load( 'strategy_list.php' ) ;
			}
			if( $('#IdentityZone').children().attr('class') == 'jList')
			{
				$('#IdentityZone').load( 'identity_list.php' ) ;
			}

			break ;
		case "contactMenu" :
			scrolly = 522 ;
			if(window.XMLHttpRequest)
			{
				mbg = 'background:url(./images/mbg1.png)' ;
			}
			else
			{
				mbg = "_background:none;_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true', sizingMethod='scale', src='images/mbg1.png' );" ;
			}
			break ;
		case "shareMenu" :
			scrolly = 683 ;
			if(window.XMLHttpRequest)
			{
				mbg = 'background:url(./images/mbg3.png)' ;
			}
			else
			{
				mbg = "_background:none;_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true', sizingMethod='scale', src='images/mbg3.png' );" ;
			}
			break ;
		}
		imgH = body - scrolly ;
		moveH = $(this).parent().next().height() + scrolly + 28 + $(this).height() ;
		position = scrolly + $(this).height() ;
		if( $(this).parent().next().is(':hidden') )
		{//展開
			$('.toggleMenu').not($(this)).attr('style' , '') ;
			$blockMenu = "" ;
			$nowClickMenu = '#'+$(this).attr('id') ;
			$('.toggleMenu').parent().next().each(function(){
				if( $(this).css('display') == 'block' )
				{
					$blockMenu = '#'+$(this).attr('id') ;
				}
			}) ;

			switch ($blockMenu)
			{
			case "#IntroductionZone" :
				oldscrolly = body - 115 ;
				break ;
			case "#StrategyZone" :
				oldscrolly = body - 172 ;
				break ;
			case "#IdentityZone" :
				oldscrolly = body - 250 ;
				break ;
			case "#SolutionZone" :
				oldscrolly = body - 345 ;
				break ;
			case "#ClientZone" :
				oldscrolly = body - 387 ;
				break ;
			case "#EyeshotZone" :
				oldscrolly = body - 430 ;
				break ;
			case "#ContactZone" :
				oldscrolly = body - 522 ;
				break ;
			case "#shareContent" :
				oldscrolly = body - 683 ;
				break ;
			}

			if( $blockMenu != '' )
			{
				$($blockMenu).slideUp(1000,function(){
					$($nowClickMenu).parent().next().slideDown(1000,function(){
						var $body = (window.opera) ? (document.compatMode == "CSS1Compat" ? $('html') : $('body')) : $('html,body');
						$body.animate({
							scrollTop: scrolly
						}, 600);
					}) ;

					$($nowClickMenu).attr('style' , mbg) ;
					$('#repeat').animate({ 'top' : moveH } , 1000).attr('nowposition' , moveH).css({
						'top' : scrolly + $($nowClickMenu).height() ,
						'height' : imgH ,
						'background-position': "0px -" + position + "px" 
					}).attr('nowposition' , moveH) ;
				}) ;

				$('#repeat').animate({ 'top' : scrolly + $($nowClickMenu).height() },1000 ).css({
					'height' : imgH ,
					'background-position': "0px -" + position + "px" 
				}).attr('nowposition' , moveH) ;

				var $body = (window.opera) ? (document.compatMode == "CSS1Compat" ? $('html') : $('body')) : $('html,body');
				$body.animate({
					scrollTop: 0
				}, 100);
				
			}
			else
			{
				$(this).parent().next().slideDown(1000,function(){
					var $body = (window.opera) ? (document.compatMode == "CSS1Compat" ? $('html') : $('body')) : $('html,body');
					$body.animate({
						scrollTop: scrolly
					}, 1000);
				}) ;
				$(this).attr('style' , mbg) ;
				$('#repeat').css({
					'top' : scrolly + $(this).height() ,
					'height' : imgH ,
					'background-position': "0px -" + position + "px" 
				}).animate({ 'top' : moveH } , 1000).attr('nowposition' , moveH) ;
			}
			return false ;
		}
		else
		{//關閉
			if(menuid == 'strategyMenu' && $('#StrategyZone').children().attr('class') == 'jList' )
			{//strategy
				$('#StrategyZone').load( 'strategy_list.php' ,function(){
					topNp = scrolly + $('#identityMenu').height() ;
					imgHeightNp = body - scrolly ;
					imgHNp = $(this).height() ;
					moveHNp = topNp + 28 + imgHNp ;
					$('#repeat').css({
						'top' : topNp ,
						'height' : imgHeightNp ,
						'background-position': "0px -" + topNp + "px" 
					}).animate({ 'top' : moveHNp } , 1) ;
				}) ;
				$(this).attr('style' , '') ;
				var $body = (window.opera) ? (document.compatMode == "CSS1Compat" ? $('html') : $('body')) : $('html,body');
				$body.animate({
					scrollTop: 0
				}, 600);
				return false ;
			}
			if(menuid == 'identityMenu' && $('#IdentityZone').children().attr('class') == 'jList' )
			{//identity
				$('#IdentityZone').load( 'identity_list.php' ,function(){
					topNp = scrolly + $('#identityMenu').height() ;
					imgHeightNp = body - scrolly ;
					imgHNp = $(this).height() ;
					moveHNp = topNp + 28 + imgHNp ;
					$('#repeat').css({
						'top' : topNp ,
						'height' : imgHeightNp ,
						'background-position': "0px -" + topNp + "px" 
					}).animate({ 'top' : moveHNp } , 1) ;
				}) ;
				$(this).attr('style' , '') ;
				var $body = (window.opera) ? (document.compatMode == "CSS1Compat" ? $('html') : $('body')) : $('html,body');
				$body.animate({
					scrollTop: 0
				}, 600);
				return false ;
			}
			
			if(menuid == 'eyeshotMenu' && $('#EyeshotZone').children().attr('class') == 'eyeBimg')
			{//eyeshot
				$('#EyeshotZone').load( 'eyeshot_list.php' ,function(){
					topNp = scrolly + $('#identityMenu').height() ;
					imgHeightNp = body - scrolly ;
					imgHNp = $(this).height() ;
					moveHNp = topNp + 28 + imgHNp ;
					$('#repeat').css({
						'top' : topNp ,
						'height' : imgHeightNp ,
						'background-position': "0px -" + topNp + "px" 
					}).animate({ 'top' : moveHNp } , 1) ;
				}) ;

				$(this).attr('style' , '') ;
				var $body = (window.opera) ? (document.compatMode == "CSS1Compat" ? $('html') : $('body')) : $('html,body');
				$body.animate({
					scrollTop: 0
				}, 600);
				return false ;
			}

			$('#repeat').css({
				'top' : scrolly + $(this).height() ,
				'height' : '0px' ,
				'background-position': "0px 0px"
			});
			
			if(window.XMLHttpRequest)
			{
				$('#repeat').animate({ top : 0 },'slow') ;
			}
			else
			{
				$('#repeat').fadeOut('fast').animate({ top : 0 },'fast').fadeIn('fast') ;
			}
			
			$(this).attr('style' , '') ;
			$(this).parent().next().slideUp(500 , function(){
				var $body = (window.opera) ? (document.compatMode == "CSS1Compat" ? $('html') : $('body')) : $('html,body');
				$body.animate({
					scrollTop: 0
				}, 600);
			}) ;

			return false ;
		}
	}) ;
}) ;
