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

	CSS

 -----------------------------------------
	INDEX
 -----------------------------------------
	

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

/* IE6で砂時計回避
========================================== */
try {
	document.execCommand('BackgroundImageCache', false, true);
}catch(e){}


/* Mouse Over
========================================== */
$(function() {
  var image_cache = new Object();
  $(".swap").each(function(i) {
    var imgsrc = this.src;
    var dot = this.src.lastIndexOf('.');
    var imgsrc_on = this.src.substr(0, dot) + '_o' + 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; });
  });
});


/* Cookie Script
========================================== */
function createCookie(name,value,days){
   if (days){
   var date = new Date();
   date.setTime(date.getTime()+(days*24*60*60*1000));
   var expires = "; expires="+date.toGMTString();
   }
   else var expires = "";
   document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name){
   var nameEQ = name + "=";
   var ca = document.cookie.split(';');
   for(var i=0;i < ca.length;i++)
   {
   var c = ca[i];
   while (c.charAt(0)==' ') c = c.substring(1,c.length);
   if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
   }
   return null;
}


/* Chenge Font Size
========================================== */
$(function(){
	var currentstyle = readCookie('little_mermaidFontStyle');
	if (currentstyle){
		switchFont(currentstyle);
	}else{
		switchFont("fontMedium");
	};
		
	$("dl#changeFontsize dd.small a").click(function(){
		switchFont("fontSmall");
		return false;
	});
		
	$("dl#changeFontsize dd.medium a").click(function(){
		switchFont("fontMedium");
		return false;
	});
	
	$("dl#changeFontsize dd.large a").click(function(){
		switchFont("fontLarge");
		return false;
	});
});

function switchFont(className){
   $('#main').removeAttr('class').addClass(className);
   $('dl#changeFontsize').removeAttr('class').addClass(className);
   createCookie('little_mermaidFontStyle', className, 365);
};


/* Smooth Scroll
========================================== */
$(function(){ 
	$('a[href^=#]:not(a[href$=#])').not('#contents .categoryNavi li a, .recommendRecipeNavi ul li a').click(function(){
		var href= this.hash;
		var $target = $(href == '#_top' ? 'body' : href);

		// アンカーリンクがあるページでだけ以下を実行
		if($target.size()){
			var top = $target.offset().top;
			$($.browser.safari ? 'body' : 'html').animate({scrollTop:top}, 500, 'swing');
		}
		return false;
	});
});


/* Lightbox
========================================== */
$(function() {
		$('#contents .pointBox .image a').lightBox();
		$('#contents .introductionUnit .mainUnit .introUnit .contents .image a').lightBox();
		$('#contents .introductionUnit .mainUnit .introUnit .contents .photoList ul li a').lightBox();
		$('body.news.details #contents .detailUnit .newsContents .section .imageUnit p.image a').lightBox();
});


/* Print
========================================== */
$(function(){
	$('.printBtn img').click(function(){
		print();
	}).css('cursor','pointer');
});


/* input内のテキスト選択
========================================== */
$(function() {
	$('body.shopsearch #contents .detailUnit .detailContents .otherInfo .pcInfo input.textbox,#contents .detailUnit .recipeInfo .otherUnit p.inputArea input').click(function(){
		$(this).select();
	});
});


/* サムネイル画像　切り替え
========================================== */
$(function(){
	var mainImage = $('#contents .detailUnit .detailContents .imageUnit .imageMain img').attr('src'); // src属性の初期値
	$('ul.imageList li a').mouseover(function(){
		var thumbnailImage = $(this).attr('href');
		$('#contents .detailUnit .detailContents .imageUnit .imageMain img').attr('src', thumbnailImage);
	});
	
	$(this).mouseout(function(){
		$('#contents .detailUnit .detailContents .imageUnit .imageMain img').attr('src', mainImage);
	});
	
	$('ul.imageList li a').click(function(){
		return false;
	});
});


/* 枠のオーバー
========================================== */
/* Item List 01
---------------------------------------- */
$(function(){
	$('#contents .itemList01 ul li').not('#contents .itemList01 ul li.emptyBox').mouseover(function(){
		$(this).addClass('over');
		$(this).css('cursor','pointer');
	});
	
	$('#contents .itemList01 ul li').not('#contents .itemList01 ul li.emptyBox').mouseout(function(){
		$(this).removeClass('over');
	});
	
	$('#contents .itemList01 ul li').not('#contents .itemList01 ul li.emptyBox').click(function(){
		location.href = $(this).find('a').attr('href');
	});
	
	$('#contents .itemList01 ul li').not('#contents .itemList01 ul li.emptyBox').hover(function(){
		$(this).find('p.caption a').css('text-decoration','underline');
	},function(){
		$(this).find('p.caption a').css('text-decoration','none');
	});
});


