var theNextImage=0;
var width=1024;
var height=768;
var ratio = width/height;

window.onload = doSetup;
window.onresize = myResize;

var someimages = new Array();

someimages[0] = "lbg17.jpg";
someimages[1] = "lbg3.jpg";
someimages[2] = "lbg9.jpg";
someimages[3] = "lbg5.jpg";
someimages[4] = "lbg6.jpg";
someimages[5] = "lbg7.jpg";
someimages[6] = "lbg11.jpg";
someimages[7] = "lbg10.jpg";
someimages[8] = "lbg12.jpg";
someimages[9] = "lbg8.jpg";
someimages[10] = "lbg13.jpg";
someimages[11] = "lbg2.jpg";
someimages[12] = "lbg18.jpg";

var numberOfImages=someimages.length;


function showContent(content)
{

	if($(content).style.display=='none')
	{
		hideCurrent();
		Effect.Appear(''+content,{duration:.2});
	}
	else
		Effect.Fade(''+content,{duration:.2});
}


var menuClasses = new Array();
menuClasses[0]="homeContent";
menuClasses[1]="aboutContent";
menuClasses[2]="whoContent";
menuClasses[3]="tvContent";
menuClasses[4]="picturesContent";
menuClasses[5]="watchContent";
menuClasses[6]="merchContent";
menuClasses[7]="contactContent";

function hideCurrent()
{
	for(var i=0; i<menuClasses.length; i++)
	{
		if($(menuClasses[i]).style.display!="none")
		{	
			$(menuClasses[i]).style.display="none"
		}
	}
}


function showBio(bioID)
{
	if($(bioID).style.display=='none')
	{
		$('joshBio').style.display='none';
		$('danBio').style.display='none';
		$('jonBio').style.display='none';
		$('simonBio').style.display='none';
		$('kirstenBio').style.display='none';
		Effect.Appear(''+bioID,{duration:.2});
	}
	else
		Effect.Fade(''+bioID,{duration:.2});
}

function doSetup()
{
	myResize();
	
	theNextImage=Math.floor(1+Math.random()*numberOfImages)-1
	
	document.getElementById("bgImage").src="backgrounds/"+someimages[theNextImage];
	
	//unhide to show the home page on load
	//showContent('homeContent');
	
	var start = setTimeout('startImageRotation()', 2000);
}


var t;

function startImageRotation()
{
	t = setInterval('nextImage()', 5000);
}

function endImageRotation()
{
	clearInterval(t);
}


var newImage = new Image();
newImage.src="backgrounds/"+someimages[theNextImage];

function nextImage()
{
	
	if(newImage.complete)
	{
		document.getElementById("bgImage").src=newImage.src;
		
		if(theNextImage+1<numberOfImages)
		{
			theNextImage++;
			
		}else 
		{
			theNextImage=0;
		}
		
		newImage = new Image();
		newImage.src="backgrounds/"+someimages[theNextImage];
	}
}


function myResize() {
	if (document.all)
	{
		
		
		var theBG = document.getElementById("mainBG");
		var theBGimg = document.getElementById("bgImage");
		
		
		
		if(document.documentElement.clientWidth/document.documentElement.clientHeight<=ratio)
		{
			theBGimg.setAttribute('height',document.documentElement.clientHeight);
			theBGimg.setAttribute('width',document.documentElement.clientHeight*ratio);
			
		}
		else
		{

			theBGimg.setAttribute('width',document.documentElement.clientWidth);
			theBGimg.setAttribute('height',document.documentElement.clientWidth/ratio);
		}
	}
	else
	{
		var theBG = document.getElementById('mainBG');
		var theBGimg = document.getElementById('bgImage');

		
		
		if(window.innerWidth/window.innerHeight<=ratio)
		{
			
			theBGimg.setAttribute('height',window.innerHeight);
			theBGimg.setAttribute('width',window.innerHeight*ratio);

			
		}
		else
		{
			theBGimg.setAttribute('height',window.innerWidth/ratio);
			theBGimg.setAttribute('width',window.innerWidth);
		}


		//alert("2: "+window.innerWidth+" "+theBG);
	}
}

var hideMe;

function showVideo(vidID)
{
	endImageRotation();
	/*$('bbep1video').style.display="none";
	$('bbep2video').style.display="none";
	$('bbep3video').style.display="none";
	$('bbep4video').style.display="none";
	$('bbep5video').style.display="none";
	$('bbep6video').style.display="none";
	$('bbep7video').style.display="none";
	$('csep0video').style.display="none";
	$('csep1video').style.display="none";
	$('csep2video').style.display="none";
	$('csep3video').style.display="none";
	$('csep4video').style.display="none";
	$('csep5video').style.display="none";
	$('csep6video').style.display="none";
	$('csep7video').style.display="none";*/
	
	hideMe=$(vidID);
	$('normalContent').style.display="none";
	$(vidID).style.display="block";
	Effect.Appear('videoContent');
}

function backVid()
{
	hideMe.style.display="none";
	$('videoContent').style.display="none";
	$('normalContent').style.display="block";
	startImageRotation();
}
