

/*	=========================================================================================

						雪印メグミルクサイト共通処理

	 ……………………………………………………………………………………………………………………
		※検証コード用コメント：[10120401]0000-0001 for debug


	=========================================================================================		*/


/*	------------------------------------------------------------------

					初期値

	------------------------------------------------------------------		*/
var lay02 = '';		//	第二階層カテゴリー：	値は、各ページにて設定。
var lay03 = '';		//	第三階層カテゴリー：	値は、各ページにて設定。
var lay04 = '';		//	第四階層カテゴリー：	値は、各ページにて設定。
var lay05 = '';		//	第五階層カテゴリー：	値は、各ページにて設定。












/*	------------------------------------------------------------------

			ポップアップ展開処理

	------------------------------------------------------------------		*/
function setPopupBtn()	{

	$("a.ppw01").click(function(){
		// サイズ：600px × 620px
		var tgturl = $(this).attr('href');
		var wname = 'mspop01';
		var w = 600;
		var h = 620;
		var scr = 'yes';
		wo=window.open(tgturl,wname,"width="+w+",height="+h+",left=0,top=0,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars="+scr+",favorites=no,resizable=yes");
		wo.focus();
		return false;
	});

	$("a.ppw02").click(function(){
		// サイズ：755px × 490px
		var tgturl = $(this).attr('href');
		var wname = 'mspop02';
		var w = 755;
		var h = 490;
		var scr = 'yes';
		wo=window.open(tgturl,wname,"width="+w+",height="+h+",left=0,top=0,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars="+scr+",favorites=no,resizable=yes");
		wo.focus();
		return false;
	});

	$("a.ppw03").click(function(){
		// サイズ：750px × 580px
		var tgturl = $(this).attr('href');
		var wname = 'mspop03';
		var w = 750;
		var h = 580;
		var scr = 'yes';
		wo=window.open(tgturl,wname,"width="+w+",height="+h+",left=0,top=0,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars="+scr+",favorites=no,resizable=yes");
		wo.focus();
		return false;
	});

	$(".b-close a").click(function(){
		window.close();
		return false;
	});
}


/*	------------------------------------------------------------------

			ポップアップ展開処理(引数対応)

	------------------------------------------------------------------		*/
function openPPW(tgturl,n,w,h)	{

	var scr = 'yes';
	wo=window.open(tgturl,n,"width="+w+",height="+h+",left=0,top=0,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars="+scr+",favorites=no,resizable=yes");
	wo.focus();
	return false;

}


/*	------------------------------------------------------------------

			旧サイト ポップアップ展開処理(引数対応)
			使用ページ：ミルクデザートレシピ

	------------------------------------------------------------------		*/
function subWin(url,wname){
	wo=window.open(url,wname,"width=670,height=560,left=0,top=0,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,favorites=no,resizable=yes");
	wo.focus();
	return false;
}

/*	------------------------------------------------------------------

					ブランクページリンク設定処理

	------------------------------------------------------------------		*/
function initBlankLink() {
	//http:// , https://  _blank add
	//pdf,excel,word _blank add

	$('a').click(function(){
		var href0 = $(this).attr('href');
		if( (href0.indexOf('://') != -1)
		||	(href0.indexOf('.pdf') != -1)
		||	(href0.indexOf('.doc') != -1)
		||	(href0.indexOf('.xls') != -1)	) {
			window.open(href0, '_blank');
			return false;
		}
	});

}




/*	------------------------------------------------------------------

					ブロックリンク設定処理

	------------------------------------------------------------------		*/
function setBlockLink() {

	var href0,idx,cls0,w_cm;
	var wname,w,h;

	$('.lnkblk').hover(function(){
		$(this).css('cursor','pointer');
		$(this).addClass('hovr');
	},
	function(){
		$(this).css('cursor','default');
		$(this).removeClass('hovr');
	});

	$('.lnkblk').click(function(){
		idx = $('.lnkblk').index(this);
		href0 = $('a.lnkblklnk:eq(' + idx +')').attr('href');
		cls0 = $('a.lnkblklnk:eq(' + idx +')').attr('class');
		if(cls0.indexOf('cmppw') != -1) {
			wname = 'cm';
			w = 560;
			h = 520;
			w_cm = window.open(href0,wname,"width="+w+",height="+h+",left=0,top=0,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,favorites=no,resizable=yes");
			w_cm.focus();
			return false;
		}else {
			location.href = href0;
		}
	});

}




/*	------------------------------------------------------------------

					画像ロールオーバ処理

	------------------------------------------------------------------		*/
var lgth_unit0 = 4;		//	the length of '.gif' or '.jpg'
var lavel_on0 = '_1';
var lavel_off0 = '_2';

$(function(){ 

	$('img.rovr').live('mouseover',function()	{		//	onmouseover event
			var this_img0 = $(this).attr('src');
			var dat0 = this_img0.split('/');
			var img_name0 = dat0[dat0.length-1];
			var start0 = this_img0.length - lgth_unit0;
			var end0 = this_img0.length;
			var unit0 = this_img0.slice(start0,end0);			//	'.gif' or '.jpg'
			var name_nml0 = img_name0.split(unit0);
			var name_tgl0 = img_name0.replace(lavel_on0,lavel_off0);
			var img_tgl0 = this_img0.replace(img_name0,name_tgl0);
			$(this).attr('src',img_tgl0);
		});

	$('img.rovr').live('mouseout',function()	{		//	onmouseout event
			var this_img0 = $(this).attr('src');
			var dat0 = this_img0.split('/');
			var img_name0 = dat0[dat0.length-1];
			var start0 = this_img0.length - lgth_unit0;
			var end0 = this_img0.length;
			var unit0 = this_img0.slice(start0,end0);			//	'.gif' or '.jpg'
			var name_tgl0 = img_name0.replace(lavel_off0,lavel_on0);
			var img_tgl0 = this_img0.replace(img_name0,name_tgl0);
			$(this).attr('src',img_tgl0);
		});
	


});


