var state_po = [
		[000,000,000,000],
		[504,  0,574, 70],	//北海道
		[504, 87,574,122],	//青森県
		[539,122,574,156],	//岩手県
		[539,156,574,191],	//宮城県
		[504,122,539,156],	//秋田県
		[504,156,539,191],	//山形県
		[504,191,574,226],	//福島県
		[539,226,574,296],	//茨城県
		[504,226,539,261],	//栃木県
		[469,261,504,296],	//群馬県
		[504,261,539,296],	//埼玉県
		[539,296,574,365],	//千葉県
		[504,296,539,330],	//東京都
		[504,330,539,365],	//神奈川県
		[434,226,504,261],	//新潟県
		[400,226,434,261],	//富山県
		[365,226,400,261],	//石川県
		[365,261,400,296],	//福井県
		[469,296,504,330],	//山梨県
		[434,261,469,330],	//長野県
		[400,261,434,330],	//岐阜県
		[469,330,504,365],	//静岡県
		[400,330,469,365],	//愛知県
		[365,330,400,365],	//三重県
		[365,296,400,330],	//滋賀県
		[330,296,365,330],	//京都府
		[295,330,330,365],	//大阪府
		[261,330,295,400],	//兵庫県
		[330,330,365,365],	//奈良県
		[295,365,365,400],	//和歌山県
		[226,330,261,365],	//鳥取県
		[191,330,226,365],	//島根県
		[226,365,261,400],	//岡山県
		[191,365,226,400],	//広島県
		[157,330,191,400],	//山口県
		[226,451,261,486],	//徳島県
		[226,416,261,451],	//香川県
		[191,416,226,451],	//愛媛県
		[191,450,226,486],	//高知県
		[ 69,364,139,400],	//福岡県
		[ 35,364, 70,400],	//佐賀県
		[ 35,400, 70,434],	//長崎県
		[ 70,400,104,469],	//熊本県
		[104,400,139,434],	//大分県
		[104,435,139,504],	//宮崎県
		[ 70,469,104,504],	//鹿児島県
		[  0,468, 35,504],	//沖縄県
		[401,415,540,486]		//その他
	];

function get_state_by_xy(cx,cy) {
	var i;
	
	for(i=0; i<=48;i++)
	{
		if ( state_po[i][0] <= cx && state_po[i][1] <= cy && cx <=state_po[i][2] && cy <= state_po[i][3] ) return i;
	}
	return 0;
}

function get_state(e)
{
	var cx = e.pageX - $('#map').position().left;
	var cy = e.pageY - $('#map').position().top;
	
	var state = get_state_by_xy(cx,cy);
	
	if(!state) return 0; else return state;
}

var last_view_state = 0;
function cur(state)
{
	//if( last_view_state == state ) return;
	
	var cur_x = state_po[state][0] + 16;
	var cur_y = state_po[state][1] + 36;
	var cur_size_x = state_po[state][2] - state_po[state][0] ;
	var cur_size_y = state_po[state][3] - state_po[state][1] ;
	
	var attr = "visibility: visible;position: absolute; width:" + cur_size_x + "px;height:" + cur_size_y + "px;top:" + cur_y + "px;left:" + cur_x + "px;opacity: 0.5;filter: alpha(opacity=50);" ;
	$("#chl").attr("style" , attr);
	
	last_view_state = state;
	//$('#map').toggle('pulsate' );
	//$('#chl').toggle( 'puff' );
	//$('#chl').fadeIn(1000);  
}


jQuery(document).ready(function()
{
	$('#map').click(function(e){
		
		var state = get_state(e);
		
		if(state) {
			cur(state);
			document.getElementById("bbs_frame").src = "bbs.php?state="+state;
			//$('#bbs_frame').attr( "src" , "bbs.php?state=" + state );
		}
	});

/*
	$('#map').mousemove(function(e){
	
		//$('#pointer').text( "x:" + x + " y:" + y);
		
		var state = get_state(e) ;
		if(state) cur(state);
	});
*/
	
});
