$(document).ready(function($){
	initRollOverImages();
	initRecipeBox();
	initProgramNav();
	setHeadSearch();
});

function initRollOverImages() {  
	var image_cache = new Object();  
	$(".ro a img").not("[src*='_on.']").not("[src*='_c.']").each(function(i) {
		var parentClass = $(this).parent().parent().attr("class");
		if(parentClass.indexOf("noro") == -1){
			var imgsrc = this.src;  
			var dot = this.src.lastIndexOf('.');  
			var imgsrc_on = this.src.substr(0, dot) + '_on' + this.src.substr(dot, 4);  
			image_cache[this.src] = new Image();  
			image_cache[this.src].src = imgsrc_on;  
			$(this).hover(  
				function() { this.src = imgsrc_on;},  
				function() { this.src = imgsrc; }  
			);
		};
	});  
}


$(function() {
	$('a[href*=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var target = $(this.hash);
			target = target.length && target;
			if (target.length) {
				var sclpos = 0;
				var scldurat = 800;
				var targetOffset = target.offset().top - sclpos;
				$('html,body')
					.animate({scrollTop: targetOffset}, {duration: scldurat, easing: "easeOutExpo"});
				return false;
			}
		}
	});
});


function initRecipeBox(){
	//表示の処理
	var $recipeBtn = $('#recipeBtn');
	var $recipeBox = $('#recipeBox');
	var $recipeBtnImg = $('#recipeBtnImg');
	if($("body").is(":has('.nowonair')")){
		$recipeBox.css('width','811px')
	}
	
	$recipeBtn.hover(function(){
		$recipeBox.css('opacity','0').css('display','block');
		$recipeBox.animate(
			{opacity: 1},
			{duration:200,queue: false}
		)
		$recipeBtnImg.attr('src','/img/common/gnav06_on.png');
	},
	function(){
		$recipeBox.animate(
			{opacity: 0},
			{duration:100,queue: false,complete:function(){$(this).css('display','none');}}
		)
		$recipeBtnImg.attr('src','/img/common/gnav06.png');
	});
}

function initProgramNav(){
	//表示の処理
	var $programNavBtn = $('#programNavBtn');
	var $programNav = $('#programNav');
	var $programNavBtnImg = $('#programNavBtnImg');
	
	$programNavBtn.hover(function(){
		$programNav.css('opacity','0').css('display','block');
		$programNav.animate(
			{opacity: 1},
			{duration:200,queue: false}
		)
		$programNavBtnImg.attr('src','/img/common/gnav03_on.gif');
	},
	function(){
		$programNav.animate(
			{opacity: 0},
			{duration:100,queue: false,complete:function(){$(this).css('display','none');}}
		)
		$programNavBtnImg.attr('src','/img/common/gnav03.gif');
	});
}

function setHeadSearch(){

	$('#headSearchTxt')
		.blur(function(){
			var $$=$(this);
			if($$.val()=='' || $$.val()==$$.attr('title')){
				$$.css('color', '#999')
					.val($$.attr('title'));
			}
		})
		.focus(function(){
			var $$=$(this);
			if($$.val()==$$.attr('title')){
				$(this).css('color', '#000')
							 .val('');
			}
		})
		.parents('form:first').submit(function(){
			var $$=$('#headSearchTxt');
			if($$.val()==$$.attr('title')){
				$$.triggerHandler('focus');
			}
		}).end()
		.blur();

}
