function homeInit()
{
	if (textMode)	return;
	new genLatestNews();
	new genStory();
	new genEBanner();
	new changeList(0);
}

//Generate Latest News
function genLatestNews()
{
	var container = d.getElementById('newsDetailWrapper');
	var nav = d.getElementById('newsBtnWrapper');
	var txtArray = container.getElementsByTagName('div');
	var total = txtArray.length;
	var navList = new Array();
	var highlightA;
	var section;
	var self = this;
	
	this.init = function()
	{
		for (var i=0; i<total; i++)
		{
			txtArray[i].className = 'news_' + i;
		};
		
		this.genNav();
	};
	
	this.genNav = function()
	{
		for (var i=0; i<total; i++)
		{
			var a = createA('javascript:;', '');
			a.num = i;
			
			a.onclick = function()
			{
				self.changeNav(this);
			};
			
			nav.appendChild(a);
			navList.push(a);
		}
		
		self.changeNav(navList[0]);
	};
	
	this.changeNav = function(btn)
	{
		if (highlightA)	highlightA.className = highlightA.className.replace(/active/, '');
		btn.className += ' active';
		
		//Show Text
		if (!isNaN(section))	txtArray[section].style.display = 'none';
		txtArray[btn.num].style.display = 'block';
		
		//FadeIn
		$('#newsDetailWrapper .news_' + btn.num).css({'opacity':0});
		$('#newsDetailWrapper .news_' + btn.num).animate({'opacity':1}, 200);
		
		section = btn.num;
		highlightA = btn;
	};
	
	this.init();
}

