/**
 * Hokuetsu Site Interface Controller
 * Date: 7/17/2008
 * @author xe-que design works
 * @version 1.0
 *
 */


jQuery(function( $ ){

	// 固定値（検索エリア）
	OPT_TOGGLE_SPEED    =  500; // スクロールスピード(ms)

	// 固定値（トップメニュー）
	OPT_SCROLL_SPEED    =  500; // スクロールスピード(ms)
	OPT_CROSSFADE_SPEED = 4000; // クロスフェードスピード(ms)
	OPT_CROSSFADE_DELAY = 6000; // クロスフェード待機時間(ms)

	// 固定値（ページトップのスライドショー）
	OPT_SLIDESHOW_SPEED =  4000; // クロスフェードスピード(ms)
	OPT_SLIDESHOW_DELAY =  6000; // クロスフェード待機時間(ms)

	// -----------------
	// 全ページ共通
	// -----------------
	
	// フォントサイズ指定を表示(普段は CSS で display:none してある)
	$('ul#textsize').show();
	$('a#switch').css('display','block');
	$('#togglewrapper').show();
	
	
	// 検索エリアトグル
	var unit = 'px';
	var boxheight = $('#utility').height() - 40;
	$('#togglewrapper').css('visibility', 'visible');
	$('#togglewrapper').height(boxheight - 60 + unit);
	$('#utility').css('margin-top', '-' + boxheight + unit);
	$('#switch').toggle(
		function(){
			$('.container').animate({top: boxheight + unit}, OPT_TOGGLE_SPEED, 'easeout');
			$(this).css('background-position', '0 -19px');
		},
		function(){
			$('.container').animate({top: '0' + unit}, OPT_TOGGLE_SPEED, 'easeout');
			$(this).css('background-position', '0 0');
		}
	);

	// -----------------
	// トップページのみ
	// -----------------

	// トップページのみ動作
	if($('#navigation').length){
		// スクロール設定
		$('#navigation').localScroll({
			target:'#screen',
			axis:'x',
			queue:true,
			speed:OPT_SCROLL_SPEED,
			onBefore:function( e, el, $target ){
				$target.stop().stop();//to avoid queueing animations
				$( '#navigation a.scrolling' ).removeClass('scrolling');						
				$(this).addClass('scrolling').get(0).blur();
			},
			onAfter:function(){
				$('#navigation a.scrolling' ).removeClass('scrolling');
			}
		});
		
		// クリック時にタブの画像を切り替え	
		$('#tabmenu li a').bind('click',function(e){
				idx = (this.id.split('-')[1] - 1) * 50;
				$('#tabmenu').css('background-position','0 -' + idx + 'px');
		});
	
		// CrossFader 設定(#section-1 内の div.section-1-img を自動で登録)
		i = 0;
		aryImagesDiv = Array();
		$("#section-1 div.section-1-img").each(function(){
			aryImagesDiv[i] = this.id;
			i++;
		});
		 var cf = new Crossfader( aryImagesDiv, OPT_CROSSFADE_SPEED, OPT_CROSSFADE_DELAY );

		// ニューストピックスのスクロールバー置換え
		$('.scrollpanel').jScrollPane();
	}


	// -----------------
	// トップページ以外
	// -----------------
	
	// スライドショー要素が存在？
	if ($('#slideshow').length){
		// Crossfader
		i = 0;
		aryImagesDiv = Array();
		$("#slideshow li.slideshow-img").each(function(){
			aryImagesDiv[i] = this.id;
			i++;
		});
		var cf = new Crossfader( aryImagesDiv, OPT_SLIDESHOW_DELAY, OPT_SLIDESHOW_SPEED );
	}
});
$(document).ready(function(){
	//文字のグラディエント処理
	$(".gradient").prepend("<span><\/span>");
	$(".frame").prepend("<span><\/span>");
	$(".frame-wide").prepend("<span><\/span>");

	// 偶数行の色を指定
//	$("#page #content table tr:odd").css("backgroundColor","#F5F5F5");
	$("#page #content table").each(function(){
		$("tr:odd", this).css("backgroundColor","#F5F5F5");
	});
	$("#page #content-wide table").each(function(){
		$("tr:odd", this).css("backgroundColor","#F5F5F5");
	});

	// アコーディオン
	//$("#accordions").accordion();
});
