function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
  var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
  if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
  
/*function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}*/

function mainNavigation(trg){
  showMenu('all', 'hide');
  if(trg!=currentPage){
	theLevel = $(window).height();
	assignBG(trg);
	if(trg=='start'){	
	  if($.browser.msie&&$.browser.version<=6){
		$('#noIE').html("<div style='height:60px; width:100%; position:absolute; left:0px; top:0px; z-index:44; background:url(images/ourClientBgTop.jpg) center center repeat'>&nbsp;</div><div style='height:30px; width:100%; position:absolute; left:0px; bottom:0px; z-index:43; background:url(images/ourClientBgButtom.jpg) center center repeat'>&nbsp;</div><div id='noIEContent' style='background-image:url(images/noIE6.jpg); position:absolute; width:620px; height:390px; z-index:42; background-repeat:no-repeat'><div style='position:absolute; left: 40px; top: 33px; width: 540px; height: auto;'><div style='font-size:55px; padding-bottom:8px;'>Sorry! No more IE6.</div><div style='font-size:14px; padding-bottom:10px'>As IE6 have been released for over 10 years,  we do not support IE6 anymore.  For more information please visit <a href='http://www.ie6countdown.com/' target='_blank'>http://www.ie6countdown.com/</a>.</div><div style='font-size:14px; padding-bottom:20px'>You were recommended to switch to <a href'http://www.google.com/chrome/' target='_blank'>Google Chrome</a> or other standard browsers.</div><div style='font-size:13px; padding-bottom:5px; width:420px'><table border=0 cellpadding=0 cellspacing=0><tr><td width=51 align=left valign=top style='font-size:12px; padding-bottom:2px'>Tel</td><td width=11 align='left' valign='top' style='font-size:12px; padding-bottom:2px'>&nbsp;:</td><td width=328 align='left' valign='top' style='font-size:12px; padding-bottom:2px'>+852 3105-3633</td></tr><tr><td align='left' valign='top' style='font-size:12px; padding-bottom:2px'>Fax</td><td align='left' valign='top' style='font-size:12px; padding-bottom:2px'>&nbsp;:</td><td align='left' valign='top' style='font-size:12px; padding-bottom:2px'>+852 3105-3663</td></tr><tr><td align='left' valign='top' style='font-size:12px; padding-bottom:2px'>E-mail</td><td align='left' valign='top' style='font-size:12px; padding-bottom:2px'>&nbsp;:</td><td align='left' valign='top' style='font-size:12px; padding-bottom:2px'><a href='mailto:enquiry@mybee.cc?subject=Enquiry%20from%20website.'>enquiry@mybee.cc</a></td></tr><tr><td align='left' valign='top' style='font-size:12px; padding-bottom:2px'>Address</td><td align='left' valign='top' style='font-size:12px; padding-bottom:2px'>&nbsp;:</td><td align='left' valign='top' style='font-size:12px; padding-bottom:2px'>Rm903, Arion Commercial Centre, 2-12 Queen's Road West, Sheung Wan, Hong Kong S.A.R.</td></tr></table></div><div style='font-size:10px; width:420px; padding:73px 0px 0px 58px;'>Copyright &copy; 2012 Mybee Technology Ltd. All rights reserved.</div></div></div><div id='noIEBG' style='background-image:url(images/noIE6backBG.jpg); background-position:center center; position:absolute; width:100%; z-index:41'>&nbsp;</div>");			
		$('#noIE').css('display', 'block');
		ie6Resize();
		$('#logoContainer1').remove();
		$('#headerArea').remove();	
		$('#footerArea').remove();	
		$('#loadingContainer1').remove();
		$('#bgBody').remove();
	  }else{ 
		$('#noIE').remove();
		$('#headerArea').css('top', '-117px');
		$('#footerArea').css('bottom', '-69px');	
				
		$('#logo').css('width', '220px');
		$('#logo').css('height', '238px');	
		
		if(!$.browser.msie||$.browser.version>=9){
		  $('#solganDiv').css('opacity', 0);
		}
				
		//$('#solganDiv').css('left', '419px');
		//$('#solganDiv').css('top', '-200px');
							
		$('#headerBG').css('height', '67px');	
		$('#headerBody1').css('height', '67px');	
		$('#headerBody2').css('height', '67px');	
	
		$('#headerMenu').css('width', '1020px');	
		$('#menuSpaceTop').css('height', '9px');	
		$('#menuSpaceButtom').css('height', '10px');			
		$('#menuSpace1').css('width', '61px');	
		$('#menuSpace2').css('width', '61px');	
		$('#menuSpace3').css('width', '61px');	
		$('#menuSpace4').css('width', '61px');	
		$('#menuSpace5').css('width', '61px');	
		
		$('#logoDiv').css('left', (1020-220)/2+'px');	
		$('#logoDiv').css('top', (theLevel-238)/2+'px');			
		
		// animation		
		$('#logo').css('webkitTransform', "rotateY(0deg)");	
		$('#logo').css('MozTransform', "rotateY(0deg)");	
		$('#logo').css('OTransform', "rotateY(0deg)");	
		$('#logo').css('msTransform', "rotateY(0deg)");	
		$('#logo').css('transform', "rotateY(0deg)");
		if(!$.browser.msie||$.browser.version>=9){
		  $('#logo').animate({'opacity': '1'}, 1500);
		}		
		setTimeout("$('#headerArea').animate({'top': '0px'}, 500);$('#footerArea').animate({'bottom': '0px'}, 500)" , 1700);		
		setTimeout("mainNavigation('"+directPage+"')" , 2000);			  
		// end of animation
	  }
	}else if(trg=='home' || trg=='homeStart'){
	  ModeB();
	  menuUnderLine(0);
	  $('#bgBody').animate({'opacity': '0'}, 1000);
	  $('#logoDiv').animate({"left": '285px', "top": (theLevel/2 - 93)+'px'}, 700, function(){
		if(!$.browser.msie||$.browser.version>=9){
		  $('#solganDiv').animate({'top': (theLevel/2)-47 +'px','opacity': '1'}, 1500);
		}else{
		  $('#solganDiv').animate({'top': (theLevel/2)-47 +'px'}, 1500);
		}		  
	  });				
	  $('#logo').animate({'width': '135px','height': '146px'}, 700);	  
	  
	  showLoading('show');
	 setTimeout("$('#bgBody').load('homeBG.html', function(){afterAnimate('homeStart')})" , 1000);			
	}else if(trg=='aboutMybee'){
	  ModeB();
	  menuUnderLine(1);
	  $('#bgBody').animate({'opacity': '0'}, 1000);
	  
	  $('#logoDiv').animate({"left": '461px', "top": ($(window).height()/2 - 176)+'px'}, 1000);
	  $('#logo').animate({'width': '98px','height': '106px'}, 500);	
	  solganOut();		
	  
	  showLoading('show');
	  setTimeout("$('#bgBody').load('aboutMybeeBG.html', function(){afterAnimate('aboutMybee')})" , 1000);
	}else if(trg=='ourMission'){
	  ModeB();
	  menuUnderLine(1);
	  $('#bgBody').animate({'opacity': '0'}, 1000);
	  
	  $('#logoDiv').animate({"left": '490px', "top": (theLevel/2 + 50)+'px'}, 1000);
	  $('#logo').animate({'width': '113px','height': '122px'}, 500);	
	  solganOut();		
	  
	  showLoading('show');
	  setTimeout("$('#bgBody').load('ourMissionBG.html', function(){afterAnimate('ourMission')})" , 1000);
	}else if(trg=='ourService'){		
	  ModeA(); 
	  menuUnderLine(2);
	  $('#bgBody').animate({'opacity': '0'}, 1000);
	  
	  solganOut();		
	  
	  showLoading('show');
	  setTimeout("$('#bgBody').load('ourServiceBG.html', function(){afterAnimate('ourService');ourServiceClickAct('start')})" , 1000);
	}else if(trg=='ourClients'){		
	  ModeA();  
	  menuUnderLine(3);
	  $('#bgBody').animate({'opacity': '0'}, 1000);
	  
	  solganOut();
			  
	  showLoading('show');
	  setTimeout("$('#bgBody').load('ourClientsBG.html', function(){afterAnimate('ourClients');ourClientsiPadGuide('start')})" , 1000);
	}else if(trg=='ourProjects'){				
	  ModeA();
	  menuUnderLine(3);
	  $('#bgBody').animate({'opacity': '0'}, 1000);
	  
	  solganOut();		
	  
	  showLoading('show');
	  setTimeout("$('#bgBody').load('ourProjectsBG.html', function(){afterAnimate('ourProjects');ourProjectsClickAct('start')})" , 1000);
	}else if(trg=='contactUs'){
	  ModeA();
	  menuUnderLine(4);
	  $('#bgBody').animate({'opacity': '0'}, 1000);
	  
	  solganOut();
			  
	  showLoading('show');
	  setTimeout("$('#bgBody').load('contactUsBG.html', function(){afterAnimate('contactUs');startLoopBG()})" , 1000);
	  //setTimeout("$('#bgBody').load('contactUsBG.html', function(){afterAnimate('contactUs');loadGoogleMap();})" , 1000);		
	}
	currentPage = trg;	  
	if(trg!='start'){		
	  
	  if(trg=='home'||trg=='homeStart'){
		directPage='home';
		winLoc.hash='';	
	  }else {
		directPage=trg;
		winLoc.hash=directPage;
	  }	
	}  
  }
} 
   