/*	------------------------------------------------------------------

			パンくず関連処理

	------------------------------------------------------------------		*/
function setBreadCrumbs()	{
var arw = '&gt;';

	$('#breadcrumbs li a').each(function () {
		$(this).parent().append(arw);
	});
	
}



/*	------------------------------------------------------------------

			ローカルナビゲーションアクティブ処理

	------------------------------------------------------------------		*/
function actLnav()	{
	var act_i = 0;
	var id0,src0,txt0;
	var $tgt0 = '';

	var act_id_02 = 'l-' + lay02;
	var act_id_03 = 'l-' + lay02 + '-' + lay03;
	var act_id_04 = 'l-' + lay02 + '-' + lay03 + '-' + lay04;


	if(lay02 != 'top') {

		$('#lnav li.lay02').each(function(){
			if(act_id_02 == $(this).attr('id')) {

				$(this).children('ul').css('display','block');

				if(lay03 != 'top') {
					$tgt0 = $('#' + act_id_02 + '>p a');
					img0 = $tgt0.html();
					img0 = img0.replace('_1.','_2.');
					img0 = img0.replace('rovr','bovr');
					$tgt0.html(img0);
				}else {
					$tgt0 = $('#' + act_id_02 + '>p');
					img0 = $tgt0.children('a').html();
					img0 = img0.replace('_1.','_2.');
					img0 = img0.replace('rovr','');
					$tgt0.html('<span class="act">' + img0 + '</span>');
				}
			}
		});

		$('#lnav li.lay03').each(function(){
			if(act_id_03 == $(this).attr('id')) {
	
				if(lay04 != 'top') {
					$('#' + act_id_03 + '>p').addClass('act');
				}else {
					$tgt0 = $('#' + act_id_03 + '>p');
					txt0 = $tgt0.text();
					$tgt0.html('<span class="act">' + txt0 + '</span>');
				}
			}
			
			if($(this).children('p').children('a').length == 0) {
				$(this).children('ul').css('display','block');
			}
		});

	}

}




/*	------------------------------------------------------------------

			旧サイト用 ページ おいしい自信作 レシピ・POPUPスクリプト

	------------------------------------------------------------------		*/

// レシピ 拡大画像表示
function changeRecipe(id,path,num){
	
	document.getElementById("thumblist").style.display = "none";
	document.getElementById("dessert01").style.display = "block";
	
	
	var nextval;
	var backval;
	
	if(id=="a"){
		backlink="&nbsp;";
	}else{
		if(id=="b"){
			backval="a";
		}else if(id=="c"){
			backval="b";
		}else if(id=="d"){
			backval="c";
		}else if(id=="e"){
			backval="d";
		}else if(id=="f"){
			backval="e";
		}
		backlink='<a href="javascript:changeRecipe(\''+backval+'\',\''+path+'\',\''+num+'\');">&lt;&lt;&nbsp;前へ</a>';
	}
	
	if(id=="f"){
		nextlink="&nbsp;";
	}else if(id=="a" && num=="1"){
		nextlink="&nbsp;";
	}else if(id=="b" && num=="2"){
		nextlink="&nbsp;";
	}else if(id=="c" && num=="3"){
		nextlink="&nbsp;";
	}else if(id=="d" && num=="4"){
		nextlink="&nbsp;";
	}else if(id=="e" && num=="5"){
		nextlink="&nbsp;";
	}else{
		if(id=="a"){
			nextval="b";
		}else if(id=="b"){
			nextval="c";
		}else if(id=="c"){
			nextval="d";
		}else if(id=="d"){
			nextval="e";
		}else if(id=="e"){
			nextval="f";
		}
		nextlink='<a href="javascript:changeRecipe(\''+nextval+'\',\''+path+'\',\''+num+'\');">次へ&nbsp;&gt;&gt;</a>';
	}
	
	
	var htmlVal='<div id="zoomwrap">';
	htmlVal += '<div class="txtbox text2 clearfix">';
	htmlVal += '<p class="box-l">'+backlink+'</p>';
	htmlVal += '<p class="box-c"><strong>写真 '+id+'</strong></p>';
	htmlVal += '<p class="box-r">'+nextlink+'</p>';
	htmlVal += '</div>';
	htmlVal += '<p class="image"><img src="img/'+path+'/p_'+id+'2.jpg" width="350" height="310" border="0" alt="" /></p>';
	htmlVal += '<p class="closetxt text2"><a href="javascript:closeRecipe();">×&nbsp;閉じる</a></p>';
	htmlVal += '</div>';
	
	document.getElementById("dessert01").innerHTML = htmlVal;
}

// レシピ 拡大画像を閉じる
function closeRecipe(){
	document.getElementById("dessert01").style.display = "none";
	document.getElementById("thumblist").style.display = "block";
}


//ポップアップウィンドウ（共通）
function opneWinCmn(url,wname,w,h){
	wo=window.open(url,wname,"width="+w+",height="+h+",left=0,top=0,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,favorites=no,resizable=yes");
	wo.focus();
}






/*	------------------------------------------------------------------

					処理実行

	------------------------------------------------------------------		*/

$(function(){

	setPopupBtn();
	initBlankLink();
	setBlockLink();

	setBreadCrumbs();
	actLnav();

});



