var margin = [
	[],
	[0, 0, 0, 30],
	[0, 0, 0, 37],
	[0, 0, 0, 34],
	[0, 30, 0, 0],
	[0, 37, 0, 0],
	[0, 34, 0, 0],
	[34, 0, 0, 0],
	[0, 0, 32, 0]
];

var move = [
	{},
	{x : 35, y : -162},
	{x : 35, y : -101},
	{x : 35, y : -38},
	{x : -248, y : -162},
	{x : -255, y : -101},
	{x : -252, y : -38},
	{x : -94, y : 55},
	{x : -94, y : -248},
];

var timer;
var show_flg = false;

function showBalloon(no){
	document.body.style.cursor = 'pointer';
	$('Name').innerHTML = '<a href="' + school[no].url + '" target="_blank ">' + school[no].name + '</a>';
	$('Info').innerHTML = '●所在地<br />' + school[no].address + '<br /><a href="http://maps.google.com/maps?f=q&hl=ja&geocode=&time=&date=&ttype=&ie=utf-8&z=16&om=1&q=' + encodeURL(school[no].address) + '" target="_blank"><img alt="Googleマップで周辺を表示する" src="./img/school/school_googlemap.gif" /></a>';
	$('Balloon').style.left = (school[no].x + move[school[no].type].x) + 'px';
	$('Balloon').style.top = (school[no].y + move[school[no].type].y) + 'px';
	$('Balloon').style.paddingTop = margin[school[no].type][0] + 'px';
	$('Balloon').style.paddingRight = margin[school[no].type][1] + 'px';
	$('Balloon').style.paddingBottom = margin[school[no].type][2] + 'px';
	$('Balloon').style.paddingLeft = margin[school[no].type][3] + 'px';
	$('Balloon').style.backgroundImage = 'url(./img/school/school_fukidashi_0' + school[no].type + '.gif)';
	Element.show('Balloon');
	show_flg = true;
}

function hideBalloon(){
	document.body.style.cursor = 'default';
	timer = setTimeout("killBalloon()", 1500);
	show_flg = false;
}

function killBalloon(){
	if(!show_flg){
		Element.hide('Balloon');
		clearTimeout(timer);
	}
}

function activeBalloon(){
	clearTimeout(timer);
	show_flg = true;
}

//URL Encode (UTF-8)
function encodeURL(str) {
	var character = '';
	var unicode	 = '';
	var string		= '';
	var i				 = 0;

	for (i = 0; i < str.length; i++) {
		character = str.charAt(i);
		unicode	 = str.charCodeAt(i);

		if (character == ' ') {
			string += '+';
		} else {
			if (unicode == 0x2a || unicode == 0x2d || unicode == 0x2e || unicode == 0x5f || ((unicode >= 0x30) && (unicode <= 0x39)) || ((unicode >= 0x41) && (unicode <= 0x5a)) || ((unicode >= 0x61) && (unicode <= 0x7a))) {
				string = string + character;
			} else {
				if ((unicode >= 0x0) && (unicode <= 0x7f)) {
					character	 = '0' + unicode.toString(16);
					string += '%' + character.substr(character.length - 2);
				} else if (unicode > 0x1fffff) {
					string += '%' + (oxf0 + ((unicode & 0x1c0000) >> 18)).toString(16);
					string += '%' + (0x80 + ((unicode & 0x3f000) >> 12)).toString(16);
					string += '%' + (0x80 + ((unicode & 0xfc0) >> 6)).toString(16);
					string += '%' + (0x80 + (unicode & 0x3f)).toString(16);
				} else if (unicode > 0x7ff) {
					string += '%' + (0xe0 + ((unicode & 0xf000) >> 12)).toString(16);
					string += '%' + (0x80 + ((unicode & 0xfc0) >> 6)).toString(16);
					string += '%' + (0x80 + (unicode & 0x3f)).toString(16);
				} else {
					string += '%' + (0xc0 + ((unicode & 0x7c0) >> 6)).toString(16);
					string += '%' + (0x80 + (unicode & 0x3f)).toString(16);
				}
			}
		}
	}

	return string;
}

function toggle(){
	Element.toggle('Map');
	Element.toggle('Table');
}
