// written in UTF-8
// require jQuery v1.3.2 >

$(function() {
	// menu
	$(function() {
		var c = $('#topicpath a:nth-child(2)').attr('href') || '/';
		$('#menu li a').each(function() {
			if ($(this).attr('href') == c) {
				$(this).addClass('current');
			}
		});
	});

	// Simplified roll over
	$('.ro a img, a.ro img, input[type="image"].ro').hover(
		function() { $(this).css('opacity', 0.7) },
		function() { $(this).css('opacity', 1.0) }
	);

	// Scroller
	$('.toPageTop a').click(function() {
		$(this).blur();
		$('html, body').animate({ scrollTop: 0 }, 'fast');
		return false;
	});

	// form input hinting
	$(function() {
		var e = $('.helptext[title]');
		var t = e.attr('title');
		e.blur(function() {
			if (e.val() == '') {
				e.val(t).addClass('hinting');
			}
		})
		.focus(function() {
			if (e.val() == t) {
				e.val('').removeClass('hinting');
			}
		})
		.parents('form:first').submit(function() {
			if (e.val() == t) {
				e.triggerHandler('focus');
			}
		})
		.end()
		.blur();
	});

	// top header-image
	if ($('#gallery').length) {
		$(function() {
			var cache = [];
			var c = 0;
			$('#gallery-inner h2 img').each(function(i, elm) {
				var a = document.getElementById('PHOTO0' + (i + 1)).title;
				
				//cache.push($('<img />').attr('src', 'images/top/sample0' + parseFloat(i + 1) + '.jpg'));
				cache.push($('<img />').attr('src', a));
				
				//alert( i +":" + cache[i].attr('src') + ":" + a);
				
				$(elm).click(function() {
					$('#top_window').css('backgroundImage', 'url(' + cache[i].attr('src') + ')');
					c = i;
				});
			}).css('cursor', 'pointer');
			
			var e = cache.length - 1;
			setInterval(function() {
				if (++c > e) c = 0;
				$('#top_window').css('backgroundImage', 'url(' + cache[c].attr('src') + ')');
			}, 10000);
			
		});
	}

	// Image modalbox ( a > img )
	$('a.mb').nyroModal({
		galleryCounts: null,
		addImageDivTitle: true
	});

	// gallery
	$('#thumbnails li a.mb').nyroModal({
		galleryCounts: 'galleryCounts',
		addImageDivTitle: true
	});

	// swf
	$('a.ym').nyroModal({
		processHandler: function(settings) {
			$.nyroModalSettings({
				type: 'swf',
				width: 640,
				height: 385
			});
		}
	});

	$('#submenu a').each(function() {
		if ($(this).attr('href') == $('#topicpath a:last').attr('href')) {
			$(this).addClass('current');
		}
	});

	// form error message
	$(function() {
		var messageCSS = {
			display: 'block',
			position: 'absolute',
			zIndex: 100,
			top: 0, right: 0, bottom: 0, left: 0,
			border: '1px solid #C00',
			backgroundColor: '#FFC',
			cursor: 'pointer'
		};

		var animationCSS = {
			top: '-25px', right: '-25px', bottom: '-25px', left: '-25px',
			opacity: 0.1
		};

		$('div.error-message').css(messageCSS).click(function() {
			$(this).animate(animationCSS, 'normal', function() {
				$(this).css('display', 'none');
			});
			$(this).prev('input, textarea').get(0).focus();
		});
	});

	if (location.hostname == 'morino-hatake.localhost') {
		$('.cake-sql-log').css('display', 'block');
	}
});


$(function() {
	$('a.mv').nyroModal({width:800,height:600});
});

