/**
 * jQuery.ScrollTo - Easy element scrolling using jQuery.
 * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 3/9/2009
 * @author Ariel Flesler
 * @version 1.4.1
 *
 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
 */
;(function($){var m;m=$.scrollTo=function(b,h,f){$(window).scrollTo(b,h,f)};m.defaults={axis:'xy',duration:parseFloat($.fn.jquery)>=1.3?0:1};m.window=function(b){return $(window).scrollable()};$.fn.scrollable=function(){return this.map(function(){var b=this,h=!b.nodeName||$.inArray(b.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!h)return b;var f=(b.contentWindow||b).document||b.ownerDocument||b;return $.browser.safari||f.compatMode=='BackCompat'?f.body:f.documentElement})};$.fn.scrollTo=function(l,j,a){if(typeof j=='object'){a=j;j=0}if(typeof a=='function')a={onAfter:a};if(l=='max')l=9e9;a=$.extend({},m.defaults,a);j=j||a.speed||a.duration;a.queue=a.queue&&a.axis.length>1;if(a.queue)j/=2;a.offset=n(a.offset);a.over=n(a.over);return this.scrollable().each(function(){var k=this,o=$(k),d=l,p,g={},q=o.is('html,body');switch(typeof d){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px)?$/.test(d)){d=n(d);break}d=$(d,this);case'object':if(d.is||d.style)p=(d=$(d)).offset()}$.each(a.axis.split(''),function(b,h){var f=h=='x'?'Left':'Top',i=f.toLowerCase(),c='scroll'+f,r=k[c],s=h=='x'?'Width':'Height';if(p){g[c]=p[i]+(q?0:r-o.offset()[i]);if(a.margin){g[c]-=parseInt(d.css('margin'+f))||0;g[c]-=parseInt(d.css('border'+f+'Width'))||0}g[c]+=a.offset[i]||0;if(a.over[i])g[c]+=d[s.toLowerCase()]()*a.over[i]}else g[c]=d[i];if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],u(s));if(!b&&a.queue){if(r!=g[c])t(a.onAfterFirst);delete g[c]}});t(a.onAfter);function t(b){o.animate(g,j,a.easing,b&&function(){b.call(this,l,a)})};function u(b){var h='scroll'+b;if(!q)return k[h];var f='client'+b,i=k.ownerDocument.documentElement,c=k.ownerDocument.body;return Math.max(i[h],c[h])-Math.min(i[f],c[f])}}).end()};function n(b){return typeof b=='object'?b:{top:b,left:b}}})(jQuery);