/* Point Gift Unit
---------------------------------------- */
$(function(){
	$('#contents .pointGiftUnit .eachPointUnit .giftList ul li').not('#contents .pointGiftUnit .eachPointUnit .giftList ul li.emptyBox').mouseover(function(){
		$(this).addClass('over');
		$(this).css('cursor','pointer');
	});
	
	$('#contents .pointGiftUnit .eachPointUnit .giftList ul li').not('#contents .pointGiftUnit .eachPointUnit .giftList ul li.emptyBox').mouseout(function(){
		$(this).removeClass('over');
	});
	
	$('#contents .pointGiftUnit .eachPointUnit .giftList ul li').not('#contents .pointGiftUnit .eachPointUnit .giftList ul li.emptyBox').click(function(){
		location.href = $(this).find('a').attr('href');
	});
});


/*
======================================================================
	$.changeLetterSize.addHandler(func)
	文字の大きさが変化した時に実行する処理を追加
======================================================================
*/

jQuery.changeLetterSize = {
	handlers : [],
	interval : 1000,
	currentSize: 0
};

(function($) {

	var self = $.changeLetterSize;

	/* 文字の大きさを確認するためのins要素 */
	var ins = $('<ins>M</ins>').css({
		display: 'block',
		visibility: 'hidden',
		position: 'absolute',
		padding: '0',
		top: '0'
	});

	/* 文字の大きさが変わったか */
	var isChanged = function() {
		ins.appendTo('body');
		var size = ins[0].offsetHeight;
		ins.remove();
		if (self.currentSize == size) return false;
		self.currentSize = size;
		return true;
	};

	/* 文書を読み込んだ時点で
	   文字の大きさを確認しておく */
	$(isChanged);

	/* 文字の大きさが変わっていたら、
	   handlers中の関数を順に実行 */
	var observer = function() {
		if (!isChanged()) return;
		$.each(self.handlers, function(i, handler) {
			handler();
		});
	};

	/* ハンドラを登録し、
	   最初の登録であれば、定期処理を開始 */
	self.addHandler = function(func) {
		self.handlers.push(func);
		if (self.handlers.length == 1) {
			setInterval(observer, self.interval);
		}
	};

})(jQuery);

/*
======================================================================
	$(expr).flatHeights()
	$(expr)で選択した複数の要素について、それぞれ高さを
	一番高いものに揃える
======================================================================*/

(function($) {

	/* 対象となる要素群の集合 */
	var sets = [];

	/* 高さ揃えの処理本体 */
	var flatHeights = function(set) {
		var maxHeight = 0;
		set.each(function(){
			var height = this.offsetHeight;
			if (height > maxHeight) maxHeight = height;
		});
		set.css('height', maxHeight + 'px');
	};

	/* 要素群の高さを揃え、setsに追加 */
	jQuery.fn.flatHeights = function() {
		if (this.length > 1) {
			flatHeights(this);
			sets.push(this);
		}
		return this;
	};

	/* 文字の大きさが変わった時に、
	   setsに含まれる各要素群に対して高さ揃えを実行 */
	$.changeLetterSize.addHandler(function() {
		$.each(sets, function() {
			this.height('auto');
			flatHeights(this);
		});
	});

})(jQuery);


/* ItemList01
========================================== */
$(function(){
    /* div要素を3つずつの組に分ける */
    var sets = [], temp = [];
    $('#contents .itemList01 ul li p.image, #contents .itemList01 ul li p.caption').each(function(i) {
        temp.push(this);
        if (i % 4 == 3) {
            sets.push(temp);
            temp = [];
        }
    });
    if (temp.length) sets.push(temp);

    /* 各組ごとに高さ揃え */
    $.each(sets, function() {
        $(this).flatHeights();
    });
});

$(function(){
    /* div要素を3つずつの組に分ける */
    var sets = [], temp = [];
    $('#contents .itemList01 ul li .wrap').each(function(i) {
        temp.push(this);
        if (i % 4 == 3) {
            sets.push(temp);
            temp = [];
        }
    });
    if (temp.length) sets.push(temp);

    /* 各組ごとに高さ揃え */
    $.each(sets, function() {
        $(this).flatHeights();
    });
});