//Generate Story
function genStory()
{
	//Nav Part
	var container = d.getElementById('overlookingPart');
	var navMask = getElementsByClassName(container, 'themeChoice')[0];
	var nav = getElementsByClassName(navMask, 'navContainer')[0];
	var arrowL = getElementsByClassName(container, 'arrowL')[0];
	var arrowR = getElementsByClassName(container, 'arrowR')[0];
	var navList = nav.getElementsByTagName('a');
	var total = navList.length;
	var curIndex = 0;
	var highlightA;
	var section;
	var tmpSection;
	var tmpContainer;
	var navReady = true;
	
	var navArray = new Array();
	var navShowTotal = 4;
	var navGoTotal = total - navShowTotal;
	var LIndex = 0;
	var RIndex = navShowTotal - 1;
	var autoMode;
	var time = 10000;
	//var time = 15000;
	var timeout;
	
	//Text Part
	var txtContainer = d.getElementById('noticeContainerBtm');
	var titleArray = txtContainer.getElementsByTagName('h2');
	var txtArray = txtContainer.getElementsByTagName('p');
	
	//Bg image
	var mainImage = d.getElementById('mainImage');
	
	var self = this;
	
	this.init = function()
	{
		tmpContainer = createDiv();
		
		$('#noticeContainerBtm').css({'display':'none'});
		
		for (var i=0; i<total; i++)
		{
			titleArray[i].className = 'title_' + i;
			txtArray[i].className = 'txt_' + i;
		}
		
		this.setNav();
		//new slider(navMask, nav, arrowR, arrowL);
		
		if (total == 1)
		{
			nav.style.display = 'none';
			autoMode = 0;
		}
		if (total <= navShowTotal)
		{
			arrowL.style.display = 'none';
			arrowR.style.display = 'none';
			autoMode = 1;
		}
		else
		{
			this.setSlide();
			autoMode = 2;
		}
		
		//this.autoMotion(false);
	};
	
	this.setNav = function()
	{
		for (var i=0; i<total; i++)
		{
			var a = navList[i];
			
			a.num = i;
			a.img = a.getElementsByTagName('img')[0];
			//a.imgOld = a.img.src;
			//a.imgNew = a.imgOld.replace('.jpg', '_on.jpg');
			
			if (i == total - 1)	a.className = 'last';
			
			a.onclick = function()
			{
				if (!navReady)	return;
				self.changeNav(this, true);
			};
			
			navArray.push(a);
		}
		
		//Set Width
		//nav.style.width = (total*47) + 'px';
		
		//Hidden Nav
		for (var i=0; i<navArray.length; i++)
		{
			var a = navArray[i];
			if (i >= navShowTotal)
			{
				tmpContainer.appendChild(a);
			}
		}
		
		//Set Width
		nav.style.width = ((navShowTotal + 1)*47) + 'px';
		
		self.changeNav(navList[0], false);
	};
	
	this.changeNav = function(btn, showTxt)
	{
		navReady = false;
		
		if (highlightA)
		{
			highlightA.className = highlightA.className.replace(/active/, '');
			//highlightA.img.src = highlightA.imgOld;
		}
		btn.className += ' active';
		//btn.img.src = btn.imgNew;
		
		if (btn.num != section)
		{
			//FadeOut
			$('#mainImage ').animate({'opacity':0}, 300, '', function()
			{
				//Change Img
				mainImage.style.backgroundImage = 'url(' + storyArray[btn.num].img + ')';
				
				setTimeout(function()
				{
					//FadeIn
					$('#mainImage').css({'opacity':0});
					$('#mainImage ').animate({'opacity':1}, 300);
				}, 200);
			});
			
			//FadeOut
			if (!isNaN(section) && (txtContainer.style.display == 'block' || showTxt))
			{
				//$('#noticeContainerBtm .title_' + section).animate({'opacity':0}, 200);
				//$('#noticeContainerBtm .txt_' + section).animate({'opacity':0}, 200);
				if (!isIE8 && !isIE7)
				{
					$('#noticeContainerBtm').animate({'opacity':0}, 200);
					//$('.jScrollPaneContainer .jScrollPaneTrack').animate({'opacity':0}, 200);
				}
				else
				{
					$('#noticeContainerBtm').css({'display':'none'});
					//$('.jScrollPaneContainer .jScrollPaneTrack').css({'display':'none'});
				}
			}
		}
		
		if (showTxt)
		{
			setTimeout(function()
			{
				if (!isIE8 && !isIE7)
				{
					$('#noticeContainerBtm').css({'opacity':0, 'display':'block'});
				}
				else
				{
					$('#noticeContainerBtm').css({'display':'block'});
				}
				
				//Show Text
				/*if (!isNaN(tmpSection))
				{
					titleArray[tmpSection].style.display = 'none';
					txtArray[tmpSection].style.display = 'none';
				}*/
				//Hide All
				for (var i=0; i<total; i++)
				{
					titleArray[i].style.display = 'none';
					txtArray[i].style.display = 'none';
				}
				titleArray[btn.num].style.display = 'block';
				txtArray[btn.num].style.display = 'block';
				
				//Scroll
				$('#noticeList').css({'top':0});
				$('#noticeList').jScrollPane({animateTo:true, dragMinHeight:26, dragMaxHeight:26, scrollbarMargin:10, scrollbarWidth:3, animateInterval:10, animateStep:5 /*,showArrows:true*/});
				
				
				
				//FadeIn
				//$('#noticeContainerBtm .title_' + btn.num).css({'opacity':0});
				//$('#noticeContainerBtm .title_' + btn.num).animate({'opacity':1}, 300);
				//$('#noticeContainerBtm .txt_' + btn.num).css({'opacity':0});
				//$('#noticeContainerBtm .txt_' + btn.num).animate({'opacity':1}, 300);
				if (!isIE8 && !isIE7)	$('#noticeContainerBtm').animate({'opacity':1}, 300);
				
				navReady = true;
			}, ((btn.num != section)?1000:0));
		}
		
		tmpSection = section;
		section = btn.num;
		highlightA = btn;
		//this.autoMotion(showTxt);
		
		if (!showTxt)	navReady = true;
	};
	
	this.setSlide = function()
	{
		arrowL.onclick = function()
		{
			if (!navReady)	return;
			self.goNav(-1);
		}
		arrowR.onclick = function()
		{
			if (!navReady)	return;
			self.goNav(1);
		}
	};
	
	this.goNav = function(index)
	{
		navReady = false;
		
		var offsetX = 47;
		
		curIndex += index;
		if (curIndex > navGoTotal)	curIndex = 0;
		if (curIndex < 0)			curIndex = navGoTotal;
		
		//Change Section
		setTimeout(function()
		{
			var nextSection = section + index;
			if (nextSection >= total)	nextSection = 0;
			if (nextSection < 0)		nextSection = total - 1;
			self.changeNav(navArray[nextSection], false);
			//navReady = true;
		}, 300);
		
		RIndex += index;
		if (RIndex >= total)	RIndex = 0;
		if (RIndex < 0)			RIndex = total - 1;
		
		LIndex += index;
		if (LIndex >= total)	LIndex = 0;
		if (LIndex < 0)			LIndex = total - 1;
		//d.title = (LIndex + '  :  ' + RIndex);
		
		if (index > 0)
		{
			var preIndex = RIndex - navShowTotal;
			if (preIndex < 0)	preIndex = RIndex + navGoTotal;
			//d.title = (preIndex + '  :  ' + RIndex);
			
			var nextItem = navArray[RIndex];
			var prevItem = navArray[preIndex];
			
			nav.appendChild(nextItem);
			$('#overlookingPart .navContainer').animate({'left':-offsetX}, 250, function()
			{
				tmpContainer.appendChild(prevItem);
				$('#overlookingPart .navContainer').css({'left':0});
			});
		}
		else
		{
			var preIndex = LIndex - navGoTotal;
			if (preIndex < 0)	preIndex = LIndex + navShowTotal;
			//d.title = (LIndex + '  :  ' + preIndex);
			
			var nextItem = navArray[LIndex];
			var prevItem = navArray[preIndex];
			
			nav.insertBefore(nextItem, nav.getElementsByTagName('a')[0]);
			$('#overlookingPart .navContainer').css({'left':-offsetX});
			$('#overlookingPart .navContainer').animate({'left':0}, 250, function()
			{
				tmpContainer.appendChild(prevItem);
			});
		}
	};
	
	this.autoMotion = function(noLoop)
	{
		if (noLoop)
		{
			clearTimeout(timeout);
			return;
		}
		if (!autoMode)	return;
		
		clearTimeout(timeout);
		
		if (autoMode == 1)
		{
			this.autoChange();
		}
		else
		{
			this.autoSlide();
		}
	};
	
	this.autoChange = function()
	{
		timeout = setInterval(function()
		{
			var nextSection = section + 1;
			if (nextSection >= total)	nextSection = 0;
			if (nextSection < 0)		nextSection = total - 1;
			self.changeNav(navArray[nextSection], false);
		}, time);
	};
	
	this.autoSlide = function()
	{
		timeout = setInterval(function()
		{
			self.goNav(1);
		}, time);
	};
	
	this.init();
}

