$(function() {

var mapPlots = {};
var showMap = false;

// init(Y) {{{
var init = function() {
	addEvents();

	if (undefined == yadoPlots) {
		Y.log("invalid data.");
	}
	else {
		mapPlots = yadoPlots;
	}
//	getMap();

	setInterval("doSlide()", 5000);
};

// }}}
// addEvents() {{{

var addEvents = function() {
	$("#map-toggle").click(function(e) {
		var options = {
			to: {
				height:100
			}
		};
		$("#map").toggle('blind', options, 500, function() {
			var text = showMap ? "Show MAP" : "Hide MAP";
			$("#map-toggle").html(text);
			showMap = !showMap;
			getMap();
		});
	});
};

// }}}
// getMap() {{{

getMap = function() {

	var g = google.maps;

	var centerPoint = new g.LatLng(34.985441,135.759087);

	var myOptions = {
		zoom: 15,
		center: centerPoint,
		mapTypeId: g.MapTypeId.ROADMAP,
		scaleControl: true
	};
	var map = new g.Map(document.getElementById("map"), myOptions);

	for (var yadoId in mapPlots) {

		var data = mapPlots[yadoId];

		var markerPoint = new g.LatLng(data.map.lat, data.map.lon);
	
		var marker = new g.Marker({
			position: markerPoint,
			map : map,
			title : data.name
		});
	}

};
// }}}
// doSlide() {{{

doSlide = function() {
	var $active = $('#slideshow img.active');
	if ( $active.length == 0 ) $active = $('#slideshow img:last');
	var $next =  $active.next().length ? $active.next() : $('#slideshow img:first');
	$active.addClass('last-active');
	$next.css({opacity: 0.0})
	.addClass('active')
	.animate({opacity: 1.0}, 1500, function() {
		$active.removeClass('active last-active');
	});
};

// }}}
init();

});

