/**
 * 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)
 */

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

        // Insert By Nagata
        if (src.indexOf("_cr") == -1) {
            jQuery('<img>').attr('src', _on);
        }

        img.hover(
            function() {
                // Insert By Nagata
                if (src.indexOf("_cr") != -1) {
                    return;;
                }
                img.attr('src', _on);
            },

            function() {
                // Insert By Nagata
                if (src.indexOf("_cr") != -1) {
                    return;;
                }
                img.attr('src', src);
            }
        );
    });
};



//config
jQuery(document).ready(function(jQuery) {
   // set suffix
    jQuery('.rollover a img').rollover('');
 });
//config-end

/*****
 * DIVの高さを揃える
 *****/

(function(jQuery){

	jQuery(function(){
		jQuery.sameHeight();
	});
	//高さの違うカラムを同じ高さにする
	jQuery.sameHeight = function(settings){
		var c = jQuery.extend({
			selector: '#wpyst_ranking_line_0 , #wpyst_ranking_line_1 , #wpyst_ranking_line_2 , #wpyst_ranking_line_3 , #wpyst_ranking_line_4 , #wpyst_ranking_line_5 , #wpyst_recommend_line_0 , #wpyst_recommend_line_1 , #wpyst_recommend_line_2 , #wpyst_recommend_line_3 , #wpyst_recommend_line_4 , #wpyst_recommend_line_5' //class='.sameHeight'
		}, settings);

		jQuery(c.selector).each(function(){
			//変数をセット
			var eachHeight = 0;
			var eachPaddingTop = 0;
			var eachPaddingBottom = 0;

			jQuery(this).children().each(function(){

				//高さの値を取得
				var heightValue = jQuery(this).height();

				//IE6用 padding-topとpadding-bottomの値を取得
				var topValue = jQuery(this).css("padding-top");
				var bottomValue = jQuery(this).css("padding-bottom");

				//文字を数値に変換
				topValue = parseFloat(topValue);
				bottomValue = parseFloat(bottomValue);

				//一番大きいheightの値にする
				if (heightValue > eachHeight) { eachHeight = heightValue; };

				//一番大きいpadding-topの値にする
				if (topValue > eachPaddingTop) { eachPaddingTop = topValue; };

				//一番大きいpadding-bottomの値にする
				if (bottomValue > eachPaddingBottom) { eachPaddingBottom = bottomValue; };

			});

			//IE6用 height + paddint-top + padding-bottomの合計値
			var total =  eachHeight + eachPaddingTop + eachPaddingBottom;
			if (jQuery.browser.msie && jQuery.browser.version == 6.0) { jQuery(this).children().css({'height': total}); };

			//IE6以外。paddingの値がそれぞれ違っても同じ高さになる。
			jQuery(this).children().css({'min-height': eachHeight , 'padding-top':eachPaddingTop,'padding-bottom':eachPaddingBottom});

		});
	};
	})(jQuery);

/**
*
* スライドスクロール
* jQuery required (tested on version 1.2.6)
* Copyright (c) 2008 nori (norimania@gmail.com)
* http://moto-mono.net
* Licensed under the MIT
*
*/

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

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