//Generate Story
function genEBanner()
{
	//Nav Part
	var container = d.getElementById('projectPart');
	var navMask = getElementsByClassName(container, 'themeChoice')[0];
	var nav = getElementsByClassName(navMask, 'navContainer')[0];
	var arrowL = getElementsByClassName(container, 'arrowL')[0];
	var arrowR = getElementsByClassName(container, 'arrowR')[0];
	var navList = nav.getElementsByTagName('a');
	var navArray = new Array();
	var total = navList.length;
	var navShowTotal = 5;
	var navGoTotal = total - navShowTotal;
	var LIndex = 0;
	var RIndex = navShowTotal - 1;
	var curIndex = 0;
	var highlightA;
	var section;
	var tmpSection;
	var tmpContainer;
	var autoMode;
	var time = 5000;
	var timeout;
	var navReady = true;
	
	//Text Part
	var detailsContainer = d.getElementById('projectItemWrapper');
	var detailsArray = detailsContainer.getElementsByTagName('div');
	
	//Bg image
	var mainImage = d.getElementById('mainImage');
	
	var self = this;
	
	this.init = function()
	{
		tmpContainer = createDiv();
		
		for (var i=0; i<total; i++)
		{
			detailsArray[i].className = 'details_' + i;
		}
		
		this.setNav();
		
		if (total == 1)
		{
			nav.style.display = 'none';
			autoMode = 0;
		}
		if (total <= navShowTotal)
		{
			arrowL.style.display = 'none';
			arrowR.style.display = 'none';
			autoMode = 1;
		}
		else
		{
			this.setSlide();
			autoMode = 2;
		}
		
		container.onmouseover = function()
		{
			clearTimeout(timeout);
			//d.title = 'over';
		};
		container.onmouseout = function()
		{
			self.autoMotion();
			//d.title = 'out';
		};
		
		this.autoMotion();
	};
	
	this.setNav = function()
	{
		for (var i=0; i<total; i++)
		{
			var a = navList[i];
			
			a.num = i;
			a.img = a.getElementsByTagName('img')[0];
			a.imgOld = a.img.src;
			//a.imgNew = a.imgOld.replace('.jpg', '_on.jpg');
			
			a.imgNew = a.imgOld;
			if (a.getElementsByTagName('img').length > 1)
			{
				var img = a.getElementsByTagName('img')[1];
				a.imgNew = img.src;
				img.parentNode.removeChild(img);
			}
			
			//if (i == total - 1)	a.className = 'last';
			
			a.onclick = function()
			{
				if (!navReady)	return;
				self.changeNav(this);
			};
			
			navArray.push(a);
		}
		
		//Hidden Nav
		for (var i=0; i<navArray.length; i++)
		{
			var a = navArray[i];
			if (i >= navShowTotal)
			{
				tmpContainer.appendChild(a);
			}
		}
		
		//Set Width
		nav.style.width = ((navShowTotal + 1)*47) + 'px';
		
		self.changeNav(navList[0]);
	};
	
	this.changeNav = function(btn)
	{
		navReady = false;
		
		if (highlightA)
		{
			highlightA.className = highlightA.className.replace(/active/, '');
			highlightA.img.src = highlightA.imgOld;
		}
		btn.className += ' active';
		btn.img.src = btn.imgNew;
		
		//FadeOut
		if (!isNaN(section))
		{
			$('#projectItemWrapper .details_' + section).animate({'opacity':0}, 200, '', function()
			{
				detailsArray[tmpSection].style.display = 'none';
				
				setTimeout(function()
				{
					detailsGo();
				}, 0);
			});
		}
		else
		{
			detailsGo();
		}
		
		function detailsGo()
		{
			detailsArray[btn.num].style.display = 'block';
			
			//FadeIn
			$('#projectItemWrapper .details_' + btn.num).css({'opacity':0});
			$('#projectItemWrapper .details_' + btn.num).animate({'opacity':1}, 300);
			
			navReady = true;
			section = btn.num;
			highlightA = btn;
		}
		
		this.autoMotion();
		tmpSection = section;
	};
	
	this.setSlide = function()
	{
		arrowL.onclick = function()
		{
			if (!navReady)	return;
			self.goNav(-1);
		}
		arrowR.onclick = function()
		{
			if (!navReady)	return;
			self.goNav(1);
		}
	};
	
	this.goNav = function(index)
	{
		navReady = false;
		
		var offsetX = 47;
		
		curIndex += index;
		if (curIndex > navGoTotal)	curIndex = 0;
		if (curIndex < 0)			curIndex = navGoTotal;
		
		//Change Section
		setTimeout(function()
		{
			var nextSection = section + index;
			if (nextSection >= total)	nextSection = 0;
			if (nextSection < 0)		nextSection = total - 1;
			self.changeNav(navArray[nextSection]);
			//navReady = true;
		}, 300);
		
		RIndex += index;
		if (RIndex >= total)	RIndex = 0;
		if (RIndex < 0)			RIndex = total - 1;
		
		LIndex += index;
		if (LIndex >= total)	LIndex = 0;
		if (LIndex < 0)			LIndex = total - 1;
		//d.title = (LIndex + '  :  ' + RIndex);
		
		if (index > 0)
		{
			var preIndex = RIndex - navShowTotal;
			if (preIndex < 0)	preIndex = RIndex + navGoTotal;
			//d.title = (preIndex + '  :  ' + RIndex);
			
			var nextItem = navArray[RIndex];
			var prevItem = navArray[preIndex];
			
			nav.appendChild(nextItem);
			$('#projectPart .navContainer').animate({'left':-offsetX}, 250, function()
			{
				tmpContainer.appendChild(prevItem);
				$('#projectPart .navContainer').css({'left':0});
			});
		}
		else
		{
			var preIndex = LIndex - navGoTotal;
			if (preIndex < 0)	preIndex = LIndex + navShowTotal;
			//d.title = (LIndex + '  :  ' + preIndex);
			
			var nextItem = navArray[LIndex];
			var prevItem = navArray[preIndex];
			
			nav.insertBefore(nextItem, nav.getElementsByTagName('a')[0]);
			$('#projectPart .navContainer').css({'left':-offsetX});
			$('#projectPart .navContainer').animate({'left':0}, 250, function()
			{
				tmpContainer.appendChild(prevItem);
			});
		}
	};
	
	this.autoMotion = function()
	{
		if (!autoMode)	return;
		
		clearTimeout(timeout);
		
		if (autoMode == 1)
		{
			this.autoChange();
		}
		else
		{
			this.autoSlide();
		}
	};
	
	this.autoChange = function()
	{
		timeout = setInterval(function()
		{
			var nextSection = section + 1;
			if (nextSection >= total)	nextSection = 0;
			if (nextSection < 0)		nextSection = total - 1;
			self.changeNav(navArray[nextSection]);
		}, time);
	};
	
	this.autoSlide = function()
	{
		timeout = setInterval(function()
		{
			self.goNav(1);
		}, time);
	};
	
	this.init();
}

