/** 1.3.2,1.3.2min
 * jQuery.画像のロールオーバー
 *
 * @version  1.0.2
 * @author   rew <rewish.org@gmail.com>
 * @link     http://rewish.org/javascript/jquery_rollover_plugin
 * @license  http://rewish.org/license/mit The MIT License
 * Inspired by:
 * Telepath Labs (http://dev.telepath.co.jp/labs/article.php?id=15)
 * Usage:
 * jQuery(document).ready(function($) {
 *   // <img>
 *   $('#nav a img').rollover();
 *
 *   // <input type="image">
 *   $('form input:image').rollover();
 *
 *   // set suffix
 *   $('#nav a img').rollover('_over');
 * });
 */

jQuery.fn.rollover = function(suffix) {
	suffix = suffix || '_on';
	return this.not('[src*="'+ suffix +'."]').each(function() {
		var img = jQuery(this);
		var src = img.attr('src');
		var _on = [
			src.substr(0, src.lastIndexOf('.')),
			src.substring(src.lastIndexOf('.'))
		].join(suffix);
		jQuery('<img>').attr('src', _on);
		img.hover(
			function() { img.attr('src', _on); },
			function() { img.attr('src', src); }
		);
	});
};

//config
jQuery(document).ready(function($) {
   // input type="image"
    $('form input:image').rollover('');
   // set suffix
    $('.rollover a img').rollover('');
 });
//config-end


/**
 * 開閉
 * opening
 * ("slow") ("normal") ("fast") (1500)
 */
jQuery(document).ready(function() {
  jQuery(".opening").hover(function(){
        jQuery(this).css("cursor","pointer");
  });
  jQuery(".opening").click(function(){
    jQuery(this).next().slideToggle("fast");
  });
});


/** 1.3.2,1.3.2min
 * 検索窓
 * 非フォーカス時にヒントの表示されるテキストボックス
 */
jQuery(document).ready(function(){
    jQuery('#s')
        .blur(function(){
          var $$=jQuery(this);
          if($$.val()=='' || $$.val()==$$.attr('title')){
            $$.css('color', '#999')
              .val($$.attr('title'));
          }
        })
        .focus(function(){
          var $$=jQuery(this);
          if($$.val()==$$.attr('title')){
              jQuery(this).css('color', '#000')
                   .val('');
          }
        })
        .parents('form:first').submit(function(){
          var $$=jQuery('#s');
          if($$.val()==$$.attr('title')){
            $$.triggerHandler('focus');
          }
        }).end()
        .blur();
      });




/**
 * jquery.dropdown.js
 * ul li をホバーで開く　IE用
 **/
jQuery(document).ready(function(){

	jQuery("ul.dropdown li").dropdown();

});

jQuery.fn.dropdown = function() {

	jQuery(this).hover(function(){
		jQuery(this).addClass("hover");
		jQuery('> .dir',this).addClass("open");
		jQuery('ul:first',this).css('visibility', 'visible');
	},function(){
		jQuery(this).removeClass("hover");
		jQuery('.open',this).removeClass("open");
		jQuery('ul:first',this).css('visibility', 'hidden');
	});

}


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

jQuery.slideScroll.js

jQuery required (tested on version 1.2.6)
encoding UTF-8

Copyright (c) 2008 nori (norimania@gmail.com)
http://moto-mono.net
Licensed under the MIT

$Update: 2008-12-24 20:00
$Date: 2008-12-22 23:30

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

