jQuery.noConflict()(function($){
    
	/*
	 * a.externalは別ウィンドウ
	 */
	$('a.external').attr("target","_blank");
    
    /* 
     * 画像マウスオーバ
     * imgにclass="now"がついていればデフォルトでover画像
     */
    $('a img').hover(function(){
        $(this).attr('src', $(this).attr('src').replace('_off', '_ov'));
          }, function(){
            if( !$(this).hasClass("now") ){
             $(this).attr('src', $(this).attr('src').replace('_ov', '_off'));
        }
    });
    
    /*
     * TOPページ画像クロスフェード
     * 押下してないときは一定時間でフェード切り替え
     */
    $('#mainIco a img').click(function(){
        clearInterval(mainfade);
        var index = $('#mainIco a img').index(this);
        if( index==2 ) {
            var nextIndex = 0;
        }else{ 
            var nextIndex = index+1;
        }
        
        $('#slideImage a').removeClass('active last-active');
        $('#mainIco a img').removeClass('now');
        $('#mainIco a img').each(function(){
            $(this).attr('src', $(this).attr('src').replace('_ov', '_off'));
        });
        $('#slideImage a').css({opacity: 0.0});

        $(this).addClass('now');
        $(this).attr('src', $(this).attr('src').replace('_off', '_ov'));
        $('#slideImage a:eq('+index+')').css({opacity: 1.0}).addClass('active last-active');

        var $next =  $('#slideImage a:eq('+nextIndex+')');
        var nextCh = $('#mainIco li a img').eq(nextIndex);
        var $activeCh = $(this);
        mainfade = setInterval( "slideSwitch()", 7000 );
        return false;
    });
    
    /*
     * タブメニュー
     */
     $('#glNavi').each(function() {
        var mstr = "/category/.*recipe.*";
        var regptr = new RegExp(mstr);
        var gPath = $.url().attr('path');
        if(gPath.match(regptr) != null){
                gPath = "/front/category/recipe/";
        }
        else {
                mstr = "/category/.+";
                regptr = new RegExp(mstr);
                if(gPath.match(regptr) != null){
                        gPath = "/front/category/item/";
                }
                else{
                        mstr = "/commodity/00000000/.+";
                        regptr = new RegExp(mstr);
                        if(gPath.match(regptr) != null){
                                gPath = "/front/category/item/";
                        }
                }
                mstr = "/campaign/.+";
                regptr = new RegExp(mstr);
                if(gPath.match(regptr) != null){
			if(gPath != "/front/contents/shop/00000000/campaign/rakuraku/") {
	                        gPath = "/front/contents/shop/00000000/campaign/renewal/";
			}
                }
        }
        $('li a', this).each(function(index){
                if($(this).attr('href') == gPath){
                        $(this).addClass('now');
                        $(this).find('img').addClass('now');
                        $(this).find('img').attr('src', $(this).find('img').attr('src').replace('_off', '_ov'));
                } else {
                        $(this).removeClass('now');
                        $(this).find('img').removeClass('now');
                        $(this).find('img').attr('src', $(this).find('img').attr('src').replace('_ov', '_off'));
                }
        });
        return false;
    });

    $('.tubHead li').click(function() {
        var select = $(this).find('a').attr('href');
        if(select.match(/^(#ch)/g)){
	        $('.tubHead li').removeClass('now');
	        $(this).addClass('now');
	        $('.tubBox').hide();
	        $(select).show();
	        return false;
	    }else{
	        return true;
	    }
        return false;
    });
	
    /*
     * FAQ用アコーディオン
     */
	$('.faq dl dt').click(function(){
		$(this).next().slideToggle('fast');
	}).next().hide();

    /*
     * サイドメニュー用アコーディオン
	 * URL判別にjQuery-URL-Parser利用
     */
    $('#menu .product').each(function(){
        var find_stat = 0;
        $('li a', this).each(function(index){
                        if(find_stat == 1) return false;
		        var nowPath = $.url().attr('path');
			var pthis = $(this).parent('li');
                        var $this = $(this);
			$this.next().hide();
			$('.childMenu li a', pthis).each(function(){
				if($(this).attr('href')==nowPath){
					$(pthis).find('.childMenu').show();
					$(this).addClass('now');
                                        find_stat = 1;
					
					/* カテゴリ表示時の画像反転が必要な場合 */
					var ptimg = $(pthis).find('img');
					$(ptimg).addClass('now');
					$(ptimg).attr('src', $(ptimg).attr('src').replace('_off', '_ov'));

                                        return false;
				}
			});
            /*
            $this.click(function(){
                $(this).next().slideToggle('fast');
                if($this.attr('href')=='#') return false;
            });
            */
        });
    });

    $('#menu .section ul li.parent a').each(function(index){
		        var nowPath = $.url().attr('path');
			var pthis = $(this).parent('li');
                        var $this = $(this);
			$this.next().hide();
			$('.childMenu li a', pthis).each(function(){


                        mstr = "/category/recipe.+";
                        regptr = new RegExp(mstr);
                        if(nowPath.match(regptr) != null){
				mstr = "/category/recipe_C.+";
                        	regptr = new RegExp(mstr);
                        	if(nowPath.match(regptr) != null){
					nowPath = "/front/category/caspi_recipe/";
				}
                                mstr = "/category/recipe_K.+";
                                regptr = new RegExp(mstr);
                                if(nowPath.match(regptr) != null){
                                        nowPath = "/front/category/kuro_recipe/";
                                }
                                mstr = "/category/recipe_M.+";
                                regptr = new RegExp(mstr);
                                if(nowPath.match(regptr) != null){
                                        nowPath = "/front/category/mochi_recipe/";
                                }

                         }

				if($(this).attr('href')==nowPath){
					$(pthis).find('.childMenu').show();
					$(this).addClass('now');
				}
			});
            /*
            $this.click(function(){
                $(this).next().slideToggle('fast');
                if($this.attr('href')=='#') return false;
            });
            */
    });

    /*
     * スムーススクロール
     */
    $("a[href*=#]").click(function(){
        var $target=$(this.hash);
        if($target.offset()!=null){
            var targetY=$target.offset().top;
            $((navigator.userAgent.indexOf("Opera") != -1) ? document.compatMode == 'BackCompat' ? 'body' : 'html' :'html,body').animate({scrollTop:targetY}, 'slow');
        }else{
            return true;
        }
    })

	/*
	 * ブロックリンク
	 */
	$(".blockLink").mouseover(function(){
		$(this).css('cursor','pointer');
	});
	$(".blockLink").mouseout(function(){
		$(this).css('cursor','auto');
	});
	$(".blockLink").click(function(){
	   window.open($(this).find("a").attr("href"),'_self');
	   return false;
	});

    /*
     * 高さ揃え
     */
    $('.voice dl').flatHeights();
    $('.moreTaste ul li p').flatHeights();
    $('.point.column3.stuff ul li .comment').flatHeights();
    $('.product .point .imgBoxLeft, .product .point .imgBoxRight').flatHeights();

    /*
     * 高さ揃え
     */
    $('.tile').tile(2);
});

/* TOP用クロスフェード
 * function slideSwitch
*/
function slideSwitch() {
    var $active = jQuery('#slideImage a.active');
    if ( $active.length == 0 ) $active = jQuery('#slideImage a:last');
    var activeIndex = jQuery('#slideImage a').index($active);
    if( activeIndex==2 ) {
        var nextIndex = 0;
    }else{ 
        var nextIndex = activeIndex+1;
    }
    var $next =  $active.next().length ? $active.next() : jQuery('#slideImage a:first');
    $active.addClass('last-active');
    var $activeCh = jQuery('#mainIco li a img.now');
    var nextCh = jQuery('#mainIco li a img').eq(nextIndex);
    
    jQuery(nextCh).addClass('now');
    jQuery(nextCh).attr('src', jQuery(nextCh).attr('src').replace('_off', '_ov'));
    $activeCh.removeClass('now');
    $activeCh.attr('src', $activeCh.attr('src').replace('_ov', '_off'));
    
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 2000, function() {
          $active.removeClass('active last-active');
        });
}

/*
	jquery.flatheights.js
	Version: 2010-09-15
*/
/*
======================================================================
	$.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;
	};

	/* 高さ揃えを再実行する処理 */
	var reflatting = function() {
		$.each(sets, function() {
			this.height('auto');
			flatHeights(this);
		});
	};

	/* 文字の大きさが変わった時に高さ揃えを再実行 */
	$.changeLetterSize.addHandler(reflatting);

	/* ウィンドウの大きさが変わった時に高さ揃えを再実行 */
	$(window).resize(reflatting);

})(jQuery);