//change to List / Thumbnail
function changeList() {
	var switchBtnPart = d.getElementById('switchPart');
	var switchA = switchBtnPart.getElementsByTagName('A');
	
	for (i=0; i<switchA.length; i++) {
		
		switchA[i].num = i;
		switchA[i].onclick = function() {
			
			
			btnOver(this);	
		}
	}
	
	function btnOver(btn) {
			var listPart = d.getElementById('listWrapper');
			var thumbPart = d.getElementById('projectItemWrapper');
			var thumbPartChoice = d.getElementById('thumbChoice');			
			var currBtnNum = btn.num;
			
			
			
			for (j=0; j<switchA.length; j++) {
				switchA[j].className = '';
				
			}
			
			listPart.style.display = 'none';
			thumbPart.style.display = 'none';
			thumbPartChoice.style.display = 'none';
			
			
			
			if (btn.id == 'listV') {
				$(listPart).css({'opacity':0});
   				$(listPart).animate({'opacity':1}, 300);	
				listPart.style.display = 'block';
				
				$('#noticeList2').css({'top':0});
				$('#noticeList2').jScrollPane({animateTo:true, dragMinHeight:26, dragMaxHeight:26, scrollbarMargin:10, scrollbarWidth:3, animateInterval:10, animateStep:5 /*,showArrows:true*/})
				
			}
			
			if (btn.id == 'thumbV') {
				$(thumbPart).css({'opacity':0});
   				$(thumbPart).animate({'opacity':1}, 300);
				thumbPart.style.display = 'block';
				thumbPartChoice.style.display = 'block';
				 
			}
			btn.className = 'active';
			
	}
	
	btnOver(switchA[0]);
	
}



