// JavaScript Document

jQuery(document).ready(function($) {
	
	// init rollover
	JsRoller.initialize( 'rollover' );
	
	
	$("#box1").hide();
	$("#box2").show();
	$("#topBannerArea").animate({ height: "397px"}, 800, easing, function (){
	curFocus = 2;
	});
	
});


// scrollTo
function move(n){
	$.scrollTo(n, 500);
}


//ON AIR SCHEDULE Tab
$(function(){
    $("div.panel ul:not("+$("ul.tab li a.selected").attr("href")+")").hide();
    $("ul.tab li a").click(function(){
        $("ul.tab li a").removeClass("selected");
        $(this).addClass("selected");
		$("div.panel ul").hide();
        $($(this).attr("href")).show();
		
        return false;
		
		
    })
})



//POPUP Artist detail page
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}





//mainNavi display on off
$(document).ready(function() {
	$("#navi01").hover(function(){
		$(this).css("cursor","pointer");
	},
	function(){
		$(this).css("cursor","default"); 
		});	
});



												
var curFocus = 0;
var btnClicked = 0;

var easing = 'easeInOutExpo';

function topToggle(n){
	//alert(n);
	btnClicked = n;
	if(btnClicked == 1){
		if(curFocus == 1){
			$("#topBannerArea").animate({ height: "0px"}, 800, easing, function(){
				curFocus = 0;	
			});
		} else {
			if(curFocus == 2){
				$("#topBannerArea").animate({ height: "0px"}, 800, easing, function (){
					curFocus = 0;
					$("#box1").show();
					$("#box2").hide();
					$("#topBannerArea").animate({ height: "290px"}, 800, easing, function(){
						curFocus = 1;
					})
				});
			} else {
				$("#box1").show();
				$("#box2").hide();
				$("#topBannerArea").animate({ height: "290px"}, 800, easing, function (){
					curFocus = 1;
				});
			}
		}
		
	} else if(btnClicked == 2){
		if (curFocus == 2) {
			$("#topBannerArea").animate({ height: "0px"}, 800, easing, function(){
				curFocus = 0;
			});
		} else {
			if (curFocus == 1) {
				$("#topBannerArea").animate({ height: "0px"}, 800, easing, function (){
					curFocus = 0;
					$("#box1").hide();
					$("#box2").show();
					$("#topBannerArea").animate({ height: "397px"}, 800, easing, function(){
						curFocus = 2;
					})
				});
			} else{
				$("#box1").hide();
				$("#box2").show();
				$("#topBannerArea").animate({ height: "397px"}, 800, easing, function (){
					curFocus = 2;
				});
			}
		}
	} 
	  
}


//News Ticker
$(function(){
			function newsFader(elm,fadeSpeed,fadeInterval){
				if(elm.length<=1) return false;
				
				elm.each(function(i){
					$(this).attr("id","news-"+i);
					if(i!=0) $(this).hide();
				});
				
				var start = count = 0,
					end = elm.length-1,
					fadeTimer = setInterval(function(){
						$("#news-"+(start==1 ? count==0 ? end : count-1 : count)).hide();
						$("#news-"+(start==1 ? (++count)-1 : ++count)).fadeIn(fadeSpeed);
						if(start==0 && count>=end){
							count = 0;
							start = 1;
						}else if(start==1 && count>end){
							count = 0;
						}
					},fadeInterval);
			}
			newsFader($("li","div#newsTicker ul"),"slow",3000);
		});

//ランダムバナー
function rdmad() {
        totalprobability = 0;
        rdmadi=0;
	ad=new Array();
	//基本入力項目
	//ad[0]=new adlist('確率(入力値/入力値の合計)','URLを記述','バナー広告の画像パスを入力','バナーのALTタグ用のタイトル');
	ad[0]=new adlist('33','http://www.denbak-fano.com','img/banner/banner01.jpg','協賛');
	ad[1]=new adlist('33','http://www.denbak-fano.com','img/banner/banner02.jpg','協賛');
	ad[2]=new adlist('33','http://www.denbak-fano.com','img/banner/banner03.jpg','協賛');

        //確率の合計を計算
        for(i=0; i < ad.length ;i++) {
            totalprobability += parseInt(ad[i].probability);
        }

	//乱数を発生させる
	//rdmadi=Math.floor(ad.length * Math.random());
        rdmadi=Math.floor(totalprobability * Math.random());

	totalprobability = 0 ;
        //確率の合計を計算
        for(i=0; i < ad.length ; i++) {
            totalprobability += parseInt(ad[i].probability);
            if (rdmadi <= totalprobability) {
                rdmadi = i;
                break;
            }
        }

	//乱数をインデックスとして利用し、配列から広告データ取り出す
	document.write ('<a href=\"' + ad[rdmadi].url + '\" target=\"_blank\"><img src=\"' + ad[rdmadi].imgpath + '\" alt=\"' + ad[rdmadi].title + '\"  width=\"528\" border=\"0\" height=\"83\"></a>');
	document.close();
}

//adlistクラス
function adlist(probability,url, imgpath, title){
	this.probability=probability;	//Probability
	this.url=url;		//URL
	this.imgpath=imgpath;	//Image Path
        this.title=title;	//Title
}
