
/*  ================================================================================
 サイドメニュー関連
================================================================================  */

// サブメニュー表示非表示切り換え
function cng_menu(menu_num){

	switch (menu_num){
	case 1://"news":	
		if(document.getElementById("sub_menu1").style.display == 'block'){
			document.getElementById("sub_menu1").style.display = 'none';
			document.getElementById("sub_menu2").style.display = 'none';
			document.getElementById("sub_menu3").style.display = 'none';			
		}else{
			document.getElementById("sub_menu1").style.display = 'block';
			document.getElementById("sub_menu2").style.display = 'block';		
			document.getElementById("sub_menu3").style.display = 'block';
			for(var i=4;i<=12;i++){
				document.getElementById("sub_menu"+String(i)).style.display = 'none';
			}
			
		}
		break;

	case 2://"works":
		if(document.getElementById("sub_menu4").style.display == 'block'){
			document.getElementById("sub_menu4").style.display = 'none';
			document.getElementById("sub_menu5").style.display = 'none';
			document.getElementById("sub_menu6").style.display = 'none';
			document.getElementById("sub_menu7").style.display = 'none';
			document.getElementById("sub_menu8").style.display = 'none';
			document.getElementById("sub_menu9").style.display = 'none';
		}else{
			document.getElementById("sub_menu4").style.display = 'block';		
			document.getElementById("sub_menu5").style.display = 'block';
			document.getElementById("sub_menu6").style.display = 'block';
			document.getElementById("sub_menu7").style.display = 'block';
			document.getElementById("sub_menu8").style.display = 'block';
			document.getElementById("sub_menu9").style.display = 'block';
			for(var i=1;i<=3;i++){
				document.getElementById("sub_menu"+String(i)).style.display = 'none';
			}
			for(var i=10;i<=12;i++){
				document.getElementById("sub_menu"+String(i)).style.display = 'none';
			}
		}		
		break;
		
	case 3://"blog":
		if(document.getElementById("sub_menu10").style.display == 'block'){
			document.getElementById("sub_menu10").style.display = 'none';
			document.getElementById("sub_menu11").style.display = 'none';
		}else{
			document.getElementById("sub_menu10").style.display = 'block';
			document.getElementById("sub_menu11").style.display = 'block';		
			for(var i=1;i<=9;i++){
				document.getElementById("sub_menu"+String(i)).style.display = 'none';
			}
			for(var i=12;i<=12;i++){
				document.getElementById("sub_menu"+String(i)).style.display = 'none';
			}
		}
		break;	
		
	case 4://"projects":		
		if(document.getElementById("sub_menu12").style.display == 'block'){
			document.getElementById("sub_menu12").style.display = 'none';
		}else{
			document.getElementById("sub_menu12").style.display = 'block';
			for(var i=1;i<=11;i++){
				document.getElementById("sub_menu"+String(i)).style.display = 'none';
			}
		}		
		break;	
	}

}

