//odd even

$(document).ready(function(){
  $(".tabelStyle tr:even").addClass("even");
  $("#recipeRecommend dl:odd").addClass("odd");
  $("#recipeRecommend dl:even").addClass("even");
  $(".newsrelease dl:odd").addClass("odd");
  $(".news #panel dl:odd").addClass("odd");
});

//カテゴリー一覧ボーダーオーバーIEバグ回避

$(document).ready(function(){
	$(".itemlineupBox dt.ib-ph a").mouseover(function(){
		$(this).css("borderColor", "#D8092F");
	});
	$(".itemlineupBox dt.ib-ph a").mouseout(function(){
		$(this).css("borderColor", "#E5E5E5");
	});
	$(".itemlineupBox dt.ib-ph a").click(function(){
		$(this).css("borderColor", "#E5E5E5");
	});
});

/*
 * yuga.js 0.7.1 - 優雅なWeb制作のためのJS
 *　サブメニューカレント表示

*/
(function($) {

	$(function() {
		$.yuga.selflink();
	});

	//---------------------------------------------------------------------

	$.yuga = {
		// URIを解析したオブジェクトを返すfunction
		Uri: function(path){
			var self = this;
			this.originalPath = path;
			//絶対パスを取得
			this.absolutePath = (function(){
				var e = document.createElement('span');
				e.innerHTML = '<a href="' + path + '" />';
				return e.firstChild.href;
			})();
			//絶対パスを分解
			var fields = {'schema' : 2, 'username' : 5, 'password' : 6, 'host' : 7, 'path' : 9, 'query' : 10, 'fragment' : 11};
			var r = /^((\w+):)?(\/\/)?((\w+):?(\w+)?@)?([^\/\?:]+):?(\d+)?(\/?[^\?#]+)?\??([^#]+)?#?(\w*)/.exec(this.absolutePath);
			for (var fields in fields) {
				this[fields] = r[fields[fields]];
			}
			this.querys = {};
			if(this.query){
				$.each(self.query.split('&'), function(){
					var a = this.split('=');
					if (a.length == 2) self.querys[a[0]] = a[1];
				});
			}
		},
		//現在のページと親ディレクトリへのリンク
		selflink: function (options) {
			var c = $.extend({
				selfLinkAreaSelector:'body',
				selfLinkClass:'current',
				parentsLinkClass:'parentsLink',
				//postfix: '_cr',
				changeImgSelf:true,
				changeImgParents:true
			}, options);
			$(c.selfLinkAreaSelector+((c.selfLinkAreaSelector)?' ':'')+'a[href]').each(function(){
				var href = new $.yuga.Uri(this.getAttribute('href'));
				var setImgFlg = false;
				if ((href.absolutePath == location.href) && !href.fragment) {
					//同じ文書にリンク
					$(this).addClass(c.selfLinkClass);
					setImgFlg = c.changeImgSelf;
				} else if (0 <= location.href.search(href.absolutePath)) {
					//親ディレクトリリンク
					$(this).addClass(c.parentsLinkClass);
					setImgFlg = c.changeImgParents;
				}
				//if (setImgFlg){
					//img要素が含まれていたら現在用画像（_cr）に設定
					//$(this).find('img').each(function(){
						//this.originalSrc = $(this).attr('src');
						//this.currentSrc = this.originalSrc.replace(new RegExp('('+c.postfix+')?(\.gif|\.jpg|\.png)$'), c.postfix+"$2");
						//$(this).attr('src',this.currentSrc);
					//});
				//}
			});
		}
	};
})(jQuery);
		

/*

----------------------------------------------------

 * ドロップダウンメニュー
 * Droppy 0.1.2
 * (c) 2008 Jason Frame (jason@onehackoranother.com)
	
----------------------------------------------------
$(function() {
	$('#globalMenu ul').droppy();
});

$.fn.droppy = function(options) {
    
  options = $.extend({speed: 200}, options || {});
  
  this.each(function() {
    
    var root = this, zIndex = 1000;
    
    function getSubnav(ele) {
      if (ele.nodeName.toLowerCase() == 'li') {
        var subnav = $('> ul', ele);
        return subnav.length ? subnav[0] : null;
      } else {
        return ele;
      }
    }
    
    function getActuator(ele) {
      if (ele.nodeName.toLowerCase() == 'ul') {
        return $(ele).parents('li')[0];
      } else {
        return ele;
      }
    }
    
    function hide() {
      var subnav = getSubnav(this);
      if (!subnav) return;
      $.data(subnav, 'cancelHide', false);
      setTimeout(function() {
        if (!$.data(subnav, 'cancelHide')) {
          $(subnav).slideUp(options.speed);
        }
      }, 200);
    }
  
    function show() {
      var subnav = getSubnav(this);
      if (!subnav) return;
      $.data(subnav, 'cancelHide', true);
      $(subnav).css({zIndex: zIndex++}).slideDown(options.speed);
      if (this.nodeName.toLowerCase() == 'ul') {
        var li = getActuator(this);
        $(li).addClass('hover');
        $('> a', li).addClass('hover');
      }
    }
    
    $('ul, li', this).hover(show, hide);
    $('li', this).hover(
      function() { $(this).addClass('hover'); $('> a', this).addClass('hover'); },
      function() { $(this).removeClass('hover'); $('> a', this).removeClass('hover'); }
    );
    
  });
  
};
*/

/*
	jquery.flatheights.js
	Version: 2007-08-01
*/

/*
======================================================================
	イコハイ
======================================================================
*/


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

$(function(){
    $('#resultBox dl').flatHeights();
    $('.teaPointBox dl').flatHeights();
    $('#extraMenu').flatHeights();
    $('.extraMenu').flatHeights();
    $('#factoryList .addimg').flatHeights();
    $('#factoryList .noimg').flatHeights();
    $('.itemlineupBox .ib-name').flatHeights();
		$('.ib-entry').flatHeights();
		$('.itemlineupBox > dl').flatHeights();
		$('.recipe #recipeSearchTable ul').flatHeights();
		$('#recipeRecommend dl').flatHeights();
});

/*
======================================================================
	$(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);

/*v

----------------------------------------------------

 *よくあるご質問　開閉
	
----------------------------------------------------

*/

$(function(){
	$(".faq dd").hide();
	$(".faq dt a").click(function(){
			$(this)
				.parent().parent().find("dd").slideToggle();return false;
		});
});

/*

----------------------------------------------------

 * ロールオーバー
	
----------------------------------------------------

*/


function smartRollover() {
  if(document.getElementsByTagName) {
    var tags = ["img","input"];
    var len = tags.length;
    for( var i=0; i<len; i++ ) {
      var el = document.getElementsByTagName(tags[i]);
      var len2 = el.length;
      for(var j=0; j<len2; j++) {
        var attr = el[j].getAttribute("src");
        if( attr ) {
          if(el[j].getAttribute("src").match(/_off\./))
          {
            el[j].onmouseover = function() {
              this.setAttribute("src", this.getAttribute("src").replace("_off.", "_on."));
            }
            el[j].onmouseout = function() {
              this.setAttribute("src", this.getAttribute("src").replace("_on.", "_off."));
            }
          }
        }
      }
    }
  }
}
if(window.addEventListener) {
  window.addEventListener("load", smartRollover, false);
}
else if(window.attachEvent) {
  window.attachEvent("onload", smartRollover);
}


$(function(){
	$("img.rollover").mouseover(function(){
		$(this).attr("src",$(this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_on$2"))
	}).mouseout(function(){
		$(this).attr("src",$(this).attr("src").replace(/^(.+)_on(\.[a-z]+)$/, "$1$2"));
	}).each(function(){
		$("<img>").attr("src",$(this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_on$2"))
	})
})


/*

----------------------------------------------------

 * スムーズスクロール
 
----------------------------------------------------

*/
$(function(){ 
	$('a[href^=#]:not(a[href$=#]),area[href^=#]:not(area[href$=#])').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}, 600, 'swing');
		}
		return false;
	});
});



//フォントサイズ変更
/*
 * jqswitch.js - jQuery method for style switch
 * Version: 1.0
 * Copyright (c) 2007 A.Kawashima
 * Licensed under the MIT License:
 * http://www.lllcolor.com
 */
$(function(){
   var currentstyle = readCookie('fontStyle');
   if (currentstyle){
   switchFont(currentstyle);
   };
   $(".sizeL").click(function(){
   switchFont("fontL");
   return false;
   });
   $(".sizeM").click(function(){
   switchFont("fontM");
   return false;
   });
   $(".sizeS").click(function(){
   switchFont("fontS");
   return false;
  });
});
function switchFont(className){
   $("body").removeAttr("class").addClass(className);
   createCookie('fontStyle', className, 365);
};
// cookie script http://www.quirksmode.org/js/cookies.html
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;
}