(function($){
	$(document).ready(function() {
		/* 
		 *
		 *  scrolltoTop 
		 *  ページトップへスクロール
		 *
		 */
		$('a.backtotop').click(function(){
			$.scrollTo(0, 400);
			return false;
		});
		/* 
		 *
		 *  current directory 
		 *  カレントディレクトリを表示
		 *	naviName に記載されたIDを持つaタグにlocalNaviSelectedクラスを付与する
		 *	フォントサイズを固定（2009/10/23 最終的に追加）
		 *
		 */
		var baseURL = "http://"+location.hostname+"/";
		var $1st = location.pathname.split("/")[1];
		var $2nd = location.pathname.split("/")[2];
		var $3rd = location.pathname.split("/")[3];
		var $4th = location.pathname.split("/")[4];
		var $5th = location.pathname.split("/")[5];
		
		var $url = location.pathname.split("/");

				// globalnavi
				var $hMenu = $('#headerMenuWrap');
				if(location.pathname != "/") {
					$hMenu.find('a[href^="/' + $1st + '"]').addClass('globalNaviSelected')
					.end().find('a[href^="' + baseURL + $1st + '"]').addClass('globalNaviSelected');
				} else {
					$hMenu.find('a:eq(0)').addClass('globalNaviSelected');
				}
				$hMenu.find('a').css("font-size","13px");
				
				// #ui-localNav 〜 #ui-localNav3rd
				naviName = new Array(
					'localNavi', 'ui-localNav2nd', 'ui-localNav3rd', 'ui-boxNav'
				);
				for (i = 0; i < naviName.length; i++) {
					var navi = naviName[i];
					switch (i) {
						case (0) :
							if(!!$url[2]){
								$htmlName = ($url[2].length > 0) ? ('/' + $url[2] + '/'): '';
							} else {
								$htmlName = '';
							}
							break;
						case (1) :
							if (!!$url[3]) {
								$htmlName = ($url[3].length > 0) ? ('/' + $url[3] + '/'): '';
							} else {
								$htmlName = '';
							}
							break;
						case (2) :
							$htmlName = $url[$url.length - 1];
							break;
					}
					if (!!document.getElementById(navi)) {
						switch ($htmlName) {
							case "" :
								$('#' + navi + ' a:eq(0)').addClass('localNaviSelected');
								break;
							default :
								$('#' + navi + ' a[href*="' + $htmlName + '"]').addClass('localNaviSelected');
						}
					}
				}
				
				// チームページ
				if (location.pathname.indexOf('/team/')) {
					var $htmlName = $url[$url.length - 1];
					var $htmlpre = $htmlName.substr(0,8); // schedule
					switch ($htmlName) {
						case "" :
						case "index.html" :
							$('#teamMenu a:eq(0)').addClass('teamMenuSelected');
							break;
						default :
							$('#teamMenu a[href$="' + $htmlName + '"]').addClass('teamMenuSelected');
							$('.scheduleMonthList a[href$="' + $htmlName + '"]').addClass('selected');
							
							// チームスケジュール
							if($htmlpre=='schedule') {
									$('#teamMenu a[href$="schedule.html"]').addClass('teamMenuSelected');	
							}
					}
					

				}
		/* 
		 *
		 *  a.external target="_blank"
		 *  外部リンクにはクラス指定とtarget="_blank"
		 *
		 */
			$('#mainLeft a').filter(function() {
				return this.hostname && this.hostname !== location.hostname;
			//}).addClass("external").attr("target", "_blank");
			}).attr("target", "_blank");
		/*
		 *
		 *	stripedtable
		 *	テーブルを1行おきにクラス設定
		 *  thead には適用しない
		 *
		 */
		var tbl = $('#mainLeft table.stripedtable');
		var n = tbl.size();
		var $tr,s,parentTagName,j;
		// テーブル数分繰り返す
		for(var i=0;i<n;i++){
			$tr = tbl.eq(i).find('tr');
			s = 0;
			for (var ii = 0,iTotal = $tr.length; ii < iTotal; ii++){
				j = $tr.eq(ii);
				parentTagName = j.parent().get(0).tagName.toUpperCase();
				if(j.hasClass('nostripe')||parentTagName=="THEAD"){
				} else {
					if(s==0){
						j.addClass("odd");
						s ++;
					} else {
						j.addClass("even");
						s --;
					}; //end if
				}; // end if
			}; // end for
		}; // end for
		
		var tbl = $('#mainRight table.stripedtable');
		var n = tbl.size();
		for(var i=0;i<n;i++){
			tbl.eq(i).find('tr:even').addClass("even");
			tbl.eq(i).find('tr:odd').addClass("odd");
		}
	

		
		/* 
		 *
		 *  table.tbl-standings
		 *  クラス指定された各テーブルごと1行おきにカラーリング
		 *
		 */
		var tbl = $('#mainLeft table.tbl-standings');
		var n = tbl.size();
		for(var i=0;i<n;i++){
			tbl.eq(i).find('tr:even').addClass("even");
		}
		
		/*
		*
		*		footer copyright
		*		フッターエリアのコピーライト表記
		*
		*/
		var d = new Date();
		var copyStr = 'Copyright(C)NEC BIGLOBE, Ltd. 1996-'+d.getFullYear();
		$('#footerCopyright').html(copyStr);
	
		 
		//	サイドバー用
		//		var scdBase = '/parts/dummy/golf/scheduleDummy20090802.html';
		if (typeof(window.scdBase) !== 'undefined') {
			$('#scdArea').load(scdBase);	//	スケジュール
		}
		if (typeof(window.newsBase) !== "undefined") {
			$('#newsArea').load(newsBase);	//	ニュース
		}
		if (typeof(window.scoreBase) !== "undefined") {
			$('#scoreArea').load(scoreBase);	//	スコアボード
		}
		if (typeof(window.statsBase) !== "undefined") {
			$('#statsArea').load(statsBase);	//	ランキング
		}

	});

		/* 
		 *
		 *  サイドバー用
		 *
		 *	初期読込みファイルは別途指定する
		 *	var scdBase = "/parts/dummy/golf/scheduleDummy20090802.html";
		 *
		 *	読込むHTMLから以下のメソッドを渡す
		 *	<script type="text/javascript">
		 *	(function($){
		 *		$(document).ready(function() {
		 *			$.sidebarDisp.mkLinkNEWS('','/parts/dummy/golf/newsDummy20090803.html');
		 *		});
		 *	})(jQuery);
		 *	</script>
		 *	
		 *
		 */
		 
		$.sidebarDisp = {
			
			mkLinkSCD: function(prevFile, nextFile) {
				this.mkLINK('#scheduleLinkPrev', '#scdArea', prevFile);
				this.mkLINK('#scheduleLinkNext', '#scdArea', nextFile);
			},
			mkLinkNEWS: function(prevFile, nextFile) {
				this.mkLINK('#newsLinkPrev', '#newsArea', prevFile);
				this.mkLINK('#newsLinkNext', '#newsArea', nextFile);
			},
			mkLinkSCORE: function(prevFile, nextFile) {
				this.mkLINK('#scoreLinkPrev', '#scoreArea', prevFile);
				this.mkLINK('#scoreLinkNext', '#scoreArea', nextFile);
			},
			mkLinkSTATS: function(prevFile, nextFile) {
				this.mkLINK('#statsLinkPrev', '#statsArea', prevFile);
				this.mkLINK('#statsLinkNext', '#statsArea', nextFile);
			},
			mkLINK: function(linkName, areaID, fileName) {
				if (fileName == '') {
					if(linkName.indexOf('Prev')>0) {
						$(areaID + ' li.prev').html("<span class='lightgray'>"+$(areaID + ' li.prev').text()+"</span>");
					} else if(linkName.indexOf('Next')>0) {
						$(areaID + ' li.next').html("<span class='lightgray'>"+$(areaID + ' li.next').text()+"</span>");
					}
				} else {
					$(linkName).click(function () {
						$(areaID).load(fileName);
					});
				}
				
				/*
				*
				*		striped table 処理
				*
				*/
				var tbl = $(areaID + ' table.stripedtable');
				var n = tbl.size();
				for(var i=0;i<n;i++){
					tbl.eq(i).find('tr:even').addClass("even");
					tbl.eq(i).find('tr:odd').addClass("odd");
				}
				
			}
			
		}
		
		
})(jQuery);