/*
Copyright (c) 2007, KITAMURA Akatsuki

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/


/**
 * Flatten height same as the highest element for each row.
 *
 * Copyright (c) 2011 Hayato Takenaka
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 * @author: Hayato Takenaka (http://urin.take-uma.net)
 * @version: 0.0.2
**/
;(function($) {
	$.fn.tile = function(columns) {
		var tiles, max, c, h, last = this.length - 1, s;
		if(!columns) columns = this.length;
		this.each(function() {
			s = this.style;
			if(s.removeProperty) s.removeProperty("height");
			if(s.removeAttribute) s.removeAttribute("height");
		});
		return this.each(function(i) {
			c = i % columns;
			if(c == 0) tiles = [];
			tiles[c] = $(this);
			h = tiles[c].height();
			if(c == 0 || h > max) max = h;
			if(i == last || c == columns - 1)
				$.each(tiles, function() { this.height(max); });
		});
	};
})(jQuery);

/*
 * プルダウンの変更を行う
 */
jQuery.fn.pulldownChange = function(targetid, changeid, changeItemArray){
    jQuery("#" + targetid).change(function(){
		value = jQuery(this).val();
		jQuery("#" + changeid).children().remove();
		changePulldown = changeItemArray[value];
		changeSellectNode = window.document.getElementById(changeid);
		for (var i = 0; i < changePulldown.length; i++ ) {
			//jQuery("#" + changeid).append("<option value=\"" + changePulldown[i][0] + "\">" + changePulldown[i][1] + "</option>");
			changeSellectNode.options[i] = new Option(changePulldown[i][1], changePulldown[i][0]);
		}
		changeSellectNode.selectedIndex = 0;
	});
}

