$(document).ready(function() {

	// fancy box for all images on top
	$(".fancybox").fancybox({
		'titleShow'		: false
	});


//	do not use (problems with ie6)
//	$("#menu ul li").prepend("<span></span>");

	// add span tag
	if (!$("#menuitem2").hasClass("selected")) {
		$("#menuitem2").prepend("<span></span>");
	}
	if (!$("#menuitem4").hasClass("selected")) {
		$("#menuitem4").prepend("<span></span>");
	}
	if (!$("#menuitem6").hasClass("selected")) {
		$("#menuitem6").prepend("<span></span>");
	}
	if (!$("#menuitem8").hasClass("selected")) {
		$("#menuitem8").prepend("<span></span>");
	}
	
	// hover effect
	$("#menu ul li").hover(function() {	// on hover
		$(this).find("span").stop().animate({ 
			marginTop: "-37px"
		}, 200);
	} , function() {	// on hover out
		$(this).find("span").stop().animate({
			marginTop: "0"
		}, 200);
	});
	
	// redirect when clicking span element (for iphone/ipad)
	$("#menu ul li").click(function() {
//		var parent	= $(this).parent();
		var url		= $(this).find("a").attr("href");
		// redirect
		$(window.location).attr('href', url);
	});

	// 	add map
	var obj	= document.getElementById("map");
	if (null !== obj) {
		if (GBrowserIsCompatible()) {
			var map = new GMap2(obj);
			// add contols
			map.addControl(new GLargeMapControl());
			// start point
			googleMapDefaultView(map);
			// icon
			var icon = new GIcon();
			icon.image = 'images/map_logo.gif';
			icon.iconSize = new GSize(151, 52);
			icon.iconAnchor = new GPoint(76, 54);
			// set icon positions
			var hiragishi_icon_pos = new GLatLng(43.03252, 141.38087);
			var miyagaoka_icon_pos = new GLatLng(43.05805, 141.3122);
			// create marker
			var hiragishi_marker = new GMarker(hiragishi_icon_pos, icon);
			var miyagaoka_marker = new GMarker(miyagaoka_icon_pos, icon);
			// set events
			GEvent.addListener(hiragishi_marker, "click", function() {
				if (16 == map.getZoom()) {
					googleMapDefaultView(map);
				} else {
					map.setCenter(new GLatLng(43.033, 141.381), 16);
				}
			});
			GEvent.addListener(miyagaoka_marker, "click", function() {
				if (16 == map.getZoom()) {
					googleMapDefaultView(map);
				} else {
					map.setCenter(new GLatLng(43.057787, 141.312697), 16);
				}
			});
			map.addOverlay(hiragishi_marker);
			map.addOverlay(miyagaoka_marker);
		}
	}
	
});

function googleMapDefaultView(map)
{
	map.setCenter(new GLatLng(43.048, 141.345), 13);
}