/* jumpMenu */
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

/* trackback用 selectText*/
function selectText(textarea_id)
{
	var textarea;
	if (document.all) textarea = document.all[textarea_id];
	else textarea = document.getElementById(textarea_id);
	textarea.focus();
	textarea.select();
}

//
// fireBugコンソール用
// consoleが定義されていない場合には動作しない
//
function trace(str){ 
	// consoleが定義されている場合
	if (typeof window.console === 'object' /*&& !$.browser.msie*/) {
		console.log(str);
	}
}
function timeStart(str){
	// consoleが定義されている場合
	if (typeof window.console === 'object' && !$.browser.msie) {
		console.time(str);
	}
}
function timeEnd(str){
	// consoleが定義されている場合
	if (typeof window.console === 'object' && !$.browser.msie) {
		console.timeEnd(str);
	}
}

//
//	jqueryオブジェクトの中身をダンプする関数
//
function jquery_dump($obj) {
	var dumphtml = [];
	if($.browser.msie) {
		for(var i = 0; i < $obj.length; i++) {
			dumphtml.push('[' + i + '] ');
			dumphtml.push($obj[i].outerHTML.replace(/^[\r\n\t]+/, ''));
			dumphtml.push("\n");
		}
	} else {
		for(var i = 0; i < $obj.length; i++) {
			dumphtml.push('[' + i + '] '
				+ '<' + $obj[i].nodeName.toLowerCase());
			for(var j = 0; j < $obj[i].attributes.length; j++) {
				dumphtml.push(' ' + $obj[i].attributes[j].nodeName + '="' 
					+ $obj[i].attributes[j].nodeValue + '"');
			}
			dumphtml.push('>' + $obj[i].innerHTML);
			dumphtml.push('<\/' + $obj[i].nodeName.toLowerCase() + '>');
			dumphtml.push("\n");
		}
	}
	trace(dumphtml.join(''));
}
