$(document).ready(function(){
	scroller.init();
	//information.init();

	/* メインメニュー */
	var current = $('body').attr('id');
	$('body:not(#cafe) #headerContainer .header ul.mainMenu > li.'+current+' > a').css('background-position','0 -9px');

	$('body:not(#cafe) #headerContainer .header ul.mainMenu > li').hover(function(){
		if(current != $(this).attr('class')) $(this).children('a').css('background-position','0 -9px');
		if($(this).attr('class')=='concept','new'){
			$(this).css('background-color','#ffffff');
			$(this).children('ul').slideDown('fast');
		}
	},function(){
		if(current != $(this).attr('class')) $(this).children('a').css('background-position','0 0');
		if($(this).attr('class')=='concept','new'){
			$(this).children('ul').hide();
		}
	});


	/* アーカイブリンク */
	$('#contentsContainer .archivesContainer > ul.archivesList > li > a').each(function(){
		if($(this).attr('class') == 'current'){
			$(this).siblings('ul').show();
		}
	}).click(function(){
		if( $(this).attr('class') == 'current' ) $(this).removeClass('current');
		else $(this).addClass('current');
		$(this).siblings('ul').slideToggle('fast');
	});

	/* 記事 */
	$('#contentsContainer .entry .close').each(function(entryIndex){
		if(!$(this).parent().hasClass('defaultView')) $(this).parent().hide();
	}).children('a').click(function(){
		$(this).parents('div.entryBody').slideUp('fast');
	}).parents('div.entry').children('div.title').click(function(){
		$(this).siblings('div.entryBody').slideToggle('fast');
	}).hover(function(){
		$(this).css('color','#641919').find('span').css('color','#641919');
	},function(){
		$(this).css('color','#000000').find('span').css('color','#b4b4b4');
	});

	var defaultValue = new Array();
	defaultValue[0] = '全角で登録してください ： 山田太郎';
	defaultValue[1] = '半角で登録してください ： nest@co.jp';
	defaultValue[2] = '全角または半角で登録してください';
	
	$('.textInput').each(function(inputIndex){
		$(this).focus(function(){
			if( $(this).val() == defaultValue[inputIndex] ) {
				$(this).val('').css('color','#000000');
			}
		}).blur(function(){
			if( $(this).val() == '' ) {
				$(this).val(defaultValue[inputIndex]).css('color', '#b4b4b4');
			}
		});
	});
	var imageLinkLocation = new Array();
	var chasheImage = new Array();
	for(i = 0; i < $('input.linkImage, .linkImage a > img, a.linkImage > img').length; i++) {
		imageLinkLocation[i] = $('input.linkImage, .linkImage a > img, a.linkImage > img').eq(i).attr('src');
		chasheImage[i] = new Image();
		chasheImage[i].src = imageLinkLocation[i].replace(new RegExp('(_on)?(\.gif|\.jpg|\.png)$'), "_on$2");
	}
	$('input.linkImage, .linkImage a > img, a.linkImage > img').each(function(imageIndex){
		$(this).hover(function(){
			$(this).attr('src',chasheImage[imageIndex].src);
		}, function(){
			$(this).attr('src',imageLinkLocation[imageIndex]);
		});
	});
});

//
//	 formName内の文字色をハイ色にする
//
function formNameColorb4b4b4()
{
	$("input[name='formName']").css('color','#b4b4b4');
}

//
//	 formName内の文字色を黒にする
//
function formNameColor000()
{
	$("input[name='formName']").css('color','#000000');
}

//
//	formMail内の文字色を灰色にする
function formMailColorb4b4b4()
{
	$("input[name='formMail']").css('color','#b4b4b4');
}

//
//	 formMail内の文字色を黒にする
//
function formMailColor000()
{	
	$("input[name='formMail']").css('color','#000000');
}

//
//	formTitle内の文字色を灰色にする
function formTitleColorb4b4b4()
{
	$("input[name='formTitle']").css('color','#b4b4b4');
}

//
//	 formTitle内の文字色を黒にする
//
function formTitleColor000()
{	
	$("input[name='formTitle']").css('color','#000000');
}

// Information
var information = {
	targetPosition : 0,
	currentPosition : 0,
	targetId : "",
	scrollSpeed : 20,
	init : function() {
		$('a[href*=#info?]').click(function(){
			$(this).attr('href').match(/#/g);
			scroller.targetId = RegExp.rightContext;
			scroller.targetPosition = $("#"+scroller.targetId).offset().top;
			scroller.currentPosition = $(document).scrollTop();
			scroller.scroll();
			return false;
		});
	},
	scroll : function() {
		var moveToPosition;
		if(Math.abs(scroller.currentPosition-scroller.targetPosition) <= 1){
			window.scrollTo(0,scroller.targetPosition);
			scroller.currentPosition = 0;
		} else {
			moveToPosition = Math.round(scroller.currentPosition+((scroller.targetPosition-scroller.currentPosition)/3));
			window.scrollTo(0, moveToPosition);
			scroller.currentPosition = moveToPosition;
			setTimeout(scroller.scroll,scroller.scrollSpeed);
		}
	}
}

// スクローラー
var scroller = {
	targetPosition : 0,
	currentPosition : 0,
	targetId : "",
	scrollSpeed : 20,
	init : function() {
		$('a[href*=#],a[href*=#info?]').click(function(){
			$(this).attr('href').match(/#/g);
			scroller.targetId = RegExp.rightContext;
			scroller.targetPosition = $("#"+scroller.targetId).offset().top;
			scroller.currentPosition = $(document).scrollTop();
			scroller.scroll();
			return false;
		});
	},
	scroll : function() {
		var moveToPosition;
		if(Math.abs(scroller.currentPosition-scroller.targetPosition) <= 1){
			window.scrollTo(0,scroller.targetPosition);
			scroller.currentPosition = 0;
		} else {
			moveToPosition = Math.round(scroller.currentPosition+((scroller.targetPosition-scroller.currentPosition)/3));
			window.scrollTo(0, moveToPosition);
			scroller.currentPosition = moveToPosition;
			setTimeout(scroller.scroll,scroller.scrollSpeed);
		}
	}
}
