var component = {
	checkCommonDir: function(){
		var dirPath = '';
		var head = document.getElementsByTagName('head')[0];
		var scripts = head.getElementsByTagName('script');
		if(head && scripts){
			for(var s = 0,num = scripts.length; s < num; s++){
				if(scripts[s].src.indexOf('common.js') >= 0){
					dirPath = scripts[s].src.split('js/common.js')[0];
				}
			}
		}
		return dirPath;
	},
	fontChanger: {
		setting: {
			fontSmall		:	'90%',
			fontMidium		:	'100%',
			fontLarge		:	'120%',
			fontSmallText	:	'\u30D5\u30A9\u30F3\u30C8\u30B5\u30A4\u30BA\u005B\u5C0F\u005D',
			fontMidiumText	:	'\u30D5\u30A9\u30F3\u30C8\u30B5\u30A4\u30BA\u005B\u4E2D\u005D',
			fontLargeText	:	'\u30D5\u30A9\u30F3\u30C8\u30B5\u30A4\u30BA\u005B\u5927\u005D'
		},
		setSize: false,
		writeBtns: function(){
			if(!component.isMacIE()){
				if($('home')){
					var imgInName = 'top_';
				}else{
					var imgInName = '';
				}
				
				var dd1 = document.createElement('dd');
				var dd2 = document.createElement('dd');
				var dd3 = document.createElement('dd');
				if(this.setSize){
					if(this.setSize == this.setting.fontSmall){
						var dda1 = '<a href="#" onclick="component.fontChanger.change(\'' + this.setting.fontSmall + '\',this);return false;"><img src="' + dirPath + 'images/' + imgInName + 'btn_size_s_h.gif" alt="' + this.setting.fontSmallText + '" width="22" height="16" /></a>\n'
					}else{
						var dda1 = '<a href="#" onclick="component.fontChanger.change(\'' + this.setting.fontSmall + '\',this);return false;"><img src="' + dirPath + 'images/' + imgInName + 'btn_size_s_f.gif" alt="' + this.setting.fontSmallText + '" width="22" height="16" /></a>\n'
					}
					if(this.setSize == this.setting.fontMidium){
						var dda2 = '<a href="#" onclick="component.fontChanger.change(\'' + this.setting.fontMidium + '\',this);return false;"><img src="' + dirPath + 'images/' + imgInName + 'btn_size_m_h.gif" alt="' + this.setting.fontMidiumText + '" width="25" height="22" /></a>\n'
					}else{
						var dda2 = '<a href="#" onclick="component.fontChanger.change(\'' + this.setting.fontMidium + '\',this);return false;"><img src="' + dirPath + 'images/' + imgInName + 'btn_size_m_f.gif" alt="' + this.setting.fontMidiumText + '" width="25" height="22" /></a>\n'
					}
					if(this.setSize == this.setting.fontLarge){
						var dda3 = '<a href="#" onclick="component.fontChanger.change(\'' + this.setting.fontLarge + '\',this);return false;"><img src="' + dirPath + 'images/' + imgInName + 'btn_size_l_h.gif" alt="' + this.setting.fontLargeText + '" width="30" height="26" /></a>\n'
					}else{
						var dda3 = '<a href="#" onclick="component.fontChanger.change(\'' + this.setting.fontLarge + '\',this);return false;"><img src="' + dirPath + 'images/' + imgInName + 'btn_size_l_f.gif" alt="' + this.setting.fontLargeText + '" width="30" height="26" /></a>\n'
					}
				}else{
					var dda1 = '<a href="#" onclick="component.fontChanger.change(\'' + this.setting.fontSmall + '\',this);return false;"><img src="' + dirPath + 'images/' + imgInName + 'btn_size_s_f.gif" alt="' + this.setting.fontSmallText + '" width="22" height="16" /></a>\n'
					var dda2 = '<a href="#" onclick="component.fontChanger.change(\'' + this.setting.fontMidium + '\',this);return false;"><img src="' + dirPath + 'images/' + imgInName + 'btn_size_m_h.gif" alt="' + this.setting.fontMidiumText + '" width="25" height="22" /></a>\n'
					var dda3 = '<a href="#" onclick="component.fontChanger.change(\'' + this.setting.fontLarge + '\',this);return false;"><img src="' + dirPath + 'images/' + imgInName + 'btn_size_l_f.gif" alt="' + this.setting.fontLargeText + '" width="30" height="26" /></a>\n'
				}
				dd1.innerHTML = dda1;
				dd2.innerHTML = dda2;
				dd3.innerHTML = dda3;
				
				var indd = $('viewSelect').getElementsByTagName('dd')[0];
				
				$('viewSelect').insertBefore(dd1,indd);
				$('viewSelect').insertBefore(dd2,indd);
				$('viewSelect').insertBefore(dd3,indd);
			}
		},
		change: function(size,bAnchor){
			var contents = $('contents');
			if(contents){
				contents.style.fontSize = size;
			}
			var buttons = bAnchor.parentNode.parentNode.getElementsByTagName('img');
			for(var i = 0, num = buttons.length; i < num; i++){
				buttons[i].src = buttons[i].src.replace('_h.gif','_f.gif');
			}
			bAnchor.getElementsByTagName('img')[0].src = bAnchor.getElementsByTagName('img')[0].src.replace('_f.gif','_h.gif');
			
			var fontDate = new Date();
			fontDate.setTime(fontDate.getTime() + (7*24*60*60*1000));
			document.cookie = 'font-size=' + size + '; path=/; expires=' + fontDate.toGMTString();
		},
		readCookie: function(){
			if(document.cookie.indexOf('font-size=') >= 0){
				var cookieAll = document.cookie + ';'
				var cookieF = cookieAll.indexOf('font-size=');
				var cookieE = cookieAll.indexOf(';',cookieF);
				var fontSizeData = cookieAll.substring(cookieF,cookieE);
				this.setSize = fontSizeData.split('=')[1];
				document.write('<style type="text/css">#contents {font-size: ' + this.setSize + ';}</style>');
			}
		}
		
	},
	resizeStage: {
		setting : {
			maxSize		:	1200,
			minSize		:	960,
			autoSize	:	90,
			setItems	:	new Array('siteInfo','contents','subInfo'),
			minSizeHome1	:	940,
			minSizeHome2	:	700,
			autoSizeHome	:	'auto',
			setItemsHome	:	new Array('siteName','topContents','contents','subInfo')
		},
		resizeEv: function(){
			if($('home')){
				var imgLayout = setTimeout('component.resizeStage.widthResizeHome()',400);
			}else{
				var imgLayout = setTimeout('component.resizeStage.widthResize()',400);
			}
		},
		widthResize: function(){
			var bodyWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
			for(var i = 0; i < this.setting.setItems.length; i++){
				if($(this.setting.setItems[i])){
					if(bodyWidth > this.setting.maxSize){
						$(this.setting.setItems[i]).style.width = (this.setting.maxSize * (this.setting.autoSize/100)) + 'px';
					}else if(bodyWidth < this.setting.minSize){
						$(this.setting.setItems[i]).style.width = this.setting.minSize + 'px';
					}else{
						$(this.setting.setItems[i]).style.width = this.setting.autoSize + '%';
					}
				}
			}
		},
		widthResizeHome: function(){
			var bodyWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
			for(var i = 0; i < this.setting.setItemsHome.length; i++){
				if($(this.setting.setItemsHome[i])){
					if(bodyWidth < this.setting.minSizeHome1){
						$('menu').style.left = 'auto';
						$('menu').style.right = '0px';
						$(this.setting.setItemsHome[i]).style.width = this.setting.autoSizeHome;
					}else if(bodyWidth < this.setting.minSizeHome2){
						$(this.setting.setItemsHome[i]).style.width = (this.setting.minSizeHome2) + 'px';
					}else{
						$('menu').style.left = '50%';
						$('menu').style.right = 'auto';
						$(this.setting.setItemsHome[i]).style.width = this.setting.autoSizeHome;
					}
				}
			}
		}
	},
	preloadImg: new Object(),
	preNum: 0,
	btnOverEvent: function(){
//		var images = $('menu').getElementsByTagName('img');
		var images = document.getElementsByTagName('img');
		for(var i = 0,num = images.length;i < num; i++){
			var img = images[i];
			var imgSrc = img.src;
			if(imgSrc.indexOf('_f.') > -1 && img.parentNode.href && img.parentNode.parentNode.parentNode.id != 'viewSelect'){
				var newImgSrc = imgSrc.split('_f.')[0] + '_h.' + imgSrc.split('_f.')[1];

				this.preloadImg[this.preNum] = new Image();
				this.preloadImg[this.preNum].src = newImgSrc;

				var funcOnImg = 'component.changeImg(this,\'' + newImgSrc + '\')\;return false\;';
				var funcOutImg = 'component.changeImg(this,\'' + imgSrc + '\')\;return false\;';
				
				this.setEvent(img.parentNode,'onmouseover',funcOnImg);
				this.setEvent(img.parentNode,'onmouseout',funcOutImg);
				this.setEvent(img.parentNode,'onfocus',funcOnImg);
				this.setEvent(img.parentNode,'onblur',funcOutImg);
				this.preNum++
			}
		}
	},
	changeImg: function(eventAnchor,imgSrc){
		eventAnchor.getElementsByTagName('img')[0].src = imgSrc;
	},
	setEvent: function(obj,eventType,func){
		if(this.isIE) {
			obj.setAttribute(eventType,new Function(func));
		} else {
			obj.setAttribute(eventType,func);
		}
	},
	isIE: (document.documentElement.getAttribute("style") == document.documentElement.style),
	isMacIE: function(){
		if(navigator.userAgent.match(new RegExp('MSIE 5.+Mac')) && this.isIE){
			return true;
		}else{
			return false;
		}
	}
}