function assignBG(trg){
  if(trg=='ourMission'){
	$('#headerBG').css('backgroundImage', 'url(images/ourMissionBgTop.jpg)');	
	$('#footerBG').css('backgroundImage', 'url(images/ourMissionBgButtom.jpg)');	
	$('#subAboutMybee2').css('backgroundImage', 'url(images/ourMissionBgTop.jpg)');	
	$('#subOurClients2').css('backgroundImage', 'url(images/ourMissionBgTop.jpg)');	
	$('#subLogin2').css('backgroundImage', 'url(images/wBG.png)');	
	$('#subMybeeLab2').css('backgroundImage', 'url(images/ourMissionBgTop.jpg)');			   
  }else if(trg=='ourService'){
	$('#headerBG').css('backgroundImage', 'url(images/ourServiceBG.png)');	
	$('#footerBG').css('backgroundImage', 'url(images/ourServiceBG.png)');	
	$('#subAboutMybee2').css('backgroundImage', 'url(images/ourServiceBG.png)');	
	$('#subOurClients2').css('backgroundImage', 'url(images/ourServiceBG.png)');
	$('#subLogin2').css('backgroundImage', 'url(images/ourServiceBG.png)');	
	$('#subMybeeLab2').css('backgroundImage', 'url(images/ourServiceBG.png)');	
  }else if(trg=='ourClients'){
	$('#headerBG').css('backgroundImage', 'url(images/ourClientBgTop.jpg)');	
	$('#footerBG').css('backgroundImage', 'url(images/ourClientBgButtom.jpg)');	
	$('#subAboutMybee2').css('backgroundImage', 'url(images/ourClientBgTop.jpg)');	
	$('#subOurClients2').css('backgroundImage', 'url(images/ourClientBgTop.jpg)');
	$('#subLogin2').css('backgroundImage', 'url(images/wBG.png)');
	$('#subMybeeLab2').css('backgroundImage', 'url(images/ourClientBgTop.jpg)');	
  }else {	
	$('#headerBG').css('backgroundImage', 'url(images/wBG.png)');	
	$('#footerBG').css('backgroundImage', 'url(images/wBG.png)');	
	$('#subAboutMybee2').css('backgroundImage', 'url(images/wBG.png)');	
	$('#subOurClients2').css('backgroundImage', 'url(images/wBG.png)');	
	$('#subLogin2').css('backgroundImage', 'url(images/wBG.png)');	
	$('#subMybeeLab2').css('backgroundImage', 'url(images/wBG.png)');
  }
}

