/* ----------------------------------
index.js
---------------------------------- */

$(function(){
	
	/*--------------------------------------------------
	loading
	--------------------------------------------------*/
	var $loading = $("#loading");
	var $nowloading = $("#nowloading");
	var list = 
	[
		"images/stage_philosophy.png",
		"images/stage_message.png",
		"images/stage_business.png",
		"images/stage_separate.png",
		"images/stage_division.png",
		"images/stage_profile.png",
		"images/stage_projects.png",
		"images/stage_newgraduate.png",
		"images/stage_career.png",
		"images/stage_contact.png",
		"images/philosophy_people.png",
		"images/philosophy_people2.png",
		"images/philosophy_people3.png",
		"images/separate_people.png",
		"images/profile_people.png",
		"images/projects_people1.png",
		"images/projects_people2.png",
		"images/career_people.png",
		"images/contact_people.png",
		"images/image_door.png",
		"images/image_communication.gif",
		"images/image_communicationR.gif",
		"images/image_communicationL.gif",
		"images/image_startdoor.png",
		"images/image_flying.png",
		"images/image_bubble.png",
		"images/image_elevator.png",
		"images/image_cable.png",
		"images/image_smoke.png",
		"images/image_airplane.png",
		"images/image_sun.png",
		"images/image_train.png",
		"images/image_lastdoor.png"
	];
	
	
	/*--- preloader ----------*/
	var preloader = new Loader(list, function()
	{
		//XMLLoad
		XMLLoad(0);
	});
	
	/*--- resize ----------*/
	var resizeHandler = function()
	{
		$nowloading.css("left", $(window).width() / 2 - $nowloading.width() / 2);
		$nowloading.css("top", $(window).height() / 2 - $nowloading.height() / 2);
	}
	resizeHandler();
	$(window).resize(resizeHandler);
	preloader.load();
	
	/*--------------------------------------------------
	Init
	--------------------------------------------------*/
	var Init = function()
	{
		
		$("header").show();
		$("header:not(animated)").animate({marginTop:"0px"},"slow");
		$("footer").show();
		$("#wrapper").fadeIn(1500);
		$loading.fadeOut(1500);
		
		/*---------------------------------
		bubble
		---------------------------------*/
		var i = 0;
		(function move(){
			i = i > 0 ? -1 : 1;
			var p = $("#bubble").position().top;
			$("#bubble").animate({ top: p + i * 20 }, { 
				duration: 1400,
				complete: move
			});
		})();
		
		/*--------------------------------------------------
		project window
		--------------------------------------------------*/
		$(".prjwin").fancybox(
		{
			'width':900,
			'height':500,
			'type'				: 'iframe',
			'titlePosition'		: 'inside',
			'transitionIn'		: 'fade',
			'transitionOut'		: 'fade',
			'overlayColor'		: '#000',
			'autoScale'			: false,
			'overlayOpacity'	: 0.6
		});
		
		
		/*--------------------------------------------------
		mCustomScrollbar
		--------------------------------------------------*/
		$("#message_scrollbox").mCustomScrollbar("vertical",400,"easeOutCirc",1.05,"fixed","yes","yes",10);
		$("#career_scrollbox").mCustomScrollbar("vertical",400,"easeOutCirc",1.05,"fixed","yes","no",10);
	}
	
	
	/*--------------------------------------------------
	XMLLoad
	--------------------------------------------------*/
	var XMLLoad = function(num)
	{
		//var xmlList=["xml/message.xml","xml/profile.xml","xml/recruit_newgraduate.xml","xml/recruit_career.xml","xml/news.xml","xml/projects.xml","xml/business_creative.xml","xml/business_social.xml","xml/business_business.xml"];
		var xmlList=["data/messagexml","data/profilexml","data/newgraduatexml","data/careerxml","data/newsxml","data/projectsxml","data/business_creativexml","data/business_socialxml","data/business_businessxml","data/topbannerxml"];
		
		$.ajax({
			url:xmlList[num],
			dataType:"xml",
			success:function(data){
				
				switch(num){
					
					//--------------topMessage
					case 0:
					  $("item",data).each(function(){
						  $("#contents-message dd").append("<img src='img/message_topname.png' width='127' height='40' alt='"+$("name",this).text()+"'>")
						  $("#contents-message .content").append($("message",this).text())
					  })
					  
					break;
					
					//--------------profile
					case 1:
					  $("item",data).each(function(){
						  $("#contents-profile span").append($("txt",this).text())
					  })
					break;
					
					//--------------newgraduate
					case 2:
					  $("item",data).each(function(){
						  $("#contents-newgraduate span").append($("txt",this).text())
					  })
					break;
					
					//--------------career
					case 3:
					  $("item",data).each(function(){
						  $("#contents-career .content").append($("txt",this).text())
					  })
					break;
					
					//--------------news
					case 4:
					  var i=0;
					  $("item",data).each(function(){
						  var str="<dl>";
						  str=str+"<dt>"+$("date",this).text()+"</dt>";
						  str=str+"<dd><img src='images/icon_news.gif'><a href='news.html?pScnews"+i+"'>"+$("title",this).text()+"</a></dd>";
						  str=str+"</dl>";
						  $("#top .news").append(str);
						  i++;
					  })
					break;
					
					//--------------projects
					case 5:
					  var ct=0;
					  var items=$("item",data);
					  var length=items.length;
					  var str="";
					  for(var i=0;i<24;i++){
						  if(ct==0){
							  str=str+"<ul class='projects'>";
						  }
						  str=str+"<li class='thumb'>";
						  if(i<length){
							  str=str+"<a href='"+$("url",items[i]).text()+"' class='prjwin' rel='projectsgroup'>";
							  str=str+"<img src='"+$("img",items[i]).text()+"' width='60' height='60' class='dot' alt=''></a>";
						  }else{
							  str=str+"<img src='images/icon_none.gif'>";
						  }
						  str=str+"</li>";
						  ct++;
						  if(ct==8){
							  str=str+"</ul>";
							  ct=0;
						  }
					  }
					  $("#contents-projects").append(str);
					break;
					
					//--------------business creative
					case 6:
					  var items=$("item",data);
					  var length=items.length;
					  if(length>0){
					  var str="<ul class='projects'><li>主な事例：</li>";
					  for(var i=0;i<length;i++){
						  str=str+"<li class='thumb'>";
						  str=str+"<a href='"+$("url",items[i]).text()+"' class='prjwin' rel='creativegroup'>";
						  str=str+"<img src='"+$("img",items[i]).text()+"' width='60' height='60' class='dot' alt=''></a>";
						  str=str+"</li>";
					  }
					  str=str+"</ul>";
					  $("#contents-business .section1").append(str);
					  }
					break;
					
					//--------------business creative
					case 7:
					  var items=$("item",data);
					  var length=items.length;
					  if(length>0){
					  var str="<ul class='projects'><li>主な事例：</li>";
					  for(var i=0;i<length;i++){
						  str=str+"<li class='thumb'>";
						  str=str+"<a href='"+$("url",items[i]).text()+"' class='prjwin' rel='socialgroup'>";
						  str=str+"<img src='"+$("img",items[i]).text()+"' width='60' height='60' class='dot' alt=''></a>";
						  str=str+"</li>";
					  }
					  str=str+"</ul>";
					  $("#contents-business .section2").append(str);
					  }
					break;
					
					//--------------business creative
					case 8:
					  var items=$("item",data);
					  var length=items.length;
					  if(length>0){
					  var str="<ul class='projects'><li>主な事例：</li>";
					  for(var i=0;i<length;i++){
						  str=str+"<li class='thumb'>";
						  str=str+"<a href='"+$("url",items[i]).text()+"' class='prjwin' rel='businessgroup'>";
						  str=str+"<img src='"+$("img",items[i]).text()+"' width='60' height='60' class='dot' alt=''></a>";
						  str=str+"</li>";
					  }
					  str=str+"</ul>";
					  $("#contents-business .section3").append(str);
					  }
					break;
					
					//--------------top banner
					case 9:
					  $("item",data).each(function(){
						  $("#contents-top .banner").append($("txt",this).text())
					  })
					break;
					
				}
		
				
				num=num+1;
				if(num<xmlList.length){
					XMLLoad(num);
				}else{
					//Init
					Init();
				}
				
			}
		});
		
	}
	
	
});



/*--------------------------------------------------
Change Image
--------------------------------------------------*/
var profileImg=0;
var contactImg=0;
function ChangeProfile(){
	profileImg++;
	if(profileImg>2)profileImg=0;
	$('#stage-profile .people-monitor a').css('background-image', 'url(images/profile_monitorpeople'+profileImg+'.png)');
	$('#stage-contact .monitor').css('background-image', 'url(images/contact_monitor'+profileImg+'.png)');
}
function ChangeContact(){
	contactImg++;
	if(contactImg>2)contactImg=0;
	$('#stage-contact .people-monitor a').css('background-image', 'url(images/contact_monitorpeople'+contactImg+'.png)');
	$('#stage-profile .monitor').css('background-image', 'url(images/profile_monitor'+contactImg+'.png)');
}