var $ = function(itemID){
	return document.getElementById(itemID);
}

///////////////////////////////////////////////////////

var dirPath = component.checkCommonDir();
component.fontChanger.readCookie();

var topPageFlag = false;

window.onload = function(){
	closeButton();
	if($('home')){
		var topPageFlag = true;
	}
	component.btnOverEvent();
}

window.onresize = function(){
	component.resizeStage.resizeEv();
}


function closeButton(){
	if($('thanks')){
		var closeAnchor = document.createElement('a');
		closeAnchor.setAttribute('href','#');
		closeAnchor.setAttribute('id','close');
		closeAnchor.appendChild(document.createTextNode('Close'))
		component.setEvent(closeAnchor,'onclick','this.parentNode.style.display = \'none\';return false;')
		$('thanks').appendChild(closeAnchor);
	}
	
}

function writeSlideLink(pageId){
	if(!component.isMacIE()){
		if($('home')){
			var imgInName = 'top_';
			pageId = '';
		}else{
			var imgInName = '';
			pageId = '#' + pageId;
		}
		document.write('<a href="/contents/slide.html' + pageId + '" target="_blank"><img src="/common/images/' + imgInName + 'btn_mode_presentation_f.gif" width="40" height="26" alt="\u30D7\u30EC\u30BC\u30F3(\u65B0\u3057\u3044\u30A6\u30A4\u30F3\u30C9\u30A6\u3067\u958B\u304D\u307E\u3059)" /></a>')
	}
}

