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

////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
(function($) {
var myAgent = navigator.userAgent;
var whetherVST = myAgent.indexOf('NT 6.0');
var gHMList = {};
var totalNum = 1;
gHMList = {
	list0:[],list1:[],list2:[],list3:[],list4:[],list5:[],list6:[],list7:[],list8:[],list9:[]
};

//Newマークを表示するかどうが決める関数/////////////////////////////////////////////////////////////
//Use Top Page /////////////////////////////////////////////////////////////////////////////////////
$.fn.setNewMark = function (myDate){
	var myDateLen = myDate.length;
	var returnTag = (myDateLen >= 8) ? 'date' : 'date new';
	return returnTag;
};

//更新日を日付から逆算して、○時間前等の記述に変換する関数//////////////////////////////////////////
//Use Top Page /////////////////////////////////////////////////////////////////////////////////////
$.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;
};

//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;
	
	var mainGHM = $('div#globalHeader>ol#globalHeaderMenu>li');
	var subGHM = $('div#globalHeader>ol#globalHeaderMenu>li>ol');
	
	//文字列を変換して「%u」の文字があれば全角。それ以外は半角。/////////////////////////////////////
	//全角の場合は2を返し、半角の場合は1を返す。/////////////////////////////////////////////////////
	var strLength = function(strSrc){
		var len = 0;
		var countStrings = 0;
		
		for (i = 0; i<strSrc.length; i++){
		// 半角か全角の条件分岐
			if (strSrc.charCodeAt(i)<=255) {
				//小文字の数を数える
				if(strSrc.charCodeAt(i)<=64 || (strSrc.charCodeAt(i)>=91 && strSrc.charCodeAt(i)<=126)){
					countStrings += 1;
				}else{
					countStrings += 1.6;
				};
			}else{
				countStrings += 2;
			};
		
		};
		
		return countStrings;
	};

	//各リストの文字の長さを比べボックス(ol)の幅を設定する////////////////////////////////////////////
	var setLongstText = function(myList){
		var myListMaxLen = 0;
		if(myList == '') {
			//list○が空の場合は0にする。
			myListMaxLen = 0;
		}else{
			for (var i = 0, len = myList.length; i < len; i++) {
				if(myList[i].indexOf('<br>') >= 0 || myList[i].indexOf('<BR>') >= 0){
					var listALen = strLength(myList[i].slice(0,myList[i].indexOf('<')));
					var listBLen = strLength(myList[i].slice(myList[i].indexOf('<') + 4, myList[i].length));
					//alert(myList[i] + listALen + '改行' + listBLen);
					(myListMaxLen < listALen) ? myListMaxLen = listALen : null;
					(myListMaxLen < listBLen) ? myListMaxLen = listBLen : null;
				}else{
					var listLen = strLength(myList[i]);
					//alert(myList[i] + listLen);
					(myListMaxLen < listLen) ? myListMaxLen = listLen : null;
				};
			};
		};
		(myListMaxLen === 0) ? myListMaxLen = 12 : null;
		var myWidthScore = 0;
		(myListMaxLen < 18) ? myWidthScore = 8 : myWidthScore = 7 ;
		var myListMaxWidth = myListMaxLen*myWidthScore + 'px';
		$('div#globalHeader>ol#globalHeaderMenu>li:eq(' + totalNum +')>ol').css('width', myListMaxWidth);
		totalNum++;
	};
	
	//下の配列の準備が出来たら、上の処理を各リストごとに行う。
	var listWidthSet = function(){
		for (var i = 0, len = 9; i < len; i++) {
			var myText = gHMList['list' + (i+1)];
			setLongstText(myText)
		};
	};
	
	
	//ここが処理のはじまり。どんどん上に行く。
	//globalHeaderMenuの各リストの文字を配列に入れる。
	subGHM.each(function(i){
		var myListBox = gHMList['list' + (i+1)];
		$(this).children('li').each(function(i2){
			var myTextChiled = $(this).children().html();
			myListBox.push(myTextChiled);
		});
	}),listWidthSet(); 
	
	
	mainGHM.hover(
		function(){
			$(this).attr('class', 'over');
			$(this).children('ol').fadeIn(400);
			$(this).children('ol').children().fadeIn(400);
			$(this).children('ol').children().children().fadeIn(400);
		},
		function(){
			$(this).attr('class', '');
			$(this).children('ol').fadeOut(200);
			$(this).children('ol').children().fadeOut(200);
			$(this).children('ol').children().children().fadeOut(200);
		}
	);
});
})(jQuery);
