var returnflag=0;
var returntop;
var menuflag=0;
var gnavi;
var targetposition;

//ロードイベント
window.addEvent('domready', function(){
	//外部変数の初期化	
	this.returntop = $$('div#footer p.return');
	this.gnavi = $('globalNavi');
	this.targetposition = gnavi.getPosition().y;
	
	/*ページ内へのリンクをクリックした際にスクロールする*/
	new SmoothScroll({
		duration: 1000,
		transition: Fx.Transitions.Bounce.easeOut
	}, window);
	
	/*トップへのリンクを非表示*/
	returntop.set('opacity', '0').setStyle('display', 'block');
	
	/*brogrollの右にタイトルを表示*/
	$each($$('ul.xoxo li'),function(el){
		var img = el.getElement('img');
		el.set('html',el.get('html')+ ' : ' + img.get('title')); 
	});
	var rainbowColor = ['#ed1a3d','#ffb74c','#ffd400','#008000','#009ad6','#234794','#a757a8'];
	var myColor = new Color('#f00');
	$each($$('ul#globalNavi li a'),function(el,index){
		el.setStyle('background-color','#fff');
		el.set('events', {
			'mouseover': function(e){
				e.stop();
				this.morph({
					//'background-color': '#f00',
					//'background-color': rainbowColor[index],
					'background-color' : '#36393D',
					'color' : '#fff'
				});
			},
			'mouseout': function(e){
				e.stop();
				this.morph({
					'background-color': '#fff',
					'color' : '#000'
				});
			}
		}); 
	});
});



/**
 * スクロールイベント 
 */
window.addEvent('scroll',function() {

/*
 * メニュー追従
 * メニューが画面上端に来たら固定配置
 */
	var y = window.getScroll().y;
	if(y>=this.targetposition && this.menuflag==0){
		this.gnavi.setStyles({
			position:'fixed',
			top:'0',
			bottom:'auto',
			width:'90%'
			});
		this.menuflag=1;
	}
	if(y<this.targetposition && this.menuflag==1){
		this.gnavi.setStyles({
			position: 'absolute',
			top: 'auto',
			bottom: '0',
			width: '100%'
		});
		this.menuflag=0;
	}

/*
 * トップに戻るの表示非表示
 * 300pxスクロールしたら表示
 */
	if(y>300 && this.returnflag==0){
		this.returntop.fade('in');
		this.returnflag=1;
	}
	else if(y<=300 && this.returnflag==1){
		this.returntop.fade('out');
		this.returnflag=0;
	}
});
