// The Total rows in the Media Bar at the boottom of the player.
var totalrows;
// The Current row in the Media Bar.
var currentrow;
// The thumbnail row in the Media Bar 
var thumbrows = new Array();
var thumbrows1 = new Array();
var thumbrows2 = new Array();
// The images row in the Media Bar 
var images = new Array();
/*
This function fades out and element and if there is a and second element it will fade in the second element.

Function: fadeRow(t,f)
Variable t: The Element that will be faded too. 
Variable f: The Element that will be faded from.

*/
function fadeRow(t,f) {
	// Is there one of two elements to fade too.
	if(t && f) {
		// If there are two elements the from element will be faded out and the to element will be recursivily 
		// passed backk to this function.
		new Effect.Fade(f,{duration: 1.0, from: .9, to: 0, afterFinish: function() { fadeRow(t); } });
	} else {
		// If there is only one element that element will be faded in.
		new Effect.Appear(t,{duration: 1.0, from: 0.1, to: 2.0, afterFinish: function() {} });
	}
}
/*
This function is assigned to the next button in the media bar. It cycles forward through the 
rows in the media bar when clicked.

Function: nextRow()
*/
function nextRow() 
{
	
	if((thumbrows.length-2) >= currentrow) {
		var t = currentrow + 1;
		var f = currentrow;
	} else {
		var t = 0;
		var f = (thumbrows.length-1);
	}
	currentrow = t;
	fadeRow(thumbrows[t],thumbrows[f]);
}

/*
This function is assigned to the back button in the media bar. It cycles backwards through the 
rows in the media bar when clicked.

Function: prevRow()
*/
function prevRow() 
{
	if(currentrow == 0) {
		var t = thumbrows.length-1;
		var f = 0;
	} else {
		var t = currentrow - 1;
		var f = currentrow;
	}
	currentrow = t;
	fadeRow(thumbrows[t],thumbrows[f]);
}
function nextRow1() 
{
	
	if((thumbrows1.length-2) >= currentrow) {
		var t = currentrow + 1;
		var f = currentrow;
	} else {
		var t = 0;
		var f = (thumbrows1.length-1);
	}
	currentrow = t;
	fadeRow(thumbrows1[t],thumbrows1[f]);
}

/*
This function is assigned to the back button in the media bar. It cycles backwards through the 
rows in the media bar when clicked.

Function: prevRow()
*/
function prevRow1() 
{
	if(currentrow == 0) {
		var t = thumbrows1.length-1;
		var f = 0;
	} else {
		var t = currentrow - 1;
		var f = currentrow;
	}
	currentrow = t;
	fadeRow(thumbrows1[t],thumbrows1[f]);
}
function nextRow2() 
{
	
	if((thumbrows2.length-2) >= currentrow) {
		var t = currentrow + 1;
		var f = currentrow;
	} else {
		var t = 0;
		var f = (thumbrows2.length-1);
	}
	currentrow = t;
	fadeRow(thumbrows2[t],thumbrows2[f]);
}

