/*
 * Superfish v1.4.8 - jQuery menu widget
 * Copyright (c) 2008 Joel Birch
 *
 * Dual licensed under the MIT and GPL licenses:
 * 	http://www.opensource.org/licenses/mit-license.php
 * 	http://www.gnu.org/licenses/gpl.html
 *
 * CHANGELOG: http://users.tpg.com.au/j_birch/plugins/superfish/changelog.txt
 */

;(function($){
	$.fn.superfish = function(op){

		var sf = $.fn.superfish,
			c = sf.c,
			$arrow = $(['<span class="',c.arrowClass,'"> &#187;</span>'].join('')),
			over = function(){
				var $$ = $(this), menu = getMenu($$);
				clearTimeout(menu.sfTimer);
				$$.showSuperfishUl().siblings().hideSuperfishUl();
			},
			out = function(){
				var $$ = $(this), menu = getMenu($$), o = sf.op;
				clearTimeout(menu.sfTimer);
				menu.sfTimer=setTimeout(function(){
					o.retainPath=($.inArray($$[0],o.$path)>-1);
					$$.hideSuperfishUl();
					if (o.$path.length && $$.parents(['li.',o.hoverClass].join('')).length<1){over.call(o.$path);}
				},o.delay);	
			},
			getMenu = function($menu){
				var menu = $menu.parents(['ol.',c.menuClass,':first'].join(''))[0];
				sf.op = sf.o[menu.serial];
				return menu;
			},
			addArrow = function($a){ $a.addClass(c.anchorClass).append($arrow.clone()); };
			
		return this.each(function() {
			var s = this.serial = sf.o.length;
			var o = $.extend({},sf.defaults,op);
			o.$path = $('li.'+o.pathClass,this).slice(0,o.pathLevels).each(function(){
				$(this).addClass([o.hoverClass,c.bcClass].join(' '))
					.filter('li:has(ol)').removeClass(o.pathClass);
			});
			sf.o[s] = sf.op = o;
			
			$('li:has(ol)',this)[($.fn.hoverIntent && !o.disableHI) ? 'hoverIntent' : 'hover'](over,out).each(function() {
				if (o.autoArrows) addArrow( $('>a:first-child',this) );
			})
			.not('.'+c.bcClass)
				.hideSuperfishUl();
			
			var $a = $('a',this);
			$a.each(function(i){
				var $li = $a.eq(i).parents('li');
				$a.eq(i).focus(function(){over.call($li);}).blur(function(){out.call($li);});
			});
			o.onInit.call(this);
			
		}).each(function() {
			var menuClasses = [c.menuClass];
			if (sf.op.dropShadows  && !($.browser.msie && $.browser.version < 7)) menuClasses.push(c.shadowClass);
			$(this).addClass(menuClasses.join(' '));
		});
	};

	var sf = $.fn.superfish;
	sf.o = [];
	sf.op = {};
	sf.IE7fix = function(){
		var o = sf.op;
		if ($.browser.msie && $.browser.version > 6 && o.dropShadows && o.animation.opacity!=undefined)
			this.toggleClass(sf.c.shadowClass+'-off');
		};
	sf.c = {
		bcClass     : 'sf-breadcrumb',
		menuClass   : 'sf-js-enabled',
		anchorClass : 'sf-with-ul',
		arrowClass  : 'sf-sub-indicator',
		shadowClass : 'sf-shadow'
	};
	sf.defaults = {
		hoverClass	: 'sfHover',
		pathClass	: 'overideThisToUse',
		pathLevels	: 1,
		delay		: 800,
		animation	: {opacity:'show'},
		speed		: 'normal',
		autoArrows	: true,
		dropShadows : true,
		disableHI	: false,		// true disables hoverIntent detection
		onInit		: function(){}, // callback functions
		onBeforeShow: function(){},
		onShow		: function(){},
		onHide		: function(){}
	};
	$.fn.extend({
		hideSuperfishUl : function(){
			var o = sf.op,
				not = (o.retainPath===true) ? o.$path : '';
			o.retainPath = false;
			var $ol = $(['li.',o.hoverClass].join(''),this).add(this).not(not).removeClass(o.hoverClass)
					.find('>ol').hide().css('visibility','hidden');
			o.onHide.call($ol);
			return this;
		},
		showSuperfishUl : function(){
			var o = sf.op,
				sh = sf.c.shadowClass+'-off',
				$ol = this.addClass(o.hoverClass)
					.find('>ol:hidden').css('visibility','visible');
			sf.IE7fix.call($ol);
			o.onBeforeShow.call($ol);
			$ol.animate(o.animation,o.speed,function(){ sf.IE7fix.call($ol); o.onShow.call($ol); });
			return this;
		}
	});

})(jQuery);

