MAP = {
/*
	scale: 3,
	min_size: 2,
	max_size: 4,
	small: function(){
		if (this.scale > this.min_size) {
			$('#the_map').effect('scale', { percent: 80, origin: ['middle', 'center'] }, 200, function(){ MAP.rec(); });
			this.scale -= 1;
		}
	},
	large: function(){
		if (this.scale < this.max_size) {
			$('#the_map').effect('scale', { percent: 125, origin: ['middle', 'center'] }, 200, function(){ MAP.rec(); });
			this.scale += 1;
		}
	},
*/
	rec: function(){
		var win_h = $(window).height();
		var win_w = $(window).width();
		var obj_h = $('#the_map').height();
		var obj_w = $('#the_map').width();
		
		$('#frame').height(win_h);
		if (win_h < obj_h) {
			$('#mapframe').height(win_h + (obj_h-win_h)*2);
			$('#mapframe').css('margin-top', '-'+(obj_h-win_h)+'px');
		} else {
			$('#mapframe').height(obj_h);
			$('#mapframe').css('margin-top', '0');
		}
		if (win_w < obj_w) {
			$('#mapframe').width(win_w + (obj_w-win_w)*2);
			$('#mapframe').css('margin-left', '-'+(obj_w-win_w)+'px');
		} else {
			$('#mapframe').width(obj_w);
			$('#mapframe').css('margin-left', '0');
		}
		return { top: (obj_h-win_h)+'px', left: (obj_w-win_w)+'px' };
	}
}

function dragger()
{
	var opts = { cursor: 'move', containment: $('#mapframe') };
	$('#the_map').draggable(opts);
	$('#controller').draggable(opts);
}

var da = new Date();
var mm = da.getMonth()+1;
var nexm = (mm == 12) ? 1 : mm+1;
var prem = (mm == 1) ? 12 : mm-1;
var dd = Math.floor(da.getDate()/10)+1;
var bml = ['.m'+prem+'l','.m'+mm+'b','.m'+mm+'m','.m'+mm+'l','.m'+nexm+'b','.m'+nexm+'m'];
var ars = ['.m'+mm, bml[dd-1], bml[dd], bml[dd+1], bml[dd+2]];
if (dd > 1) {
	ars.push('.m'+nexm);
} else {
	ars.push('.m'+prem);
}
var classes = ars.join(',');

$(function(){
	dragger();
	$(window).resize(MAP.rec);
	pos = MAP.rec();
	$('#the_map').css(pos);
	
	$('p.img img, div#map_food div span').hover(
		function(){ $(this).parent().parent().css('z-index', 10).find('.explain').show() },
		function(){ $(this).parent().parent().css('z-index', 0).find('.explain').hide() }
	);
	$('div#map_food .explain').hover(
		function(){ $(this).show().parent().css('z-index', 10) },
		function(){ $(this).hide().parent().css('z-index', 0) }
	);
	
	$('div.flowers div, div#map_food').hide();
	$('#select_by_flower a').click(function(){
		$('.flowers div, div#map_food').hide();
		$('#map_'+this.id+' div').show(1000);
	});
	$('#select_food a').click(function(){
		$('.flowers div').hide();
		$('#map_'+this.id).show(1000);
	});
	
	$('#select_by_season a').click(function(){
		$('div.flowers div, div#map_food').hide();
		$('.ma,'+classes).show(1000);
	});
	
	if (location.search == '?type=food') {
		$('#food').click();
	}
});