function solganOut(){
  if($('#solganDiv').css('top')!='-200px'){	
	if(!$.browser.msie||$.browser.version>=9){	   
	  $('#solganDiv').animate({'opacity': '0','top':'-200px'}, 1000);
	}else{
	  $('#solganDiv').animate({'top':'-200px'}, 1000);
	}
  }
}  

function menuUnderLine(trg){
  uPost=[[48,46,1,0],[48,47,101,1],[63,300,98,1],[63,440,85,1],[63,565,82,1]]
  $('#underline').animate({'top':uPost[trg][0]+'px','left':uPost[trg][1]+'px','width':uPost[trg][2]+'px','opacity':uPost[trg][3]}, 1000);	  
}

function showLoading(act){
  if(act=='show'){
	$('#loadingDiv').css('display', 'block');	
	if(!$.browser.msie||$.browser.version>=9){
	  $('#loadingDiv').animate({'opacity': '.7'}, 600);
	}
  }else if(act=='hide'){
	if(!$.browser.msie||$.browser.version>=9){
	  $('#loadingDiv').animate({'opacity': '0'}, 600, function(){$('#loadingDiv').css('display', 'none');});
	}else{
	  $('#loadingDiv').css('display', 'none');
	}
  }
} 
  
function ModeA(){	
  $('#headerBG').animate({"height": '97px' }, 1000);
  $('#headerBody1').animate({"height": '97px'},1000);
  $('#headerBody2').animate({"height": '97px'},1000);
  
  $('#headerMenu').animate({"width": '905px'},1000);	
  $('#menuSpaceTop').animate({"height": '24px'},1000);
  $('menuSpaceButtom').animate({"height": '24px'},1000);
  $('#menuSpace1').animate({"width": '38px'},1000);
  $('#menuSpace2').animate({"width": '38px'},1000);
  $('#menuSpace3').animate({"width": '38px'},1000);
  $('#menuSpace4').animate({"width": '38px'},1000);
  $('#menuSpace5').animate({"width": '38px'},1000);	
  
  $('#logoDiv').animate({'left': '57px','top': '8px'},1000);
  $('#logo').animate({'width': '75px','height': '81px'},500);
	  
  $('#subAboutMybee').animate({'top': '25px','left': '148px'},1000);
  $('#subOurClients').animate({'top': '25px','left': '422px'},1000);
  $('#subLogin').animate({'top': '25px','left': '661px'},1000);
  $('#subMybeeLab').animate({'top': '25px','left': '840px'},1000);
}