// メニュー表示
// str_cate1:メニュー名,str_cate2:子メニュー名
function show_menu(str_cate1,str_cate2){

	// 子メニュー表示指定
	var str_sub_display_news="none";
	var str_sub_display_works="none";
	var str_sub_display_blog="none";
	var str_sub_display_projects="none";

	// 現在地表示バーの指定
	var str_here_top = "";
	var str_here_news = "";
	var str_here_news_sub1 = "";
	var str_here_news_sub2 = "";
	var str_here_news_sub3 = "";
	var str_here_services = "";
	var str_here_works = "";
	var str_here_works_sub1 = "";
	var str_here_works_sub2 = "";
	var str_here_works_sub3 = "";
	var str_here_works_sub4 = "";
	var str_here_works_sub5 = "";
	var str_here_works_sub6 = "";
	var str_here_voice = "";
	var str_here_blog = "";
	var str_here_blog_sub1 = "";
	var str_here_blog_sub2 = "";
	var str_here_staff = "";
	var str_here_company = "";
	var str_here_contact = "";
	var str_here_recruit = "";
	var str_here_projects = "";
	var str_here_projects_sub1 = "";
	
	// 振り分け処理
	switch (str_cate1){
		case "top":
			str_here_top="class='here'";
			break;
		case "news":
			str_sub_display_news="block";
			str_here_news="class='here'";
			switch (str_cate2){
				case "update":
					str_here_news_sub1="class='here'";
					break;
				case "information":
					str_here_news_sub2="class='here'";
				break;
				case "press":
					str_here_news_sub3="class='here'";
					break;
			}
			break;
		case "services":
			str_here_services="class='here'";
			break;
		case "works":
			str_sub_display_works="block";
			str_here_works="class='here'";
			switch (str_cate2){
				case "ci_design":
					str_here_works_sub1="class='here'";
					break;
				case "pamphlets_design":
					str_here_works_sub2="class='here'";
				break;
				case "dmcard_design":
					str_here_works_sub3="class='here'";
					break;
				case "flyer_design":
					str_here_works_sub4="class='here'";
					break;
				case "web_design":
					str_here_works_sub5="class='here'";
					break;
				case "other_design":
					str_here_works_sub6="class='here'";
					break;
			}			
			break;
		case "voice":
			str_here_voice="class='here'";
			break;
		case "blog":
			str_sub_display_blog="block";
			str_here_blog="class='here'";
			switch (str_cate2){
				case "ceoblog":
					str_here_blog_sub1="class='here'";
					break;
				case "staff blog":
					str_here_blog_sub2="class='here'";
				break;
			}			
			break;
		case "staff":
			str_here_staff="class='here'";
			break;
		case "company":
			str_here_company="class='here'";
			break;
		case "contact":
			str_here_contact="class='here'";
			break;
		case "recruit":
			str_here_recruit="class='here'";
			break;
		case "projects":
			str_sub_display_projects="block";
			str_here_projects="class='here'";
			switch (str_cate2){
				case "cdc":
					str_here_projects_sub1="class='here'";
					break;
			}
			break;
		case "cdc":
			str_sub_display_projects="block";
			str_here_projects="class='here'";
			str_here_projects_sub1="class='here'";
			break;
	}
	
	// HTML表示文字列設定
	var str_tgt = "";
	str_tgt = str_tgt +"	<ul class='mainmenu'>";
	str_tgt = str_tgt +"	<li class='first'><a href='http://www.celldivision.jp/' " + str_here_top  + "><img src='http://www.celldivision.jp/images/common/m_top.gif' alt='top' width='23' height='14'></a></li>";
	str_tgt = str_tgt +"	<li><a onclick='cng_menu(1)' " + str_here_news + "><img src='http://www.celldivision.jp/images/common/m_news.gif' alt='news' width='33' height='14'></a>";
	str_tgt = str_tgt +"		<ul class='submenu'>";
	str_tgt = str_tgt +"			<li class='sub_menu ' style='display: " + str_sub_display_news +"' id='sub_menu1'>      <a " + str_here_news_sub1 + " href='http://www.celldivision.jp/news/update/index.html'><img src='http://www.celldivision.jp/images/common/m_update.jpg' alt='update' width='37' height='14'></a></li>";
	str_tgt = str_tgt +"			<li class='sub_menu ' style='display: " + str_sub_display_news +"' id='sub_menu2'>      <a " + str_here_news_sub2 + " href='http://www.celldivision.jp/news/information/index.html'><img src='http://www.celldivision.jp/images/common/m_information.jpg' alt='information' width='62' height='14'></a></li>";
	str_tgt = str_tgt +"			<li class='sub_menu  last' style='display:  " + str_sub_display_news +"' id='sub_menu3'><a " + str_here_news_sub3 + " href='http://www.celldivision.jp/news/press/index.html'><img src='http://www.celldivision.jp/images/common/m_press.jpg' alt='press' width='29' height='14'></a></li>";
	str_tgt = str_tgt +"		</ul>";
	str_tgt = str_tgt +"	</li>";
	str_tgt = str_tgt +"	<li><a href='http://www.celldivision.jp/services/index.html'" + str_here_services + "><img src='http://www.celldivision.jp/images/common/m_services.gif' alt='servicees' width='53' height='14'></a></li>";
	str_tgt = str_tgt +"	<li><a onclick='cng_menu(2)' " + str_here_works + "><img src='http://www.celldivision.jp/images/common/m_works.jpg' alt='works' width='38' height='14'></a>";
	str_tgt = str_tgt +"		<ul class='submenu'>";
	str_tgt = str_tgt +"		<li class='sub_menu  ' style='display: " + str_sub_display_works +"' id='sub_menu4'>   <a " + str_here_works_sub1 + " href='http://www.celldivision.jp/works/ci_design/index.html'><img src='http://www.celldivision.jp/images/common/m_ci.gif' alt='ci' width='15' height='14'></a></li>";
	str_tgt = str_tgt +"		<li class='sub_menu  ' style='display: " + str_sub_display_works +"' id='sub_menu8'>   <a " + str_here_works_sub5 + " href='http://www.celldivision.jp/works/web_design/index.html'><img src='http://www.celldivision.jp/images/common/m_web.gif' alt='web' width='22' height='14'></a></li>";
	str_tgt = str_tgt +"		<li class='sub_menu  ' style='display: " + str_sub_display_works +"' id='sub_menu5'>   <a " + str_here_works_sub2 + " href='http://www.celldivision.jp/works/pamphlets_design/index.html'><img src='http://www.celldivision.jp/images/common/m_pamphlet.gif' alt='pamphlets' width='54' height='14'></a></li>";
	str_tgt = str_tgt +"		<li class='sub_menu  ' style='display: " + str_sub_display_works +"' id='sub_menu6'>   <a " + str_here_works_sub3 + " href='http://www.celldivision.jp/works/dmcard_design/index.html'><img src='http://www.celldivision.jp/images/common/m_dmcard.gif' alt='dm & cards' width='56' height='14'></a></li>";
	str_tgt = str_tgt +"		<li class='sub_menu  ' style='display: " + str_sub_display_works +"' id='sub_menu7'>   <a " + str_here_works_sub4 + " href='http://www.celldivision.jp/works/flyer_design/index.html'><img src='http://www.celldivision.jp/images/common/m_flyer.gif' alt='flyer' width='31' height='14'></a></li>";
	str_tgt = str_tgt +"		<li class='sub_menu last' style='display: " + str_sub_display_works +"' id='sub_menu9'><a " + str_here_works_sub6 + " href='http://www.celldivision.jp/works/other_design/index.html'><img src='http://www.celldivision.jp/images/common/m_other.gif' alt='others' width='34' height='14'></a></li>";
	str_tgt = str_tgt +"		</ul>";
	str_tgt = str_tgt +"	</li>";
	str_tgt = str_tgt +"	<li><a href='http://www.celldivision.jp/voice/index.html' " + str_here_voice + "><img src='http://www.celldivision.jp/images/common/m_voice.gif' alt='voice' width='37' height='14'></a></li>";
	str_tgt = str_tgt +"	<li><a onclick='cng_menu(3)'  " + str_here_blog + " ><img src='http://www.celldivision.jp/images/common/m_blog.gif' alt='blog' width='30' height='14'></a>";
	str_tgt = str_tgt +"		<ul class='submenu'>";
	str_tgt = str_tgt +"		<li class='sub_menu' style='display:  " + str_sub_display_blog +"' id='sub_menu10'>     <a  " + str_here_blog_sub1 + " href='http://www.celldivision.jp/masashiblog/index.html'><img src='http://www.celldivision.jp/images/common/m_ceoblog.gif' alt='blog' width='56' height='14'></a></li>";
	str_tgt = str_tgt +"		<li class='sub_menu last' style='display:  " + str_sub_display_blog +"' id='sub_menu11'><a  " + str_here_blog_sub2 + " href='http://www.celldivision.jp/weblog/index.html'><img src='http://www.celldivision.jp/images/common/m_staffblog.gif' alt='blog' width='56' height='14'></a></li>";
	str_tgt = str_tgt +"		</ul>";
	str_tgt = str_tgt +"	</li>";
	str_tgt = str_tgt +"	<li><a href='http://www.celldivision.jp/staff/index.html'   " + str_here_staff   + "><img src='http://www.celldivision.jp/images/common/m_staff.gif' alt='staff' width='34' height='14'></a></li>";
	str_tgt = str_tgt +"	<li><a href='http://www.celldivision.jp/company/index.html' " + str_here_company + "><img src='http://www.celldivision.jp/images/common/m_company.gif' alt='company' width='56' height='14'></a></li>";
	str_tgt = str_tgt +"	<li><a href='http://www.celldivision.jp/contact/index.php' " + str_here_contact + "><img src='http://www.celldivision.jp/images/common/m_contact.gif' alt='contact' width='49' height='14'></a></li>";
	str_tgt = str_tgt +"	<li><a href='http://www.celldivision.jp/recruit/index.html' " + str_here_recruit + "><img src='http://www.celldivision.jp/images/common/m_recruit.gif' alt='recruit' width='47' height='14'></a></li>";
	str_tgt = str_tgt +"	</ul>";
	str_tgt = str_tgt +"	<ul class='mainmenu mainmenu2'>";
	str_tgt = str_tgt +"	<li class='first'><a onclick='cng_menu(4)'  " + str_here_projects + " ><img src='http://www.celldivision.jp/images/common/m_projects.gif' alt='cdc'></a>";
	str_tgt = str_tgt +"		<ul class='submenu'>";
	str_tgt = str_tgt +"		<li class='sub_menu last' style='display:  " + str_sub_display_projects +"' id='sub_menu12'><a  " + str_here_projects_sub1 + " href='http://www.celldivision.jp/cdc/index.html'><img src='http://www.celldivision.jp/images/common/m_cdc.jpg' alt='cdc'></a></li>";
	str_tgt = str_tgt +"		</ul>";
	str_tgt = str_tgt +"	</li>";
	str_tgt = str_tgt +"	</ul>";

	// トップ以下はパスの階層深くするために置換
	/*if(str_cate1 != "top"){
		str_tgt = replaceAll(str_tgt,"href='", "href='../","g")		
		str_tgt = replaceAll(str_tgt,"src='images", "src='../images","g")
	}*/

	// 表示
	document.write(str_tgt);

}


 // 全ての文字列 s1 を s2 に置き換える  
 function replaceAll(expression, org, dest){  
     return expression.split(org).join(dest);  
 }
 

