
$(document).ready(function() {
	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("section-content-map"));
		map.setCenter(new GLatLng(37.174556,138.235237), 14);  
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl(true));
		map.enableScrollWheelZoom();
		map.addControl(new GScaleControl());
		point = new GLatLng(37.174556,138.235237);
		marker = new GMarker(point);
		map.addOverlay(marker);
		marker.openInfoWindow("<strong>越後上越 天地人博<\/strong><br \/>住所：上越市西本町４-１８-１２ 直江津屋台会館<br \/><center><img src=\"/wp-content/themes/tenchijin/images/yataikaikan.jpg\" /><br \/>～&nbsp;お車&nbsp;～<br \/>北陸自動車道上越ICから約15分<br \/>上信越自動車道上越高田ICから約20分<br \/>春日山周辺から約15分<br \/>五智周辺から約10分<br \/>～&nbsp;徒歩&nbsp;～<br \/>ＪＲ直江津駅から約15分</center>");
	}

	scrollwidth = $('#section-1').width();

	$("#about-tabmenu-1 a").addClass('current');
	$('#aboutslider').animate({scrollLeft:0}, 'slow','easeOutQuart');

	// クリック時にタブの画像を切り替え	
	$('#about-tabmenu li a,#sections .section-content-navi-next a,#sections .section-content-navi-prev a,#sectioncontentnavi1-3').bind('click',function(e){
		$(this).stop();
		idx = (this.id.split('-')[1] - 1);

		if ($("#about-tabmenu-" + (idx+1) + " a").attr('class')) return false;

		var maxcnt = $('#about-tabmenu li').length;
		for(var loop = 0; loop < maxcnt; loop++) {
			var target = '#about-tabmenu-' + (loop+1) + ' a';
			if (loop == idx) {
				$(target).addClass('current');
			} else {
				$(target).removeClass('current');
			}	
		}

		scrollmargin = idx * scrollwidth;
        $('#aboutslider').animate({scrollLeft:scrollmargin}, 'slow','easeOutQuart');
        
        return false;
	});
	jQuery.extend(jQuery.easing,
	{
		easeOutQuart: function (x, t, b, c, d) {
			return -c * ((t=t/d-1)*t*t*t - 1) + b;
		}
	});



    $('.bubbleInfo').each(function () {
        var distance = 10;
        var time = 250;
        var hideDelay = 500;

        var hideDelayTimer = null;

        var beingShown = false;
        var shown = false;
        var trigger = $('.trigger', this);
        var info = $('.popup', this).css('opacity', 0);

		function animateDisp(){
					$('.popup').css('opacity', 0);
		
		            // reset position of info box
		            beingShown = true;
		            info.css({
		                top: 90,
		                left: 840,
		                display: 'block'
		            }).animate({
		                left: '-=' + distance + 'px',
		                opacity: 1
		            }, time, 'swing', function() {
		                beingShown = false;
		                shown = true;
						info.css('display','block');
						info.css('opacity','1');
		            });
		}
		
        $([trigger.get(0), info.get(0)]).click(function () {
            if (hideDelayTimer) clearTimeout(hideDelayTimer);
			animateDisp();
            return false;
        });
        
        $([trigger.get(0), info.get(0)]).mouseover(function () {
            if (hideDelayTimer) clearTimeout(hideDelayTimer);
            if (beingShown || shown) {
                // don't trigger the animation again
                return;
            } else {
				animateDisp();
            }
            return false;
        }).mouseout(function () {
            if (hideDelayTimer) clearTimeout(hideDelayTimer);
            hideDelayTimer = setTimeout(function () {
                hideDelayTimer = null;
                info.animate({
                    left: '+=' + distance + 'px',
                    opacity: 0
                }, time, 'swing', function () {
                    shown = false;
                    info.css('display', 'none');
                });

            }, hideDelay);

            return false;
        });
    });
});