function ModeB(){
  $('#headerBG').animate({"height": '67px' }, 1000);
  $('#headerBody1').animate({"height": '67px'},1000);
  $('#headerBody2').animate({"height": '67px'},1000);
  
  $('#headerMenu').animate({"width": '1020px'},1000);
  $('#menuSpaceTop').animate({"height": '9px'},1000);
  $('menuSpaceButtom').animate({"height": '10px'},1000);
  $('#menuSpace1').animate({"width": '61px'},1000);
  $('#menuSpace2').animate({"width": '61px'},1000);
  $('#menuSpace3').animate({"width": '61px'},1000);
  $('#menuSpace4').animate({"width": '61px'},1000);
  $('#menuSpace5').animate({"width": '61px'},1000);	
  
  $('#subAboutMybee').animate({'top': '10px','left': '35px'},1000);
  $('#subOurClients').animate({'top': '10px','left': '355px'},1000);
  $('#subLogin').animate({'top': '10px','left': '639px'},1000);
  $('#subMybeeLab').animate({'top': '10px','left': '840px'},1000);
}

function afterAnimate(trg){
  defPos(trg);		
  $('#bgBody').animate({'opacity': '1'}, 1000);
  showLoading('hide');
  setTimeout("document.getElementById('loadingDiv').style.display = 'none'" , 1100);	
} 

function resizeWindow(){	
  //resizeBG();	
  if(currentPage=='homeStart'){
	defPos('home');	
  }else{
	defPos(currentPage);	
  }
}

/*function resizeBG(){	
  $('#bgBody').height($(window).height())
  //document.getElementById("bgBody").style.height = $(window).height()+'px';	
}*/ 

