$dk = (function(){
	var _publicObj={};
	
	
	//▼IE6 PNG
	if(typeof document.documentElement.style.maxHeight=='undefined'){
		var src='<script src="/common/js/DD_belatedPNG.js"></script><script>DD_belatedPNG.fix(".png");</script>';
		$('head').append(src);
	};
	
	
	//▼フォントサイズ
	function setFontSize(){
		$('.fontChange li').click(function(e){
			var type = $(e.target).attr('class');
			var changeType;
			switch(type){
				case 'medium':
					$('.mainContents').attr({"class":"mainContents"});
					$(this).attr({"class":"medium_on"});
					$(this).next().attr({"class":"large"});
					changeType='medium';
					break;
				case 'large':
					$('.mainContents').attr({"class":"mainContents fontLarge"});
					$(this).attr({"class":"large_on"});
					$(this).prev().attr({"class":"medium"});
					changeType='large';
					break;
				default:
					break;
			}
			$.cookie('font_size',null)
			$.cookie('font_size',changeType,{path:'/'});
		});
		if(!!$.cookie('font_size')){
			if($.cookie('font_size')=="large"){
				$('.mainContents').attr({"class":"mainContents fontLarge"});
				$('.fontChange .large').attr({"class":"large_on"});
				$('.fontChange .medium_on').attr({"class":"medium"});
			}
		}
	}
	
	
	//▼インクルード関連
	var dfrObj = {
		pageLoad : function(){
			var dfr = $.Deferred();
			$(function(){
				dfr.resolve();
			});		
			return dfr.promise();
		},
		loadCheck : function(target){
			var dfr = $.Deferred();
			$(target).ready(function(){
				dfr.resolve();
				
			});
			return dfr.promise();
		},
		include : function(file){
			var dfr = $.Deferred();
			$.ajax({
				url : file,
				dataType : 'html',
				success : dfr.resolve,
				error : dfr.reject
			});
			return dfr.promise();
		}
	};
	function error(target){
		$(target).html('<p>読み込みに失敗しました。</p>')
	}

	//ヘッダー読み込み
	var headerObj = {
		id : '#Header',
		src : '',
		loader : dfrObj.include('/common/include/header.html'),
		check : dfrObj.loadCheck(this.id)
	};
	headerObj.loader.then(
		function(res){
			headerObj.src=res;
		},
		function(){
			error(headerObj.id);
		}
	);
	$.when(headerObj.loader,headerObj.check).done(function(){
		$(headerObj.id+' .yahooSearch').before(headerObj.src).show();
		setFontSize();
		$('#GrobalNavi').lu_ddmenu({cname:"showMenu",left:"3px",top:"53px"});
	});
	
	//フッター読み込み
	var footerObj = {
		id : '#Footer',
		src : '',
		loader : dfrObj.include('/common/include/footer.html'),
		check : dfrObj.loadCheck(this.id)
	};
	footerObj.loader.then(
		function(res){
			footerObj.src=res;
		},
		function(){
			error(footerObj.id);
		}
	);
	$.when(footerObj.loader,footerObj.check).done(function(){
		$(footerObj.id).html(footerObj.src);
	});
	
	//サイドバー処理
	var sideObj = {
		id:"#Sidebar",
		src : '',
		loader : '',
		checkBody : dfrObj.loadCheck('body'),
		checkSide : dfrObj.loadCheck(this.id)
	};
	sideObj.checkBody.done(function(){
		var cornerId = $('body').attr('id');
		if(!cornerId) return;
		sideObj.loader = dfrObj.include('/common/include/sidebar_'+cornerId.toLowerCase()+'.html').then(function(res){
			sideObj.checkSide.done(function(){
				var cname = $(sideObj.id).html(res).attr('class');
				var cn = cname.split('_')[0];
				if(!cn) return;
				$(sideObj.id+' li').each(function(){
					var url = $(this).find('a:first-child').attr('href');
					if(url.indexOf(cn.replace(/-/g,'/'))!=-1){
						$(this).attr({'class':'on'});
						return false;
					};
				});
				if(cn.indexOf('dkreport')!=-1){
					var page = location.href.split("/dkreport/")[1].split('.html')[0];
					page = page.substr(0,4)+"年"+Number(page.substr(4,2))+"月";
					$('#ReportList').show();
					$("#Sidebar .month").each(function(){
						if($(this).find('a').text()==page){
							$(this).parents('.monthContainer').show();//.prev().css({'border-top':'1px #fff solid'});
							$(this).next().show();
							return true;
						}
					});
				}
				if(cname.indexOf('careers-index_2013')!=-1){
					$(".careersBox").show();
				}
			});
		},function(){error(sideObj.id);});
	});
	
	//初期処理
	var initHandler = dfrObj.pageLoad();
	$.when(headerObj.loader,footerObj.loader,initHandler).done(function(){
		
	});
	
	
	
	//▼Yahoo検索書き出し
	_publicObj.yahooSearch = function(){
		var src='';
		src+='<!-- ここから検索窓のソースコード -->';
		src+='<link rel="stylesheet" href="http://i.yimg.jp/images/sitesearch/t1/css/sb.css?dr" />';
		src+='<div id="yjSsSb">';
		src+='<form action="http://site.search.yahoo.co.jp/search" method="GET" name="" id="yjSsFrm">';
		src+='<p id="yjSsMod_1">';
		src+='<span id="yjSsTxtWrap"><input type="text" name="p" id="yjSsTxt"></span>';
		src+='<span id="yjSsBtnWrap"><input type="submit" value="検索" id="yjSsBtn"></span>';
		src+='</p>';
		src+='<p id="yjSsMod_3" style="display:none;"><a href="http://www.yahoo.co.jp/">Powered by Yahoo! JAPAN</a></p>';
		src+='<input type="hidden" value="UTF-8" name="ei" id="yjSsChr">';
		src+='<input type="hidden" value="yssbgl" name="fr">';
		src+='<input type="hidden" value="wrt" name="x">';
		src+='<input type="hidden" value="LQBPmLurRjc-" name="conf_id">';
		src+='</form>';
		src+='<script type="text/javascript" src="http://site.search.yahoo.co.jp/search/searchboxjs?conf_id=LQBPmLurRjc-"></script>';
		src+='</div><!--/#yjSsSb end-->';
		src+='<!-- /ここまで検索窓のソースコード -->';
		document.write(src);
	}
	
	//▼loadContents
	_publicObj.loadContents = function(){
		var q = location.href.split("?file=")[1];
		var fileName = q.split('&')[0];
		var titleName = q.split('&name=')[1];
		
		var loadObj = {
			id : '#LoadContentsResult',
			src : '',
			loader : dfrObj.include('./'+fileName+'.html'),
			check : dfrObj.loadCheck(this.id)
		}
		loadObj.loader.then(
			function(res){
				loadObj.src=res;
			},
			function(){
				error(loadObj.id);
			}
		);
		
		$.when(loadObj.loader,loadObj.check).done(function(){
			//$('html').find('title').html(decodeURI(titleName)+" [第一興商]");
			document.title = decodeURI(titleName)+" [第一興商]";
			//document.getElementsByTagName('title')[0].innerHTML=" [第一興商]";
			$('#BreadPageName').text(decodeURI(titleName));
			//console.log(loadObj.src.replace(/\n/g,''));
			var src = loadObj.src.replace(/\n/g,'').replace(/<script.*?<\/script>/g,'').replace(/<a href="javascript.*?<\/a>/g,'').replace(/<img [^>]*copyright\.gif.*?>/g,'').replace(/<img [^>]*shim\.gif.*?>/g,'<img src="/images/shim.gif" width="1" height="15">');
			
			$(loadObj.id).html(src);
		});
	}
	
	//DKレポート
	_publicObj.dkreport = function(filename){
		var obj = {
			id:"#Result",
			loader : dfrObj.include('/newsrelease/dkreport/'+filename)
		}
		obj.loader.then(
			function(res){
				$(obj.id).html($(res).find(".cornerContents").html());
			},
			function(){
				error(obj.id);
			}
		);
		
	}
	_publicObj.dkreport2 = function(filename){
		var url = location.href.split('dkreport/')[0]+'dkreport/'+filename;
		location.href=url;
	}
	_publicObj.dkReportOpen = function(id){
		$("#"+id).toggle();
	}

	return _publicObj;
})();
function m_open(fileurl){
window.open(fileurl,'subwin','width=400,height=300');
}