/*
This function is assigned to the back button in the media bar. It cycles backwards through the 
rows in the media bar when clicked.

Function: prevRow()
*/
function prevRow2() 
{
	if(currentrow == 0) {
		var t = thumbrows2.length-1;
		var f = 0;
	} else {
		var t = currentrow - 1;
		var f = currentrow;
	}
	currentrow = t;
	fadeRow(thumbrows2[t],thumbrows2[f]);
}
/*
This function sets the Media Control bar at the bottom of the Page.

Function: setMediaBar()
*/
function setMediaBar() {
	// Rows Counter
	var tr = 0; 
	// The DIV's in the Thumbnail DIV
	var mbdiv = document.getElementById('media-thumbnails').getElementsByTagName('div');
	// Loops through the DIV's 
	
	for(i=0; i<mbdiv.length; i++) {
		// Finds the Class Name(s)
		var c = mbdiv[i].className;
		// Finds the class name 'row'
		if(new RegExp('\\b'+'row'+'\\b').test(mbdiv[i].className))	{
			// Turns off the display
			thumbrows[tr] = mbdiv[i];
			
			thumbrows[tr].style.display = 'none';
			// Adds one the row Counter
			tr++;
		}
	}
	// Sets the global row total 
	totalrows = tr;
	// Sets the counter
	currentrow = 0;
	// Fades in the first row of thumbnails
	fadeRow(thumbrows[currentrow]);
	// Finds the back and nexts links
	var next = document.getElementById('top-next');
	var prev = document.getElementById('top-previous'); 
	// Assigns functions to the links
	next.onclick = function() { nextRow(); }
	prev.onclick = function() { prevRow(); }
	// Adds links to the thumbnails.
	//addThumbnailLinks();
}
function setMediaBar1() {
	// Rows Counter
	var tr = 0; 
	// The DIV's in the Thumbnail DIV
	var mbdiv = document.getElementById('media-thumbnails1').getElementsByTagName('div');
	// Loops through the DIV's 
	
	for(i=0; i<mbdiv.length; i++) {
		// Finds the Class Name(s)
		var c = mbdiv[i].className;
		// Finds the class name 'row'
		if(new RegExp('\\b'+'row'+'\\b').test(mbdiv[i].className))	{
			// Turns off the display
			thumbrows1[tr] = mbdiv[i];
			
			thumbrows1[tr].style.display = 'none';
			// Adds one the row Counter
			tr++;
		}
	}
	// Sets the global row total 
	totalrows = tr;
	// Sets the counter
	currentrow = 0;
	// Fades in the first row of thumbnails
	fadeRow(thumbrows1[currentrow]);
	// Finds the back and nexts links
	var next = document.getElementById('top-next');
	var prev = document.getElementById('top-previous');
	// Assigns functions to the links
	next.onclick = function() { nextRow1(); }
	prev.onclick = function() { prevRow1(); }
	// Adds links to the thumbnails.
	//addThumbnailLinks();
}
function setMediaBar2() {
	// Rows Counter
	var tr = 0; 
	// The DIV's in the Thumbnail DIV
	var mbdiv = document.getElementById('media-thumbnails2').getElementsByTagName('div');
	// Loops through the DIV's 
	
	for(i=0; i<mbdiv.length; i++) {
		// Finds the Class Name(s)
		var c = mbdiv[i].className;
		// Finds the class name 'row'
		if(new RegExp('\\b'+'row'+'\\b').test(mbdiv[i].className))	{
			// Turns off the display
			thumbrows2[tr] = mbdiv[i];
			
			thumbrows2[tr].style.display = 'none';
			// Adds one the row Counter
			tr++;
		}
		
	}
	// Sets the global row total 
	totalrows = tr;
	// Sets the counter
	currentrow = 0;
	// Fades in the first row of thumbnails
	fadeRow(thumbrows2[currentrow]);
	// Finds the back and nexts links
	var next = document.getElementById('top-next');
	var prev = document.getElementById('top-previous');
	// Assigns functions to the links
	next.onclick = function() { nextRow2(); }
	prev.onclick = function() { prevRow2(); }
	// Adds links to the thumbnails.
	//addThumbnailLinks();
}
/*

*/
function addThumbnailLinks() {
	//
	var ia = 0;
	//
	var mba = document.getElementById('media-thumbnails').getElementsByTagName('a');
	//
	for(i=0; i<mba.length; i++) {
		//
		var c = mba[i].className;
		//
		if(new RegExp('\\b'+'image'+'\\b').test(mba[i].className))	{
			//
			images[ia] = mba[i];
			images[ia].onclick = function() { alert('Image Clicked '+ this.childNodes[0].getAttribute('id')); }
			ia++;
		}
	}
}

/*

*/ 
function setLandingPage(obj){
	//alert('setLandingPage ' + obj);
	for(i=0; i<obj.length; i++){
		document.getElementById(obj[i]).style.display = 'none';
	}
	//
	fadeInObj(0, obj);
}
/*

*/
function fadeInObj (id, obj) {
	//alert('ID: ' + id + ' OBJ: ' + obj[id])
	if((id+1) < obj.length) {
		var e = document.getElementById(obj[id]);
		var id = id + 1;
		new Effect.Appear(e,{afterFinish: function() { fadeInObj (id, obj) } });
	} else {
		var e = document.getElementById(obj[id]);
		new Effect.Appear(e);
		id = 0;
	}
}