/* Recipe Details
========================================== */
$(function(){
    /* div要素を3つずつの組に分ける */
    var sets = [], temp = [];
    $('#contents .detailUnit .processUnit ul li p.text').each(function(i) {
        temp.push(this);
        if (i % 4 == 3) {
            sets.push(temp);
            temp = [];
        }
    });
    if (temp.length) sets.push(temp);

    /* 各組ごとに高さ揃え */
    $.each(sets, function() {
        $(this).flatHeights();
    });
});

$(function(){
    /* div要素を3つずつの組に分ける */
    var sets = [], temp = [];
    $('#contents .detailUnit .processUnit ul li p.image').each(function(i) {
        temp.push(this);
        if (i % 4 == 3) {
            sets.push(temp);
            temp = [];
        }
    });
    if (temp.length) sets.push(temp);

    /* 各組ごとに高さ揃え */
    $.each(sets, function() {
        $(this).flatHeights();
    });
});

/* Margueriteclub Giftlist Details
========================================== */
$(function(){
    /* div要素を2つずつの組に分ける */
    var sets = [], temp = [];
    $('body.enjoy.margueriteclub.giftlist.details #contents .frameBox03 .giftDetailList ul li .itemContents').each(function(i) {
        temp.push(this);
        if (i % 2 == 1) {
            sets.push(temp);
            temp = [];
        }
    });
    if (temp.length) sets.push(temp);

    /* 各組ごとに高さ揃え */
    $.each(sets, function() {
        $(this).flatHeights();
    });
});

/* Margueriteclub Giftlist
========================================== */
$(function(){
    /* div要素を5つずつの組に分ける */
    var sets = [], temp = [];
    $('body#giftlistIndex #contents .frameBox03 .pointGiftUnit .eachPointUnit .giftList ul li .image').each(function(i) {
        temp.push(this);
        if (i % 5 == 4) {
            sets.push(temp);
            temp = [];
        }
    });
    if (temp.length) sets.push(temp);

    /* 各組ごとに高さ揃え */
    $.each(sets, function() {
        $(this).flatHeights();
    });
});

$(function(){
    /* div要素を5つずつの組に分ける */
    var sets = [], temp = [];
    $('body#giftlistIndex #contents .frameBox03 .pointGiftUnit .eachPointUnit .giftList ul li .content').each(function(i) {
        temp.push(this);
        if (i % 5 == 4) {
            sets.push(temp);
            temp = [];
        }
    });
    if (temp.length) sets.push(temp);

    /* 各組ごとに高さ揃え */
    $.each(sets, function() {
        $(this).flatHeights();
    });
});

/* Tab
========================================== */
/* Recipe Index
---------------------------------------- */
$(function(){
	$('body.recipe#recipeIndex #contents .categoryUnit').hide();
	
	var currentstyle1 = readCookie('little_mermaid'+$('body').attr('class')+$('body').attr('id')+'showTab');
	var currentstyle2 = readCookie('little_mermaid'+$('body').attr('class')+$('body').attr('id')+'showList');
	
	if (currentstyle1){
		$(currentstyle1).fadeIn(400);//選択されたタブの対象コンテンツ参照、設定
		$('body.recipe#recipeIndex #contents .categoryNavi li a:eq('+currentstyle2+')').addClass('active');//active設定割り当て
	}else{
		//最初にアクティブ状態になる要素の設定
		$('body.recipe#recipeIndex #contents #categoryUnit01').show();
		$('body.recipe#recipeIndex #contents .categoryNavi li.item01 a').addClass('active');
	};
	
	$('body.recipe#recipeIndex #contents .categoryNavi li a').click(function() {
		var showTab = $(this).attr('href'); // 呼び出し元a要素のherf属性取得
		var showList = $('body.recipe#recipeIndex #contents .categoryNavi li a').index(this);
		
		$('body.recipe#recipeIndex #contents .categoryUnit').hide();//コンテンツ部分を一括非表示
		$(showTab).fadeIn(400);//選択されたタブの対象コンテンツ参照、設定
		$('body.recipe#recipeIndex #contents .categoryNavi li a').removeClass('active');//active設定削除
		$(this).addClass('active');//active設定割り当て
		
	  createCookie('little_mermaid'+$('body').attr('class')+$('body').attr('id')+'showTab', showTab, 365);
	  createCookie('little_mermaid'+$('body').attr('class')+$('body').attr('id')+'showList', showList, 365);
		
		return false;
	});
});