/*  ================================================================================
 サイドメニューが付いてくる関連
================================================================================  */

 // ついてくるメニュー
var str_follow="";
str_follow = str_follow + "<script type='text/javascript'>";
str_follow = str_follow + "var name = '#topColumnMenu';";
str_follow = str_follow + "var menuYloc = null;";
str_follow = str_follow + "jQuery(document).ready(function(){";
str_follow = str_follow + "	jQuery(window).scroll(function () {;"
str_follow = str_follow + "		if(jQuery(document).scrollTop()<= 110){";
str_follow = str_follow + "			menuYloc =210-$(document).scrollTop();";
str_follow = str_follow + "		}else{";
str_follow = str_follow + "			menuYloc =100;";
str_follow = str_follow + "		}";
str_follow = str_follow + "		offset = menuYloc+jQuery(document).scrollTop()+'px';";
str_follow = str_follow + "		jQuery(name).animate({top:offset},{duration:700,queue:false});";
str_follow = str_follow + "	});";
str_follow = str_follow + "});";
str_follow = str_follow + "</script>";
str_follow = str_follow + "<style>#topColumnMenu {position:absolute;}</style>";
document.write(str_follow);


/*  ================================================================================
 トップへスクロール関連
================================================================================  */

//** jQuery Scroll to Top Control script- (c) Dynamic Drive DHTML code library: http://www.dynamicdrive.com.
//** Available/ usage terms at http://www.dynamicdrive.com (March 30th, 09')
//** v1.1 (April 7th, 09'):
//** 1) Adds ability to scroll to an absolute position (from top of page) or specific element on the page instead.
//** 2) Fixes scroll animation not working in Opera. 