function flashDrawer(src,w,h) {
 flashObject = '' + '<object data=\"' + src + '\" width=\"' + w + '\" height=\"' + h + '\" type=\"application/x-shockwave-flash\" >' + '<param name=\"movie\" value=\"' + src + '\" />' + '</object>'; document.write(flashObject);
}

function writeFlashBtn01(t,s){
	var fpVer = deconcept.SWFObjectUtil.getPlayerVersion();
	var tarVer = 8;
	if (fpVer && fpVer['major'] >= tarVer){
		document.write(''+
		'<div class="moviebtn"><p>' +
		'<a href="' + s + '" rel="mediabox[560 460]" title="' + t + '">' +
		'<img src="/contents/images/powercms1_1/btn_movie.gif" width="144" height="40" alt="\u30E0\u30FC\u30D3\u30FC\u3092\u898B\u308B" />' +
		'</a></p></div>');
	}
}

function writeFlashBtn02(t,s){
	var fpVer = deconcept.SWFObjectUtil.getPlayerVersion();
	var tarVer = 8;
	if (fpVer && fpVer['major'] >= tarVer){
		document.write(''+
		'<div class="moviebtn"><p>' +
		'<a href="' + s + '" rel="mediabox[560 555]" title="' + t + '">' +
		'<img src="/contents/images/powercms1_1/btn_movie.gif" width="144" height="40" alt="\u30E0\u30FC\u30D3\u30FC\u3092\u898B\u308B" />' +
		'</a></p></div>');
	}
}

function writeFlashBtn00(t,s,size){
	var fpVer = deconcept.SWFObjectUtil.getPlayerVersion();
	var tarVer = 8;
	if (fpVer && fpVer['major'] >= tarVer){
		document.write(''+
		'<div class="moviebtn"><p>' +
		'<a href="' + s + '" rel="mediabox[' + size + ']" title="' + t + '">' +
		'<img src="/contents/images/powercms1_1/btn_movie.gif" width="144" height="40" alt="\u30E0\u30FC\u30D3\u30FC\u3092\u898B\u308B" />' +
		'</a></p></div>');
	}
}