function defPos(trg){	
  if(trg!='none'){
	// logo & content
	if($.browser.msie&&$.browser.version<=6){		
	  ie6Resize();
	}else if(trg=='homeStart'){
	  $('#logoDiv').css('top', ($(window).height()/2 - 93)+'px');
	}else if(trg=='home'){
	  $('#logoDiv').css('top', ($(window).height()/2 - 93)+'px');
	  $('#solganDiv').css('top', ($(window).height()/2)-47 +'px');
	}else if(trg=='aboutMybee'){		
	  $('#logoDiv').css('top', ($(window).height()/2 - 176)+'px');
	  $('#contentBody3').css('top', ($(window).height()-415)/2+'px');
	}else if(trg=='ourMission'){		
	  $('#logoDiv').css('top', ($(window).height()/2 + 50)+'px');
	  $('#contentBody3').css('top', ($(window).height()-440)/2+'px');
	}else if(trg=='ourService'){
	  $('#contentMenu').css('top', $(window).height()-160+'px');
	  $('#contentBody3').css('top', ($(window).height()-488)/2+'px');
	}else if(trg=='ourClients'){
	  $('#scrollBar').css('height', $(window).height()-249+'px');
	  $('#scrollBarBG').css('height', $(window).height()-275+'px');		
	  $('#contentBody3').css('height', $(window).height()+'px');
	  scroll_Resize();
	  ourClientsiPadGuide('');
	}else if(trg=='ourProjects'){
	  $('#contentBody1').css('height', $(window).height()+'px');
	  $('#contentBody3').css('top', ($(window).height()-380)/2+'px');
	  if($('#lightBox').css('display')=='block'){
		resizeLightBox();
	  }
	}else if(trg=='contactUs'){
	  $('#contentBody3').css('top', ($(window).height()-367)/2+'px');
	  resizeContactUs();  
	}	  
	// background
	if(trg=='ourProjects'||trg=='contactUs'){
	  $('#bgCover').css('height', $(window).height()+'px');
	}
	$('#bgDiv').css('height', $(window).height()+'px');
	$('#contentBody1').css('height', $(window).height()+'px');
	$('#contentBody1').css('overflow', 'hidden');
  }
}

function ie6Resize(){	
  $('#noIE').css('height', $(window).height()+'px');
  $('#noIEContent').css('left', ($(window).width()-620)/2+'px');
  $('#noIEContent').css('top', ($(window).height()-390)/2+'px');
  $('#noIEBG').css('width', $(window).width()+'px');
  $('#noIEBG').css('height', $(window).height()+'px');	 	
}

function showMenu(trg, act){
  subMenuList=['subAboutMybee', 'subOurClients','subLogin','subMybeeLab'];
  transTime=400;
  if (act=='show'){
	for(a=0; a<subMenuList.length; a++){
	  if(trg==subMenuList[a]){
		$('#'+trg).css('display', 'block');
		if(!$.browser.msie||$.browser.version>=9){
		  $('#'+trg).animate({"opacity": '1'},transTime);
		}
	  }else{
		showMenu(subMenuList[a], 'hide');
	  }
	}		  
  }else if (act=='hide'){
	if(trg=='all'){
	  for(a=0; a<subMenuList.length; a++){
		showMenu(subMenuList[a], 'hide');
	  }
	}else{
	  if(!$.browser.msie||$.browser.version>=9){
		$('#'+trg).animate({"opacity": '0'},transTime, function(){$('#'+trg).css('display', 'none')}); 
	  }else{
		$('#'+trg).css('display', 'none'); 
	  }
	}
  }
}  

function debugMSG(msg){
  $('#debugDIV').html(msg);	  
}

function  checkIOS(){  
  var agent=navigator.userAgent.toLowerCase();
  var is_iphone = ((agent.indexOf('iphone') != -1));
  var is_ipad = ((agent.indexOf('ipad') != -1));    
  if(is_iphone || is_ipad){
	// location.reload(true);
	window.onorientationchange = resizeWindow;
  } else {     
	window.onresize = resizeWindow;
  }; 
}