var scrolltotop={
	//startline: Integer. Number of pixels from top of doc scrollbar is scrolled before showing control
	//scrollto: Keyword (Integer, or "Scroll_to_Element_ID"). How far to scroll document up when control is clicked on (0=top).
	setting: {startline:100, scrollto: 0, scrollduration:1000, fadeduration:[500, 100]},
	
	controlHTML: '<img src="http://www.celldivision.jp/images/common/btn_pagetop_off.gif" style="width:71px; height:13px" />', //HTML for control, which is auto wrapped in DIV w/ ID="topcontrol"
	controlattrs: {offsetx:5, offsety:5}, //offset of control relative to right/ bottom of window corner
	anchorkeyword: '#top', //Enter href value of HTML anchors on the page that should also act as "Scroll Up" links

	state: {isvisible:false, shouldvisible:false},

	scrollup:function(){
		if (!this.cssfixedsupport) //if control is positioned using JavaScript
			this.$control.css({opacity:0}) //hide control immediately after clicking it
		var dest=isNaN(this.setting.scrollto)? this.setting.scrollto : parseInt(this.setting.scrollto)
		if (typeof dest=="string" && jQuery('#'+dest).length==1) //check element set by string exists
			dest=jQuery('#'+dest).offset().top
		else
			dest=0
		this.$body.animate({scrollTop: dest}, this.setting.scrollduration);
	},

	keepfixed:function(){
		var $window=jQuery(window)
		var controlx=$window.scrollLeft() + $window.width() - this.$control.width() - this.controlattrs.offsetx
		var controly=$window.scrollTop() + $window.height() - this.$control.height() - this.controlattrs.offsety
		this.$control.css({left:controlx+'px', top:controly+'px'})
	},

	togglecontrol:function(){
		var scrolltop=jQuery(window).scrollTop()
		if (!this.cssfixedsupport)
			this.keepfixed()
		this.state.shouldvisible=(scrolltop>=this.setting.startline)? true : false
		if (this.state.shouldvisible && !this.state.isvisible){
			this.$control.stop().animate({opacity:1}, this.setting.fadeduration[0])
			this.state.isvisible=true
		}
		else if (this.state.shouldvisible==false && this.state.isvisible){
			this.$control.stop().animate({opacity:0}, this.setting.fadeduration[1])
			this.state.isvisible=false
		}
	},
	
	init:function(){
		jQuery(document).ready(function($){
			var mainobj=scrolltotop
			var iebrws=document.all
			mainobj.cssfixedsupport=!iebrws || iebrws && document.compatMode=="CSS1Compat" && window.XMLHttpRequest //not IE or IE7+ browsers in standards mode
			mainobj.$body=(window.opera)? (document.compatMode=="CSS1Compat"? $('html') : $('body')) : $('html,body')
			mainobj.$control=$('<div id="topcontrol">'+mainobj.controlHTML+'</div>')
				.css({position:mainobj.cssfixedsupport? 'fixed' : 'absolute', bottom:mainobj.controlattrs.offsety, right:mainobj.controlattrs.offsetx, opacity:0, cursor:'pointer'})
				.attr({title:'Scroll Back to Top'})
				.click(function(){mainobj.scrollup(); return false})
				.appendTo('body')
			if (document.all && !window.XMLHttpRequest && mainobj.$control.text()!='') //loose check for IE6 and below, plus whether control contains any text
				mainobj.$control.css({width:mainobj.$control.width()}) //IE6- seems to require an explicit width on a DIV containing text
			mainobj.togglecontrol()
			$('a[href="' + mainobj.anchorkeyword +'"]').click(function(){
				mainobj.scrollup()
				return false
			})
			$(window).bind('scroll resize', function(e){
				mainobj.togglecontrol()
			})
		})
	}
}

scrolltotop.init()

/*  ================================================================================
 自動ロールオーバー機能
================================================================================  */

function smartRollover() {
	if(document.getElementsByTagName) {
		var images = document.getElementsByTagName("img");

		for(var i=0; i < images.length; i++) {
		
			/*if(images[i].getAttribute("src").match("_off."))*/
			
			if(images[i].src.match("_off."))
			
			{
				images[i].onmouseover = function() {
					/*this.setAttribute("src", this.getAttribute("src").replace("_off.", "_on."));*/
					this.setAttribute("src", this.src.replace("_off.", "_on."));
				}
				images[i].onmouseout = function() {
					/*this.setAttribute("src", this.getAttribute("src").replace("_on.", "_off."));*/
					this.setAttribute("src", this.src.replace("_on.", "_off."));
				}
			}
		}
	}
}

if(window.addEventListener) {
	window.addEventListener("load", smartRollover, false);
}
else if(window.attachEvent) {
	window.attachEvent("onload", smartRollover);
}


