// JavaScript Document

// 利用法: log('inside coolFunc', this, arguments);
window.log = function(){
  log.history = log.history || [];  // ログを配列に保存
  log.history.push(arguments);
  arguments.callee = arguments.callee.caller;  
  if(this.console) console.log( Array.prototype.slice.call(arguments) );
};

// 常に安全にconsole.logを利用できるように
(function(b){function c(){}for(var d="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(","),a;a=d.pop();)b[a]=b[a]||c})(window.console=window.console||{});




// ★別々のスクリプトファイルではなく(リクエストを増やさない)jQueryのプラグイン、ヘルパプラグインをここに記述すること。

/*************************************
* INDEX
* 
* 1. jquery.hover.js
* 2. jquery.flatheights.js
* 3. year.js
* 4. jquery.socialbutton-1.8.0.js

**************************************/

/****************************************
* Rollover Script on JQuery
* Rollover class = imgOver
* Rollover FileName = ***_o.jpg/gif/png
* Original Source : http://peps.ca/blog/easy-image-rollover-script-with-jquery/
****************************************/

$(document).ready( function()
{
 PEPS.rollover.init();
});

PEPS = {};

PEPS.rollover =
{
 init: function()
 {
    this.preload();
    
    $(".imgover").hover(
       function () { $(this).attr( 'src', PEPS.rollover.newimage($(this).attr('src')) ); },
       function () { $(this).attr( 'src', PEPS.rollover.oldimage($(this).attr('src')) ); }
    );
 },
 
 preload: function()
 {
    $(window).bind('load', function() {
       $('.imgover').each( function( key, elm ) { $('<img>').attr( 'src', PEPS.rollover.newimage( $(this).attr('src') ) ); });
    });
 },
 
 newimage: function( src ) { return src.substring( 0, src.search(/(\.[a-z]+)/) ) + '_o' + src.match(/(\.[a-z]+)/)[0]; },
 oldimage: function( src ){ return src.replace(/_o/, ''); }
};



/***********************
*
* jquery.flatheights.js
*
************************/
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 timer = 0;
	/* 文字の大きさが変わったか */
	var isChanged = function() {
		ins.appendTo('body');
		var size = ins[0].offsetHeight;
		ins.remove();
		if (self.currentSize == size) return false;
		if (timer < 2) {
			timer +=1;
		} else {
			self.currentSize = size;
			timer = 0;
		};
		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)で選択した複数の要素について、それぞれ高さを
	一番高いものに揃える
======================================================================
*/

/* 対象となる要素群の集合 */
var FLAT_HEIGHT_SETS = [];
(function($) {

	/* 対象となる要素群の集合 */
//	var sets = [];

	/* 高さ揃えの処理本体 */
	var flatHeights = function(set) {
//	console.log('flatHeights')
		var maxHeight = 0;
		set.each(function(){
			var height = $(this).height();
//			var height = this.offsetHeight;
			if (height > maxHeight) maxHeight = height;
		});
		if (maxHeight > 0) {
			set.css('height', maxHeight + 'px');
		}
	};

	/* 要素群の高さを揃え、setsに追加 */
	jQuery.fn.flatHeights = function() {
//		if (initFlag) sets = [];
//	console.log('jQuery.fn.flatHeights')
//	console.log(FLAT_HEIGHT_SETS.length)
		if (this.length > 1) {
			flatHeights(this);
			FLAT_HEIGHT_SETS.push(this);
		}
		return this;
	};

	/* 文字の大きさが変わった時に、
	   setsに含まれる各要素群に対して高さ揃えを実行 */
	$.changeLetterSize.addHandler(function() {
		$.each(FLAT_HEIGHT_SETS, function() {
			this.height('auto');
			flatHeights(this);
		});
	});
})(jQuery);



function setFlatHeightElements() {
	FLAT_HEIGHT_SETS = [];
	$('div, ul').filter(function (index) {
		return $(this).get(0).className.indexOf('flatHeight-') > -1
	}).each(function(i) {
		var clsList = $(this).get(0).className.split(' ');
		var splitChildLength;
		for (j=0;j<clsList.length;j++) {
			if (clsList[j].indexOf('flatHeight-') > -1) {
				splitChildLength = clsList[j].split('flatHeight-');
				break;
			}
		}
		var childIndex = splitChildLength[1].split('C');
		splitChildLength = parseInt(childIndex[0]);
		if (childIndex[1]) {
			childIndex = childIndex[1];
		} else {
			childIndex = undefined;
		}
		var sets = [], temp = [];
		$(this).children('div:visible, li:visible').each(function(i) {
			if (childIndex == undefined) {
				temp.push(this);
			} else {
				temp.push($('*:eq(' + childIndex + ')', this).get(0));
			}
			if (i % splitChildLength == (splitChildLength - 1)) {
				sets.push(temp);
				temp = [];
			}
		});
		if (temp.length) sets.push(temp);
		$.each(sets, function() {
			$(this).flatHeights();
		});
	});
	$('div, ul').filter(function (index) {
		return $(this).get(0).className.indexOf('flatHeightParent') > -1
	}).each(function(i) {
		var sets = [], temp = [];
		$(this).children().each(function(i) {
			temp.push(this);
		});
		if (temp.length) sets.push(temp);
		$.each(sets, function() {
			$(this).flatHeights();
		});
	});
}
$(function(){
	/*-------------
	flatHeight実行
	--------------*/
	($.browser.safari ? $(window).load : $).call($(window), function () {
		setFlatHeightElements();
	});
});


/***********************
*
* year.js
*
************************/
function chgYear(){
	var myDate=new Date();
	var nowYear=myDate.getFullYear();
	
	return nowYear;
}