jQuery.fn.slideScroll = function(options){

	var c = jQuery.extend({
		interval: 20, // 変化はあんまりないかも
		easing: 0.6, // 0.4 ~ 2.0 くらいまで
		comeLink: false
	},options);
	var d = document;

	// timerとposのscopeをjQuery.fn.slideScroll内に限定する
	var timer;
	var pos;

	// スクロール開始時の始点を得る
	function currentPoint(){
		var current = {
			x: d.body.scrollLeft || d.documentElement.scrollLeft,
			y: d.body.scrollTop || d.documentElement.scrollTop
		}
		return current;
	}

	// 現在のウィンドウサイズとターゲット位置から最終到達地点を決める
	function setPoint(){

		// 表示部分の高さと幅を得る
		var h = d.documentElement.clientHeight;
		var w = d.documentElement.clientWidth;

		// ドキュメントの最大の高さと幅を得る
		var maxH = d.documentElement.scrollHeight;
		var maxW = d.documentElement.scrollWidth;

		// ターゲットの位置が maxH(W)-h(w) < target < maxH(W) なら スクロール先をmaxH(W)-h(w)にする
		pos.top = ((maxH-h)<pos.top && pos.top<maxH) ? maxH-h : pos.top;
		pos.left = ((maxW-w)<pos.left && pos.left<maxW) ? maxW-w : pos.left;
	}

	// 次のスクロール地点を決める
	function nextPoint(){
		var x = currentPoint().x;
		var y = currentPoint().y;
		var sx = Math.ceil((x - pos.left)/(5*c.easing));
		var sy = Math.ceil((y - pos.top)/(5*c.easing));
		var next = {
			x: x - sx,
			y: y - sy,
			ax: sx,
			ay: sy
		}
		return next;
	}

	// 到達地点に近づくまでスクロールを繰り返す
	function scroll(href){
		var movedHash = href;
		timer = setInterval(function(){
			nextPoint();

			// 到達地点に近づいていたらスクロールをやめる
			if(Math.abs(nextPoint().ax)<1 && Math.abs(nextPoint().ay)<1){
				clearInterval(timer);
				window.scroll(pos.left,pos.top);
				location.href = movedHash;
			}
			window.scroll(nextPoint().x,nextPoint().y);
		},c.interval);
	}

	// URIにhashがある場合はスクロールする
	function comeLink(){
		if(location.hash){
			if(jQuery(location.hash) && jQuery(location.hash).length>0){
				pos = jQuery(location.hash).offset();
				setPoint();
				window.scroll(0,0);
				if(jQuery.browser.msie){
					setTimeout(function(){
						scroll(location.hash);
					},50);
				}else{
					scroll(location.hash);
				}
			}
		}
	}
	if(c.comeLink) comeLink();

	// アンカーにclickイベントを定義する
	jQuery(this).each(function(){
		if(this.hash && jQuery(this.hash).length>0
			&& this.href.match(new RegExp(location.href.split("#")[0]))){
			var hash = this.hash;
			jQuery(this).click(function(){

				// ターゲットのoffsetを得る
				pos = jQuery(hash).offset();

				// スクロール中ならスクロールをやめる
				clearInterval(timer);

				// 到達地点を決めてスクロールを開始する
				setPoint();
				scroll(this.href);
				return false;
			});
		}
	});
}

//config
jQuery(function(){
	jQuery("a[href*='#']").slideScroll();
	});



//ある要素の子のdiv要素を○個ずつ高さを揃える
/*
jquery.flatheights.js
Version: 2007-08-01
*/

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

//jQuery.changeLetterSize = {
//handlers : [],
//interval : 1000,
//currentSize: 0
//};
//
//(function(jQuery) {
//
//var self = jQuery.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;
//	jQuery.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(jQuery) {

/* 対象となる要素群の集合 */
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に含まれる各要素群に対して高さ揃えを実行 */
//jQuery.changeLetterSize.addHandler(function() {
//	jQuery.each(sets, function() {
//		this.height('auto');
//		flatHeights(this);
//	});
//});

})(jQuery);

//config
jQuery(function(){
    /* div要素を3つずつの組に分ける */
    var sets = [], temp = [];
    jQuery('.recomendblock > div').each(function(i) {
        temp.push(this);
        if (i % 4 == 3) {
            sets.push(temp);
            temp = [];
        }
    });
    if (temp.length) sets.push(temp);

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

//config
jQuery(function(){
    /* div要素を3つずつの組に分ける */
    var sets = [], temp = [];
    jQuery('.whoboughtblock > div').each(function(i) {
        temp.push(this);
        if (i % 4 == 3) {
            sets.push(temp);
            temp = [];
        }
    });
    if (temp.length) sets.push(temp);

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