/* Ingredients Index
---------------------------------------- */
$(function(){
	$('body.products.ingredients#ingredientsIndex #contents .ingredientsLabelUnit').hide();
	
	var currentstyle1 = readCookie('little_mermaid'+$('body').attr('class')+$('body').attr('id')+'showTab2');
	var currentstyle2 = readCookie('little_mermaid'+$('body').attr('class')+$('body').attr('id')+'showList2');
	
	if (currentstyle1){
		$(currentstyle1).fadeIn(400);//選択されたタブの対象コンテンツ参照、設定
		$('body.products.ingredients#ingredientsIndex #contents .categoryNavi li a:eq('+currentstyle2+')').addClass('active');//active設定割り当て
	}else{
		//最初にアクティブ状態になる要素の設定
		$('body.products.ingredients#ingredientsIndex #contents #ingredientsLabelUnit01').show();
		$('body.products.ingredients#ingredientsIndex #contents .categoryNavi li.item01 a').addClass('active');
	};
	
	$('body.products.ingredients#ingredientsIndex #contents .categoryNavi li a').click(function() {
		var showTab = $(this).attr('href');//呼び出し元a要素のherf属性取得
		var showList = $('body.products.ingredients#ingredientsIndex #contents .categoryNavi li a').index(this);
		
		$('body.products.ingredients#ingredientsIndex #contents .ingredientsLabelUnit').hide();//コンテンツ部分を一括非表示
		$(showTab).fadeIn(400);//選択されたタブの対象コンテンツ参照、設定
		$('body.products.ingredients#ingredientsIndex #contents .categoryNavi li a').removeClass('active');//active設定削除
		$(this).addClass('active');//active設定割り当て
		
		
		createCookie('little_mermaid'+$('body').attr('class')+$('body').attr('id')+'showTab2',showTab, 365);
		createCookie('little_mermaid'+$('body').attr('class')+$('body').attr('id')+'showList2',showList, 365);
		return false;
	});
});


/* Recommend Recipe
---------------------------------------- */
$(function(){
	$('body.recipe.recommend#recommendIndex #contents .frameBox03 .recommendRecipe').hide();
	
	var currentstyle1 = readCookie('little_mermaid'+$('body').attr('class')+$('body').attr('id')+'showTab3');
	var currentstyle2 = readCookie('little_mermaid'+$('body').attr('class')+$('body').attr('id')+'showList3');
	
	if (currentstyle1){
		$(currentstyle1).fadeIn(400);//選択されたタブの対象コンテンツ参照、設定
		$('body.recipe.recommend#recommendIndex #contents .frameBox03 .recommendRecipeNavi ul li a:eq('+currentstyle2+')').addClass('active');//active設定割り当て
	}else{
		//最初にアクティブ状態になる要素の設定
		$('body.recipe.recommend#recommendIndex #contents .frameBox03 .recommendRecipe#recommendRecipeUnit02').show();
		$('body.recipe.recommend#recommendIndex #contents .frameBox03 .recommendRecipeNavi ul li.item02 a').addClass('active');
	};
	
	$('body.recipe.recommend#recommendIndex #contents .frameBox03 .recommendRecipeNavi ul li a').click(function() {
		var showTab = $(this).attr('href');//呼び出し元a要素のherf属性取得
		var showList = $('body.recipe.recommend#recommendIndex #contents .frameBox03 .recommendRecipeNavi ul li a').index(this);
		
		$('body.recipe.recommend#recommendIndex #contents .frameBox03 .recommendRecipe').hide();//コンテンツ部分を一括非表示
		$(showTab).fadeIn(400);//選択されたタブの対象コンテンツ参照、設定
		$('body.recipe.recommend#recommendIndex #contents .frameBox03 .recommendRecipeNavi ul li a').removeClass('active');//active設定削除
		$(this).addClass('active');//active設定割り当て
		
		
		createCookie('little_mermaid'+$('body').attr('class')+$('body').attr('id')+'showTab3',showTab, 365);
		createCookie('little_mermaid'+$('body').attr('class')+$('body').attr('id')+'showList3',showList, 365);
		return false;
	});
});