// JavaScript Document
var move_obj = "";
var box_al = new Array();
box_al["id"] = new Array();
var Ory;
if (!Ory) Ory = {};
if (!Ory.Widget) Ory.Widget = {};

Ory.Widget.SlideMenu = function(id){
	this.ele = $("#"+id)[0];
	this.ele1 = $("#"+id);
	this.id = id;
	this.menuWidth = 21;
	this.MenuList = new Array();
	this.MenuIdNumList = new Array();
	this.MenuBtnList = new Array();
	for(var i=0; i<this.ele.childNodes.length; i++){
		if(this.ele.childNodes.item(i).tagName == "DIV"){
			this.MenuList[this.MenuList.length] = this.ele.childNodes.item(i).id;
		}
	}
	this.MenuList.reverse();
	for(var i=0; i<this.MenuList.length; i++){
		this.MenuIdNumList[this.MenuList[i]] = i;
	}
	this.pw = null;
	this.targetMenu = this.MenuList[0];
	this.currentMenu = 0;
	this.MenuLength = this.MenuList.length;
	this.ml = 0;
	this.mr = 0;
	this.fs = 60;//time-40
	this.fc = 5;//koma
};
function urchinTracker(){
	return 0;
}
Ory.Widget.LinkMove = function( hash ){
	var i = "id";
	$('#body-1').attr("class","");
	var h = top.location.hash;
		h = h.replace(/#/i,"");
	if(h == 10){
			//location.href = "#";
	}
	if( !hash || hash == 1 ){
		acc1.openPanel(0);
		document.title = ttl_str;
		if(!flag_search) setTimeout(function(){ $("#ApcHome").css("visibility", "visible") }, 800);
	}else{
		$("#ApcHome").css("visibility", "hidden");
	}
/*--------for SITEMAP -----*/
	if(flag_sitemap) Sitemap_Set();
/*--------for Search -----------*/
	//if(flag_search) Search_Set();
	if( hash == 10 ){//site map
		acc1.openPanel(7);	$('#body-1').attr("class","sitemap");
	}else if( hash >= 100000 && hash < 200000 ){
		acc1.openPanel(1);	ApcAboutUs.MenuOpen(i+hash);
		if(hash == 100000) document.title = page_title[hash] + ttl_str;
		else document.title = page_title[hash] + page_title[100000] + ttl_str;
	}else if( hash >= 200000 && hash < 300000 ){//work
		acc1.openPanel(2);
		if(hash == 200000){//ApcWorks.MenuOpen(i+hash,"",true);
			ApcWorks.MenuOpen(i+200000,hash);
		}else if(hash >= 200900 && hash < 201300){
			if($("#"+i+201000).attr("class") != "outline-open" && $("#"+i+200999).attr("class") != "outline-open"){ 
				ApcWorks.MenuOpen(i+201000,hash);
			}else if($("#"+i+201000).attr("class") == "outline-open"){
				$("#"+i+200999).attr("class","outline");
				ApcWorks.MenuOpen(i+200999,hash);
			}else if($("#"+i+200999).attr("class") == "outline-open"){ 
				$("#"+i+201000).attr("class","outline");
				$("#"+i+200002).after($("#"+i+201000));
				ApcWorks.MenuOpen(i+201000,hash);
			}
			if(page_title[hash]) document.title = page_title[hash] + " : " + page_title[200001] + page_title[200000] + ttl_str;
		}else if(hash >= 203000 && hash < 204000){
			if($("#id200003").attr("class") != "outline-open" ) ApcWorks.MenuOpen(i+200003);
		}else{
			ApcWorks.MenuOpen(i+hash);
		}
		if(hash <= 200009) document.title = page_title[hash] + ttl_str;
	}else if( hash >= 300000 && hash < 400000 ){//case 
		acc1.openPanel(3);	ApcCasestudy.MenuOpen(i+300000,hash);
		document.title = page_title[hash] + ttl_str;
	}else if( hash >= 400000 && hash < 500000 ){
		acc1.openPanel(4);	ApcNews.MenuOpen(i+hash);
		document.title = page_title[hash] + ttl_str;
	}else if( hash >= 500000 && hash < 600000 ){
		acc1.openPanel(5);	ApcRecruit.MenuOpen(i+hash);
		document.title = page_title[hash] + ttl_str;
	}else if( hash >= 600000 && hash < 700000 ){
		acc1.openPanel(6);	ApcContactUs.MenuOpen(i+hash);
		if(hash == 600000) document.title = page_title[hash] + ttl_str;
		else document.title = page_title[hash] + page_title[600000] + ttl_str;
	}
	/************ For Google Analytics ********************/
	var virtual_page = "/#" + load_key;
	if(urchinTracker() != 0){
		urchinTracker(virtual_page); 	
	}
	/************ For Google Analytics End ********************/
};

function set_Btn_MouseOver(id) {
	$("img.mouse-over").mouseover(function(){ $btn_img(this); });	$("img.mouse-over").mouseout(function(){ $btn_img(this,1); });	$("img.mouse-over").mousedown(function(){ $btn_img(this,1); });
	//$("#works-2-1-itweb a img").mouseover(function(){ $btn_img(this); });	$("#works-2-1-itweb a img").mouseout(function(){ $btn_img(this,1); });	$("#works-2-1-itweb a img").mousedown(function(){ $btn_img(this,1); });
};

Ory.Widget.LinkHistorySet = function(){
		jQuery("a[@rel='history']").click(function(){
			var hash = this.href;
			hash = hash.replace(/^.*\.\/?c=/, '');
			if(!hash) hash = 1;
			jQuery.historyLoad(hash);
			return false;
		});
		
		jQuery("a[@rel='history2']").click(function(){
			var hash = this.href;
			hash = hash.replace(/^.*\.\/?c=/, '');
			jQuery.historyLoad(hash);
		});
};

function LinkBtn(ele,m,i){
	var hash = ele.href;
	hash = hash.replace(/^.*?c=/, '');
	if(hash == "./") hash = 1;
	if(!m){
		if(!hash) hash = 1;
		jQuery.historyLoad(hash);
	}else if(m){
	
		if(!hash) hash = 1;
		jQuery.historyLoad(hash);
	}
	return false;
};

var local_link = new Array();
//var TabbedPanels1 = "";
//var fg_LinkBtnSet_1;
/*             var TabbedPanels1;   ------------ */
function LinkBtnSet(ct){//alert(ct);
	/*if(!fg_LinkBtnSet_1){
		fg_LinkBtnSet_1 = ct;
		return;
	}*/
	local_link[ct] = $('#'+ct)[0].getElementsByTagName("A");
	for(var i=0; i<local_link[ct].length; i++){
		if(local_link[ct][i].getAttribute("rel") == "history"){
			local_link[ct][i].onclick = function () {
				LinkBtn(this,0);
				return false;
			}
		}
	}
	if(ct == "ct200003"){
		//if(!TabbedPanels1) TabbedPanels1 = new Spry.Widget.TabbedPanels("TabbedPanels1");
	}	
	ThickBox_Ini_Set(ct);
	set_Btn_MouseOver(ct);
	fg_LinkBtnSet_1 = false;
}

var TC_flag_array = new Array;
function ThickBox_Ini_Set(ct){//For ThickBox
	var domChunk = "#"+ct+" a.thickbox";
	tb_init(domChunk);
}

var flag_file_option1 = "";
var flag_file_option2 = "";

Ory.Widget.SlideMenu.prototype.MenuOpen = function(ele,op1,op2){
	var a = this.menuWidth;// - Menu Width
	var t = ele;
	var clname = $('#'+ele).attr("class");
	$('#'+ele).addClass("openmove");
	//this.pw = this.ele.parentNode.clientWidth;//IE7Bug
	this.pw = $('#'+this.id)[0].clientWidth;
	this.targetMenu = t;
	if(this.id == "ApcWorks"){
		this.ml = (this.MenuLength - 2 )*a;//alert("ApcWorks");
	}else{
		this.ml = (this.MenuLength )*a;//alert(11);
	}
	/* ==== Option Set ===*/
	if(op1 && !op2){/*var get_file = op1 + ".html.php";*///!Check
		var get_file = op1 + ".html";
		var res_id = t.replace(/id/i,"ct");//!Check
	}else if(!op2){/*var get_file = t.replace(/id/i,"") + ".html.php";*/
		var get_file = t.replace(/id/i,"") + ".html";
		var res_id = t.replace(/id/i,"ct");
	}
	flag_file_option1 = op1;
	flag_file_option2 = op2;
	/* ==== Option Set END ===*/

	var j = this.fc;
	var w = this.pw;
	var wl = w-this.ml;
	var wq = parseInt(wl/this.fc);
	var s = this.id + ".MenuMove('" + t + "'," + wq + ");"
	for(var i=1; i < j; i++){
		s += "setTimeout(\"" + this.id + ".MenuMove('" + t + "'," + wq + ")\"," + i*this.fs +");";
	}
	eval(s);
	return true;
};

Ory.Widget.SlideMenu.prototype.MenuHeight = function(){
///For Menu Heigth
	var dv;
	var g2_Height;
	if($('#'+this.MenuList[this.currentMenu]).height() > g_Height){
		g2_Height = $('#'+this.MenuList[this.currentMenu]).height();
	}else{
		g2_Height = g_Height;
	}
	
	for(var i=0; i<this.MenuList.length; i++){
		dv = $('#'+this.MenuList[i])[0].getElementsByTagName("DIV");
		this.MenuBtnList[i] = dv[0];
		if(this.currentMenu != i) $('#'+this.MenuList[i]).height(g2_Height);
		this.MenuBtnList[i].firstChild.style.height = g2_Height+"px";
	}
	//if(($('#'+this.targetMenu)[0].clientHeight) > g_Height) {
		for(var i=0; i<this.MenuBtnList.length; i++){
			$('#'+this.MenuList[i])[0].style.height = this.MenuBtnList[i].firstChild.style.height = g2_Height+"px";
		}
	//}
};

Ory.Widget.SlideMenu.prototype.MenuMove = function(t,ww1){
	var o = $('#'+this.targetMenu);
	if(o.attr("class") != "outline-open"){
		var w = this.pw;
		var wl = w-this.ml;
		var ow = o[0].clientWidth;
		var ww = ow + ww1;//-1 ;
		var ws = w - ww - this.ml;//80
		var obj = $('#'+this.MenuList[this.currentMenu]);
		//var obj0 = obj[0];	
		obj.attr("className","outline-move");
		if(ws <= obj[0].clientWidth && ws >= this.menuWidth){
			obj.css("width",(ws+18)+"px");
		}
		if(ww <= wl){
			o.css("width",ww+"px");
		}else{//Display Fix	
			this.MenuFix(this.targetMenu);
			return;
		}
	}
};

Ory.Widget.SlideMenu.prototype.MenuFix = function(ele){
	//var o = $('#'+ele)[0];
	var o1 = $('#'+ele);
	var o2 = $('#'+this.MenuList[this.currentMenu]);
	var e;
	o1.attr("class","outline-open");
	o1.css({width:"auto",height:"auto"});
	if(this.currentMenu < this.MenuIdNumList[ele]){
		o2.attr("class","outline-left");
		o2.css("width",this.menuWidth + "px");
	}else if(this.currentMenu > this.MenuIdNumList[ele]) {
		o2.attr("class","outline");
	}
	this.currentMenu = this.MenuIdNumList[ele];
	var o3;
	for(var i = 0; i < this.MenuLength; i++){
		o3 = $('#'+this.MenuList[i]);
		if( i < this.currentMenu) {//this.MenuIdNumList[MenuList[i]]
			o3.attr("class","outline-left");
			o3.css("width",this.menuWidth + "px");
			//$('#'+this.MenuList[i])[0].style.height = g_Height+"px";
			o1.before(o3);
		}else if( i > this.currentMenu){
			o1.before($('#'+this.MenuList[i]));
			o3.before(o1);
			o3.attr("class","outline");
			o3.css("width",this.menuWidth + "px");
			//----------$('#'+this.MenuList[i])[0].style.height = g_Height+"px";
		}
	}

	if(o1.clientHeight < g_Height){
			//o.style.height = g_Height+"px";	
	}
		//alert(this.currentMenu);alert(apcHomeBody.currentMenu);
		//this.MenuHeight();
	if(flag_file_option1 && !flag_file_option2){//alert(1);
		/*var get_file = op1 + ".html.php";*///!Check
		var get_file = "./" + flag_file_option1 + ".html";
		var res_id = ele.replace(/id/i,"ct");//!Check
	}else if(!flag_file_option2){
		/*var get_file = t.replace(/id/i,"") + ".html.php";*/
		var get_file = "./" + ele.replace(/id/i,"") + ".html";
		var res_id = ele.replace(/id/i,"ct");
	}
	
	var menu_Height_change_str = "setTimeout(\"" + this.id + ".MenuHeight()\",300);";
	//var menu_Height_change_str = this.id + ".MenuHeight();";
	//----------------------------
	if(!flag_file_option2){ 
		if((!flag_file_option1 && $('#'+res_id).html() == "#") || flag_file_option1){
			$('#'+res_id).html("");//loadHTML(get_file,res_id);
			$("#"+res_id).load(get_file, function(html, status){
				if(status == "success"){
					$(function(){
						LinkBtnSet(ele.replace(/id/i,"ct"));
						eval(menu_Height_change_str);
					});
				}
			});
		}else{
			set_Btn_MouseOver(null);
			//LinkBtnSet(ele.replace(/id/i,"ct"));
		}
	}
	flag_file_option1 = false;
	flag_file_option2 = false;
	/*document.getElementById(this.id).scrollTo(0,10);*/
	//var scl_id = this.id
	//scl_id.scrollTop -= 300;
	$("#"+this.id)[0].scrollTop = 0;
	eval(menu_Height_change_str);
	/*-----------------------LinkBtnSet(ele.replace(/id/i,"ct"));-----------------------------------*/
	return;
};

document.write('<style type="text/css" id="style-submenu-2">');
document.write('.SlidingPanels { height: '+ (g_Height-110) +'px}');//for SlideMenu
document.write('.SlidingPanelsContent { height: '+ (g_Height-110) +'px}');//for SlideMenu
document.write('.sub-menu-v a{ height: '+ g_Height +'px}</style>');//for sub-Menu

/* for Safari */
if ($.browser.safari) {
	document.write('<link href="css/safari.css" rel="stylesheet" type="text/css" />');	
}


function jquery_dump($obj) {/*  Test Dump アップ時削除　*/
	var dumphtml = [];
	if($.browser.msie) {
		for(var i = 0; i < $obj.length; i++) {
			dumphtml.push('[' + i + '] ');
			dumphtml.push($obj[i].outerHTML.replace(/^[\r\n\t]+/, ''));
			dumphtml.push("\n");
		}
	} else {
		for(var i = 0; i < $obj.length; i++) {
			dumphtml.push('[' + i + '] '
				+ '<' + $obj[i].nodeName.toLowerCase());
			for(var j = 0; j < $obj[i].attributes.length; j++) {
				dumphtml.push(' ' + $obj[i].attributes[j].nodeName + '="' 
					+ $obj[i].attributes[j].nodeValue + '"');
			}
			dumphtml.push('>' + $obj[i].innerHTML);
			dumphtml.push('<\/' + $obj[i].nodeName.toLowerCase() + '>');
			dumphtml.push("\n");
		}
	}
	alert(dumphtml.join(''));
}
