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

$(function() {
	// 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);
			
		});
	}

	// gooogle search
	$('#search_box input').val('サイト内検索')
	   .css("color","#969696");
	$('#search_box input').focus(function(){
		if(this.value == 'サイト内検索'){
			$(this).val('').css('color','#000');
		}
	});
	$('#search_box input').blur(function(){
		if(this.value == ''){
			$(this).val('サイト内検索')
			     .css('color','#969696');
		}
		if(this.value != 'サイト内検索'){
			$(this).css('color','#000');
		}
	});

	// 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});
});


function jump(){
    
	var target = "";

	var url = document.form1.select.options[document.form1.select.selectedIndex].value;

	if(url != "" ){

		if(target == 'top'){

			top.location.href = url;

		}
		else if(target == 'blank'){

			window.open(url, 'window_name');

		}
		else if(target != ""){

			eval('parent.' + target + '.location.href = url');

		}
		else{

			location.href = url;

		}

	}

}