////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
var myAgent = navigator.userAgent;
var whetherVST = myAgent.indexOf('NT 6.0');
var whetherIE = myAgent.indexOf('MSIE');
(function($) {
//Newマークを表示するかどうが決める関数////////////////////////////////////////////////////////////
$.fn.setNewMark = function (myDate){
	var myDateLen = myDate.length;
	var returnTag = (myDateLen >= 8) ? 'date' : 'date new';
	return returnTag;
};

//更新日を日付から逆算して、○時間前等の記述に変換する関数//////////////////////////////////////////
$.fn.prettyDate = function(myY, myM, myD, myH, myMu, myS){
	var newM
	if(myM.length === 3){
		if(myM === 'Jan'){ newM = '01'
		}else if(myM === 'Feb'){ newM = '02'
		}else if(myM === 'Mar'){ newM = '03'
		}else if(myM === 'Apr'){ newM = '04'
		}else if(myM === 'May'){ newM = '05'
		}else if(myM === 'Jun'){ newM = '06'
		}else if(myM === 'Jul'){ newM = '07'
		}else if(myM === 'Aug'){ newM = '08'
		}else if(myM === 'Sep'){ newM = '09'
		}else if(myM === 'Oct'){ newM = '10'
		}else if(myM === 'Nov'){ newM = '11'
		}else if(myM === 'Dec'){ newM = '12'
		}
	}else{
		newM = myM;
	};
	
	var date = new Date(myY, parseInt(newM,10)-1, parseInt(myD,10), parseInt(myH,10), parseInt(myMu,10), parseInt(myS,10));
	diff = (((new Date()).getTime() - date.getTime()) / 1000);
	day_diff = Math.floor(diff / 86400);
	
	var returnDate = '';
	
	if(day_diff === 0){
		if(diff < 60){
			returnDate = '直前';
		}else if(diff < 120){
			returnDate = '1分前';
		}else if(diff < 3600){
			returnDate = Math.floor( diff / 60 ) + '分前';
		}else if(diff < 7200){
			returnDate = '1時間前';
		}else{
			returnDate = Math.floor( diff / 3600 ) + "時間前";
		};
	}else if(day_diff == 1){
		returnDate = "昨日";
	}else{
		returnDate = myY + '.' + newM + '.' + myD;
	};
	return returnDate;
};


//Googlo Analyticsのカウント関数///////////////////////////////////////////////////////////////////
//Use Models Profile etc...////////////////////////////////////////////////////////////////////////
$.fn.countGA = function(myName){
	var meeCountName = location.pathname + myName;
	pageTracker._trackPageview(meeCountName);
};
//ADバナーをリフレッシュする関数///////////////////////////////////////////////////////////////////
//Use Models Profile etc...////////////////////////////////////////////////////////////////////////
$.fn.setADBanner = function(thisPageAdd){
	var adBannerURL = '../contents/ad_banner.html';
	var adBannerTarget = $('div#oggiAD300');
	
	var thisPageADDLength = thisPageAdd.length;
	
	var thisPagePath = thisPageAdd.slice(thisPageAdd.indexOf('/', 7), thisPageADDLength);
	var loadAddName =  adBannerURL + '#' + thisPagePath;
	
	if(myAgent.indexOf('Win') >= 0){
		var myCSSClip = 'rect(2px ' +  302 + 'px ' + 252 +'px 2px)';
	}else{
		var myCSSClip = 'rect(0px ' +  300 + 'px ' + 250 +'px auto)';
	};
	
	var targetElement = adBannerTarget;
	
	targetElement.empty();
	targetElement.hide();
	
	targetElement.append(
		$('<iframe></iframe>').attr({
			'id':'meeWin_inner',
			'src':loadAddName,
			'scrolling':'no',
			'frameborder':'0',
			'width':'320',
			'height':'270'
		})
		.css({
			'position':'absolute',
			'border':'0px',
			'z-index':'20',
			'clip':myCSSClip
		})
	);

	targetElement.show();
	
	$('iframe#meeWin_inner').attr('frameborder','0');
};

$(document).ready(function(){
	//VISTAの場合のフォントサイズフィッティング//////////////////////////////////////////////////////
	(whetherVST >= 0) ? $('body').css('font-size','80%') : null;
	
	
	//Global Header Menu の処理ここから ///////////////////////////////////////////////////////////▼
	var mainGHM = $('div#globalHeader>ol#globalHeaderMenu>li');
	var subGHM = $('div#globalHeader>ol#globalHeaderMenu>li>ol');
	var subGHMList = subGHM.children('li').children('a');
	var nowHoverIDName = '';
	var btnHovarSwitch = false;
	
	//各リストにナンバリングする。（各リストで何番目か）
	mainGHM.each(function(i){
		$(this).children('ol').children('li').each(function(j){
			$(this).children('a').addClass('no' + j);
		});
	});
	
	//メインメニューのHoverの処理
	mainGHM.hover(
		function(){
			btnHovarSwitch = true;
			nowHoverIDName = $(this).attr('id');
			$(this).addClass('hover');
			$(this).children('ol').fadeIn(600, function(){
				hideOtherGHM();
				(btnHovarSwitch == false)? subGHM.hide(): null;
				subGHM.css('visibility', 'visible');
			});
		},
		function(){
			$(this).removeClass('hover');
			$(this).children('ol').hide();
		}
	);
	
	$('div#globalHeader>ol#globalHeaderMenu', 'div#globalHeader>ol#globalHeaderMenu>li').mouseout(function(){
		subGHM.hide();
		btnHovarSwitch = false;
	});
	
	//サブメニューのHoverの処理
	subGHMList.hover(
		function(){
			var myNum = ($(this).attr('class').length > 3) ? parseInt($(this).attr('class').slice(2,4),10) : parseInt($(this).attr('class').slice(2,3),10);
			var myPos = '0px ' + ((14 - myNum) * -32) + 'px';
			$(this).parent('li').parent('ol').css('background-position', myPos);
		},
		function(){
			$(this).parent('li').parent('ol').css('background-position', '0px 0px');
		}
	);
	
	function hideOtherGHM(){
		//alert(nowHoverIDName);
		mainGHM.each(function(i){
			var myIDName = $(this).attr('id');
			if(myIDName == nowHoverIDName){
				null;
			}else{
				$(this).children('ol').hide();
			};
		});
	};
	
	//Global Header Menu の処理ここまで ///////////////////////////////////////////////////////////▲
	
	
	//Global Footer Menu の処理ここから ///////////////////////////////////////////////////////////▼
	var mainGFM = $('ol#globalFooterMenu>li');
	var topListNum = 0;
	var bottomListNum = 0;
	
	//上下それぞれの行の中で一番列数が多いものを調べて変数に入れる
	mainGFM.each(function(i){
		var myListNum = $(this).children('ol').children().length;
		var myListHTML = $(this).children('ol').html();
		
		//改行タグが含まれる場合は2行と見なす
		if(myListHTML == null){
		}else{
			if(myListHTML.indexOf('<br>') > -1){
				myListNum += strCount(myListHTML, '<br>');
			}else if(myListHTML.indexOf('<BR>') > -1){
				myListNum += strCount(myListHTML, '<BR>');
			};
		};
		
		if(i < 4){
			topListNum = (myListNum > topListNum) ? myListNum : topListNum;
			$(this).addClass('topList');
		}else{
			bottomListNum = (myListNum > bottomListNum) ? myListNum : bottomListNum;
			$(this).addClass('bottomList');
		};
	});
	
	//上で取得した変数からそれぞれの行の高さを設定
	//2010.2.5 かける値を20→18にした。
	var topListHeight = topListNum*16;
	var bottomListHeight = bottomListNum*16;
	
	$('li.topList').each(function(i){
		$(this).css('height', topListHeight);
	});
	$('li.bottomList').each(function(i){
		$(this).css('height', bottomListHeight);
	});
	
	//上下の行の高さを足してトータルの高さを設定
	var totalHeight = topListHeight + bottomListHeight + 30;
	$('ol#globalFooterMenu').css('height', totalHeight);
	
	
	//文字列の中から特定の単語を探す（inSTR:任意の文字列　findSTR:探したい単語）
	function strCount(inSTR, findSTR){
		var icount;
		var rtnNum = 0;
		var iCount = inSTR.indexOf(findSTR,0)
		while ( iCount >= 0 ) {
		iCount = inSTR.indexOf(findSTR,++iCount);
		rtnNum++;
		}
		return rtnNum;
	};
	
	//各リストの頭のアイコンを切り替える
	mainGFM.children('ol').children('li').children('a').hover(
		function(){
			$(this).parent().addClass('over');
		},
		function(){
			$(this).parent().removeClass('over');
	});
	
	//Global Footer Menu の処理ここまで ///////////////////////////////////////////////////////////▲

	//Global Header Menu(Superfish対応) の処理 ////////////////////////////////////////////////////▲
	$(function(){
		$('ol.globalHeaderMenu').superfish();
	});

});
})(jQuery);