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		:	'smaller',
			fontMidium		:	'100%',
			fontLarge		:	'150%',
			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="26" height="31" /></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="26" height="31" /></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="29" height="31" /></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="29" height="31" /></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="33" height="31" /></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="33" height="31" /></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="26" height="31" /></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="29" height="31" /></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="33" height="31" /></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>');
			}
		}
		
	},
	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();
	link_controller.action('pageBody');
}

/*
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>');
	}
}

////////////////////

var change_menu = {
	init: {
		class_name: 'here'
	},
	focus: function(a){
		var li = a.parentNode.parentNode.parentNode.parentNode;
		change_class.append(li,this.init.class_name);
	},
	blur: function(a){
		var li = a.parentNode.parentNode.parentNode.parentNode;
		change_class.remove(li,this.init.class_name);
	}
}

var change_class = {
	append: function(ele,c){
		var c_c = ele.className;
		var n_c = '';
		if(c_c){
			var c_array = c_c.split(' ');
			for(var i = 0; i < c_array.length; i++){
				if(c_array[i] == c){
					return;
				}
			}
			n_c = c_c + ' ' + c;
		}else{
			n_c = c;
		}
		ele.className = n_c;
	},
	remove: function(ele,c){
		var c_c = ele.className;
		if(c_c){
			var n_c_array = new Array();
			var num = 0;
			var c_array = c_c.split(' ');
			for(var i = 0; i < c_array.length; i++){
				if(c_array[i] != c){
					n_c_array[num] = c_array[i];
					num++;
				}
			}
			var n_c = n_c_array.join('@');
			ele.className = n_c;
		}else{
			return;
		}
	}
}


var isIE = (document.documentElement.getAttribute("style") == document.documentElement.style);
var commonPath = document.getElementsByTagName('head')[0].getElementsByTagName('script')[0].src.split('js/common.js')[0];

/*============================================================**
		Width Resize ウィンドウリサイズ
**============================================================*/

var resizeElements = new Array('contents','footer');
var resizeWidth = {
	'maxWidth'	: '1200',
	'minWidth'	: '900',
	'autoWidth'	: '100%'
}

var imgLayout = '';

function widthResize(){
	var parentWidth=document.getElementsByTagName('body')[0].clientWidth;
	for(var i = 0, num=resizeElements.length; i < num; i++){
		if(document.getElementById(resizeElements[i])){
			if((parentWidth > resizeWidth.maxWidth)){
				document.getElementById(resizeElements[i]).style.width = resizeWidth.maxWidth + 'px';
			} else if(parentWidth < resizeWidth.minWidth){
				document.getElementById(resizeElements[i]).style.width = resizeWidth.minWidth + 'px';
			} else {
				document.getElementById(resizeElements[i]).style.width = resizeWidth.autoWidth;
			}
		}
		
	}
}


function resizeEv(){
	if(document.getElementById('viewerL')){
		imgLayout = setTimeout("widthResizeL()",400);
	}else{
		imgLayout = setTimeout("widthResize()",400);
	}
}

function wResize(){
	resizeEv();
}

window.onresize = wResize;

function widthResizeL(){
	var imageWidth = 0;
	var imageLs = document.getElementById('photoImage').getElementsByTagName('img');
	for(var i = 0, num=imageLs.length; i < num; i++){
		var imageL = imageLs[i];
		if(imageL.width > imageWidth){
			imageWidth = imageL.width;
		}
	}
	
	if(imageWidth < resizeWidth.minWidth){
		widthResize();
	}else{
		for(var i = 0, num=resizeElements.length; i < num; i++){
			if(document.getElementById(resizeElements[i])){
				document.getElementById(resizeElements[i]).style.width = imageWidth + 'px';
			}
		}
	}
}


/*============================================================**
		窓アイコンを付加
**============================================================*/

var link_controller = {
	action: function(limit){
		if(limit){
			var limit_ele = document.getElementById(limit);
			if(!limit_ele){
				return;
			}
		}else{
			var limit_ele = document.getElementsByTagName('body')[0];
		}
		
		var anchors = limit_ele.getElementsByTagName('a');
		for(var i = 0; i < anchors.length; i++){
			var a = anchors[i];
			if(a.href){
				this.win.append(a);
			}
		}
	},
	win: {
		init: {
			exclude_hostname: window.location.hostname,
			icon_path: '/common/images/icon_gaibu.gif',
			alt_text: '外部サイトへリンク'
		},
		append: function(a){
			if(!a.href.match(this.init.exclude_hostname)){
				var icon = document.createElement('img');
				icon.src = this.init.icon_path;
				icon.style.margin = '0px 0px 0.1em 4px';
				icon.style.verticalAlign = 'baseline';
				icon.title = this.init.alt_text;
				icon.alt= this.init.alt_text;
				a.appendChild(icon);
			}
		}
	}
}

/*============================================================**
		NEWアイコンを付加
**============================================================*/

var now = new Date();
var new_icon = {
	init: {
		term: 30
	},
	action: function(entryDate){
		if(Math.floor((now.getTime() - entryDate.getTime()) / (24 * 60 * 60 * 1000)) <= this.init.term){
			document.write('<img src="/common/images/icon_new.gif" width="44" height="18" alt="NEW" />');
		}
	}
}