//dom.event.addEventListener(window, 'load', init);

var msIE;
var header = 86;
var footer = 56;


j$('document').ready(function(){
	var tr = util.$('treeMenu1');
	var h = tr.offsetHeight;

	// kisei panel tab init
	initTab();

	// this script
	initResize();
    });



function initResize() {
    //msIE6 = (navigator.userAgent.indexOf("MSIE 6") != -1)? true : false;
    msIE = navigator.appVersion.charAt(22);

    var mapScroll = util.$('map_scroll');
    var tree1 = util.$('treeMenu1');
    var tree2 = util.$('treeMenu2');
    var scY = getScreenSize().y;

    //tree1.style.backgroundColor = "#EEEEEE";

    // set overlay panel size
    setPosition();

    // bind resize event
    if (msIE != 6) {
	dom.event.addEvent(window, 'resize', setPosition);
    }
}


function setPosition() {
    var mapScroll = util.$('map_scroll');
    var hosokuScroll = util.$('hosoku_scroll');
    var hosokuScrollH = hosokuScroll.offsetHeight;

    var bizBanner = util.$('biz_banner_free');
    var bizBannerH = 0;
    if (bizBanner) {
	bizBannerH = bizBanner.offsetHeight;
    }

    var scY = getScreenSize().y;

    //console.debug('scY: ' + scY);
    //console.debug('hosoku scroll:' + hosokuScrollH);

    var tree1H = document.getElementById('treeMenu1').offsetHeight;
    var tree2H = document.getElementById('treeMenu2').offsetHeight;

    if(scY > 400) {
	if(document.getElementById('marquee')) {
	    var marq = document.getElementById('marquee').offsetHeight;

	    mapScroll.style.height = (scY-(header+footer+marq ))+"px";

	    var updateH = scY-(header+footer+marq + bizBannerH );
	    hosokuScroll.style.height = updateH +"px";
	} else {
	    if(msIE == "6") {
		//util.$("footer").style.marginTop = "-7px";
	    }

	    mapScroll.style.height = (scY-(header+footer))+"px";

	    var updateH = scY-(header+footer + bizBannerH);
	    hosokuScroll.style.height = updateH +"px";
	}

    }else {
	mapScroll.style.height = "610px";
	hosokuScroll.style.height = (610 - bizBannerH) + "px";
    }
    
    //alert('org:' + hosokuScrollH + ', new:' + updateH + ', tree:' + tree1H + '/' + tree2H + ', now:' + hosokuScroll.offsetHeight);

    return;
}



function __setPosition() {
    var mapScroll = util.$('map_scroll');
    var tree1 = util.$('treeMenu1');
    var tree2 = util.$('treeMenu2');
    var scY = getScreenSize().y;

    if(scY > 400) {
	if(document.getElementById('marquee')) {
	    var marq = document.getElementById('marquee').offsetHeight;
	    mapScroll.style.height = (scY-(header+footer+marq ))+"px";
	    if(tree1.style.display =="block") {
		tree1.style.height = (mapScroll.offsetHeight + mapScroll.offsetTop) - (tree1.offsetHeight+tree1.offsetTop) + tree1.offsetHeight + "px";
		ies(36,30);
	    }
	    if(tree2.style.display =="block") {
		tree2.style.height = (mapScroll.offsetHeight + mapScroll.offsetTop) - (tree2.offsetHeight+tree2.offsetTop) + tree2.offsetHeight + "px";
		ies(36,30);
	    }
	} else {
	    if(msIE == "6") {
		//util.$("footer").style.marginTop = "-7px";
	    }
	    mapScroll.style.height = (scY-(header+footer))+"px";
	    if(tree1.style.display =="block") {
		tree1.style.height = (mapScroll.offsetHeight + mapScroll.offsetTop) - (tree1.offsetHeight+tree1.offsetTop) + tree1.offsetHeight + "px";
		ies(10,10);
	    }
	    if(tree2.style.display =="block") {
		tree2.style.height = (mapScroll.offsetHeight + mapScroll.offsetTop) - (tree2.offsetHeight+tree2.offsetTop) + tree2.offsetHeight + "px";
		ies(10,10);
	    }
	}
    } else {
	mapScroll.style.height = "610px";
	tree1.style.height = "400px";
	tree2.style.height = "400px";
    }
	
}


function ies(ie6Num,ie7Num) {
    var mapScroll = util.$('map_scroll');
    var tree1 = util.$('treeMenu1');
    var tree2 = util.$('treeMenu2');

    return;

    if(msIE == "6") {
	if(tree1.style.display != "none" && 0) {
	    tree1.style.height =
		((mapScroll.offsetHeight + mapScroll.offsetTop) - 
		 (tree1.offsetHeight+tree1.offsetTop) + 
		 tree1.offsetHeight)-ie6Num +
		"px";
	}

	if(tree2.style.display != "none") {
	    tree2.style.height =
		((mapScroll.offsetHeight + mapScroll.offsetTop) -
		 (tree2.offsetHeight+tree2.offsetTop) + 
		 tree2.offsetHeight)-ie6Num +
		"px";
	}
    }

    if(msIE == "7") {
	if(tree1.style.display != "none") {
	    tree1.style.height =
		((mapScroll.offsetHeight + mapScroll.offsetTop) -
		 (tree1.offsetHeight+tree1.offsetTop) +
		 tree1.offsetHeight)-ie7Num + 
		"px";
	}

	if(tree2.style.display != "none") {
	    tree2.style.height = 
		((mapScroll.offsetHeight +
		  mapScroll.offsetTop) -
		 (tree2.offsetHeight+tree2.offsetTop) + 
		 tree2.offsetHeight)-ie7Num +
		"px";
	}
    }
}


function getScreenSize() {
    var obj = new Object();
    obj.x =
	document.documentElement.clientWidth  ||
	document.body.clientWidth  ||
	document.body.scrollWidth;

    obj.y = document.documentElement.clientHeight ||
	document.body.clientHeight || 
	document.body.scrollHeight;

    obj.mx = parseInt((obj.x)/2);
    obj.my = parseInt((obj.y)/2);

    return obj;
}

