var images_after = new Array();

$(document).ready(function(){
	var i;
	i = 0;
	
	// グローバルメニュー
	$.each( $('.ro'), function() {
		var src = $(this).find('img').attr('src');
		var obj = $(this).find('img');
		var regexp = new RegExp('gbn_' + here_is + '.gif', 'i');
		if( obj.attr('src').match( regexp )) {
			obj.attr('src', obj.attr('src').replace(/(?:_ro)?(\.jpg|\.gif)$/i, '_on' ) + RegExp.$1 );
		} else {
			if( src ) {
				images_after[i] = new Image();
				images_after[i++].src  = obj.attr('src').replace(/(?:_ro)?(\.jpg|\.gif)$/i, '_ro' ) + RegExp.$1;
			}
			$(this).bind('mouseenter', function( evt ) {
				obj.attr('src', obj.attr('src').replace(/(?:_ro)?(\.jpg|\.gif)$/i, '_ro' ) + RegExp.$1 );
			});
			$(this).bind('mouseleave', function( evt ) {
				obj.attr('src', obj.attr('src').replace(/_ro\./i, '.' ));
			});
		}
	});
	
	// ボタン系背景ロールオーバー
	$.each( $('.bgro'), function() {
		$(this).bind('mouseenter', function( evt ) {
			$(this).css('background-image', $(this).css('background-image').replace(/(?:_ro)?\.gif/i, '_ro.gif' ));
		});
		$(this).bind('mouseleave', function( evt ) {
			$(this).css('background-image', $(this).css('background-image').replace(/_ro\./i, '.' ));
		});
	});
	
	// アイテムポイント時
	$.each( $('.list ul a'), function() {
		$(this).bind('mouseenter', function( evt ) {
			$(this).css('background-color', '#E4E4E4');
		});
		$(this).bind('mouseleave', function( evt ) {
			$(this).css('background-color', '#FFFFFF' );
		});
	});
	
	// 別窓表示
	$.each( $('a.nw'), function(){
		$(this).click( function(evt){
			window.open( this.href );
			return false;
		});
	});
	
	// galleria起動
	if( 0 < $('#galleria').size() ) {
		$('#galleria').galleria({
			//履歴を記録し戻るボタンで戻れるようにする
			history   : false, 
			//画像クリックで移動
			clickNext : true, 
			// メイン画像のセレクタ
			insert    : '#photos', 
			
			// 画像のエフェクト
			onImage   : function( image, caption, thumb ) { 
				//  画像とキャプションのフェイドイン 1000ミリ秒
				image.css('display','none').fadeIn(500);
				//caption.css('display','none').fadeIn(500);
				
				// サムネールのコンテナ
				var _li = thumb.parents('li');
				
				// サムネールのフェイドアウト
				_li.siblings().children('img.selected').fadeTo(500,0.3);
				
				// 次のサムネールをフェイドイン
				thumb.fadeTo('fast',1).addClass('selected');
				
				// 画像にtitle属性をセット
				image.attr('title','Next image >>');
			},
			
			// サムネールのエフェクト
			onThumb : function(thumb) {
				// サムネールのコンテナ
				var _li = thumb.parents('li');
				
				// サムネールアクティブならopacityを1、違えば0.3
				var _fadeTo = _li.is('.active') ? '1' : '0.3';
				
				// load終了でサムネールを_fadeToの値にフェイドイン
				thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1000);
				
				// ホバー時のトグルエフェクト
				thumb.hover(
					function() { thumb.fadeTo('fast',1); },
					function() { _li.not('.active').children('img').fadeTo('fast',0.3); });
			}
		});
	}
});

