var topIndex;
function topStars(index) {
	topIndex = index;
	newShootingRecEntriesContent = "";
	for (i=0;i<5;i++) {
		if(top[index+i] != undefined)
			newShootingRecEntriesContent +=	top[index+i];
	}
	$('ShootingRecFrame1').innerHTML = newShootingRecEntriesContent;
	if (topIndex == 0 ) {
		$('prevShootingRecButton').style.visibility='hidden';
	}
	if(totalNumberOfShootingRec<10){
		$('nextShootingRecButton').style.visibility='hidden';
		
	}
}
function nextTopRecs() {
	topStars(topIndex+5);
	$('prevShootingRecButton').style.visibility='visible';
	if (topIndex + 5 < totalNumberOfShootingRec) {
		$('nextShootingRecButton').style.visibility='visible';
	} else {
		$('nextShootingRecButton').style.visibility='hidden';
	}
}
function prevTopRecs() {
	topStars(topIndex-5);
	$('nextShootingRecButton').style.visibility='visible';
	if (topIndex > 0) {
		$('prevShootingRecButton').style.visibility='visible';
	} else {
		$('prevShootingRecButton').style.visibility='hidden';
	}
}

var newIndex;
function newRecs(index) {
	newIndex = index;
	newNewestRecEntriesContent = "";
	for (i=0;i<5;i++) {
		newNewestRecEntriesContent += newestRec[index+i];
	}
	$('newestFrame1').innerHTML = newNewestRecEntriesContent;	
	if(newIndex==0){
		$('prevNewestButton').style.visibility='hidden';
	}
	
}

function nextNewRecs() {
	newRecs(newIndex+5);
	$('prevNewestButton').style.visibility='visible';
	if (newIndex +5 < totalNumberOfNewestRec) {
		$('nextNewestButton').style.visibility='visible';
	} else {
		$('nextNewestButton').style.visibility='hidden';
	}
}
function prevNewRecs() {
	newRecs(newIndex-5);
	$('nextNewestButton').style.visibility='visible';
	if (newIndex > 0) {
		$('prevNewestButton').style.visibility='visible';
	} else {
		$('prevNewestButton').style.visibility='hidden';
	}
}

var imgIndex = 0;
function newImages(index) {
	imgIndex = index;
	newImagesContent = "";
	var j = 5;
	for (var i=0;i<j;i++) {	
		var actIndex = index+i;		
		
		if (actIndex >= userImg.length) {
			actIndex = actIndex % userImg.length;
		}
		
		if (actIndex < 0) {
			actIndex = actIndex + userImg.length;
			imgIndex = userImg.length-1;
		}
						
		if (userImg[actIndex] != null) {
			newImagesContent += "<div class='newcUsrPicWiz' id='avatar"+(userImg[actIndex][0])+"' ><a href='#' onclick='selectAva("+(userImg[actIndex][0])+");return false;'><img width='95' height='75' src='"+appPath+(userImg[actIndex][1])+"'/></a></div>"; }
	}
	$('imageFrame').innerHTML = newImagesContent;	
}

function nextImages() {	
		newImages(imgIndex+1);
}

function prevImages() {	
		newImages(imgIndex-1);
}

function showNextTopMikestars(frame1,prevButton,nextButton){
	newTopMikestarsContent = "";
	topMikestarsFirstIndex += 4;
	liveList.getTopUsers(topMikestarsFirstIndex, 4, function (data){
	for (i=0;i<data.length;i++) {
		newTopMikestarsContent += topMikestarUserFormatter(data[i]);
	}
	if (topMikestarsFirstIndex <= totalNumberOfTopMikestars) {
		window.setTimeout("showNext()", 100);
		
		if(topMikestarsFirstIndex >= 4)
			$(prevButton).style.visibility='visible';
		if ((topMikestarsFirstIndex+4) >= totalNumberOfTopMikestars)
			$(nextButton).style.visibility='hidden';
	} else {
		topMikestarsFirstIndex -= 4;
	}
	});
}	
function showPrevTopMikestars(frame1,prevButton,nextButton){
	newTopMikestarsContent = "";
	topMikestarsFirstIndex -= 4;
	if (topMikestarsFirstIndex >= 0) {
		liveList.getTopUsers(topMikestarsFirstIndex, 4, function (data){
			for (i=0;i<data.length;i++) {
				newTopMikestarsContent += topMikestarUserFormatter(data[i]);
			}
			window.setTimeout("showNext()", 100);
			
			$(nextButton).style.visibility='visible';
			if (topMikestarsFirstIndex <= 0) {
				$(prevButton).style.visibility='hidden';
			}
		});
	}
}
function showNextMostViewedEntries(frame1,prevButton,nextButton){
	newMostViewedEntriesContent = "";
	mostViewedFirstIndex += 4;
	ajaxRecord.getMostViewedRecords(mostViewedFirstIndex, 4, function (data){
		for (i=0; i < data.length; i++){
			newMostViewedEntriesContent += recordListingFormatter(data[i]);
		}
		if (mostViewedFirstIndex <= totalNumberOfMostViewed) {
		window.setTimeout("showNextMostViewed('"+frame1+"')",100);
		
		if (mostViewedFirstIndex >= 4)
			$(prevButton).style.visibility='visible';
		if ((mostViewedFirstIndex+4) >= totalNumberOfMostViewed)
			$(nextButton).style.visibility='hidden';
		} else {
		mostViewedFirstIndex -= 4;
		}		
	});	
}
function showPrevMostViewedEntries(frame1,prevButton,nextButton){
	newMostViewedEntriesContent = "";
	mostViewedFirstIndex -= 4;
	if (mostViewedFirstIndex >= 0){
		ajaxRecord.getMostViewedRecords(mostViewedFirstIndex, 4, function (data){
			for (i=0; i < data.length; i++){
				newMostViewedEntriesContent += recordListingFormatter(data[i]);
			}
			window.setTimeout("showNextMostViewed('"+frame1+"')", 100);
			
			$(nextButton).style.visibility='visible';
			if (mostViewedFirstIndex <= 0) {
				$(prevButton).style.visibility='hidden';
			}
		});		
	}
}
function showPrevShootingEntries(frame1,prevButton,nextButton) {
	newShootingRecEntriesContent = "";
	shootingListFirstIndex -= 4;
	if (shootingListFirstIndex >= 0){
		ajaxRecord.getShootingRecords(shootingListFirstIndex, 4, function (data){
			for (i=0; i < data.length; i++){
				newShootingRecEntriesContent += recordListingFormatter(data[i]);
			}
			window.setTimeout("showNextShooting('"+frame1+"')", 100);
			
			$(nextButton).style.visibility='visible';
			if (shootingListFirstIndex <= 0) {
				$(prevButton).style.visibility='hidden';
			}
		});
	}
}
function showNextShootingEntries(frame1,prevButton,nextButton) {
	newShootingRecEntriesContent = "";
	shootingListFirstIndex += 4;
	ajaxRecord.getShootingRecords(shootingListFirstIndex, 4, function (data){
		for (i=0; i < data.length; i++){
			newShootingRecEntriesContent += recordListingFormatter(data[i]);
		}
		if (shootingListFirstIndex <= totalNumberOfShootingRec) {
		window.setTimeout("showNextShooting('"+frame1+"')",100);
		
		if (shootingListFirstIndex >= 4)
			$(prevButton).style.visibility='visible';
		if ((shootingListFirstIndex+4) >= totalNumberOfShootingRec)
			$(nextButton).style.visibility='hidden';
		} else {
			shootingListFirstIndex -= 4;
		}
	});
}
function showNextNewestEntries(frame1,prevButton,nextButton) {
	newNewestRecEntriesContent = "";
	newestListFirstIndex += 4;
	ajaxRecord.getNewestRecords(newestListFirstIndex, 4, function (data){
		for (i=0; i < 4; i++){
			newNewestRecEntriesContent += recordListingFormatter(data[i]);
		}
		if (newestListFirstIndex <= totalNumberOfNewestRec) {
		window.setTimeout("showNextNewest('"+frame1+"')",100);
		
		if (newestListFirstIndex >= 4)
			$(prevButton).style.visibility='visible';
		if ((newestListFirstIndex+4) >= totalNumberOfNewestRec)
			$(nextButton).style.visibility='hidden';
		} else {
			newestListFirstIndex -= 4;
		}
	});
}
function showPrevNewestEntries(frame1,prevButton,nextButton) {
	newNewestRecEntriesContent = "";
	newestListFirstIndex -= 4;
	if (newestListFirstIndex >= 0){
		ajaxRecord.getNewestRecords(newestListFirstIndex, 4, function (data){
			for (i=0; i < data.length; i++){
				newNewestRecEntriesContent += recordListingFormatter(data[i]);
			}
			window.setTimeout("showNextNewest('"+frame1+"')",100);
			
			$(nextButton).style.visibility='visible';
			if (newestListFirstIndex <= 0) {
				$(prevButton).style.visibility='hidden';
			}
		});
	}
}
function showNextContestEntries(contestID, lastRecord, frame1,prevButton,nextButton){
	newContestEntriesContent = "";
	contestFirstIndex += 4;
	ajaxRecord.getContestRecords(contestID, lastRecord, contestFirstIndex, 4, function (data){
		for (i=0; i < data.length; i++){
			newContestEntriesContent += contestUserFormatter(data[i],contestID);
		}
		if (contestFirstIndex <= totalNumberOfContestEntries) {
		window.setTimeout("showNextContest('"+frame1+"')",100);
		
		if (contestFirstIndex >= 4)
			$(prevButton).style.visibility='visible';
		if ((contestFirstIndex+4) >= totalNumberOfContestEntries)
			$(nextButton).style.visibility='hidden';
		} else {
			contestFirstIndex -= 4;
		}
	});	
}
function showPrevContestEntries(contestID, lastRecord, frame1,prevButton,nextButton){
	newContestEntriesContent = "";
	contestFirstIndex -= 4;
	if (contestFirstIndex >= 0){
		ajaxRecord.getContestRecords(contestID, lastRecord, contestFirstIndex, 4, function (data){
			for (i=0; i < data.length; i++){
				newContestEntriesContent += contestUserFormatter(data[i], contestID);
			}
			window.setTimeout("showNextContest('"+frame1+"')", 100);
			
			$(nextButton).style.visibility='visible';
			if (contestFirstIndex <= 0) {
				$(prevButton).style.visibility='hidden';
			}
		});		
	}
}
function showNext(){
	var topMikeStarsFrame1 = document.getElementById("topMikeStarsFrame1");
	topMikeStarsFrame1.innerHTML = newTopMikestarsContent;		
	Effect.Appear("topMikeStarsFrame1",{duration:0.5});
}
function showNextMostViewed(frame1){
	var topMikeStarsFrame1 = document.getElementById(frame1);
	topMikeStarsFrame1.innerHTML = newMostViewedEntriesContent;		
	Effect.Appear(frame1,{duration:0.5});
}
function showNextShooting(frame1){
	var ShootingFrame = document.getElementById(frame1);
	ShootingFrame.innerHTML = newShootingRecEntriesContent;		
	//Effect.Appear(frame1,{duration:0.5});
}
function showNextNewest(frame1){
	var NewestFrame = document.getElementById(frame1);
	NewestFrame.innerHTML = newNewestRecEntriesContent;		
	//Effect.Appear(frame1,{duration:0.5});
}
function showNextContest(frame1) {
	$(frame1).innerHTML = newContestEntriesContent;
	Effect.Appear(frame1,{duration:0.5});
}
var topUsers = null;
function loadTopMikestarsContent(){
	var topMikeStarsFrame2 = document.getElementById("topMikeStarsFrame2");
	topUsers = liveList.getTopUsers(topListFirstIndex, numberOfTopMikestars, createTopUserEntries);
}
function loadTopEntriesContent(){
	var topMikeStarsFrame2 = document.getElementById("topEntriesFrame1");
	topUsers = liveList.getTopUsers(topEntriesFirstIndex, numberOfTopEntries, createTopUserEntriesMostViewed);
}
var mostViewedEntries = null;
function loadMostViewedEntriesContent(){
	var topMikeStarsFrame2 = document.getElementById("mostViewedFrame1");
	mostViewedEntries = ajaxRecord.getMostViewedRecords(mostViewedFirstIndex, numberOfMostViewed, createTopUserEntriesMostViewed);
}
var shootingRecEntries = null;
function loadShootingRecsContent() {
	shootingRecEntries = ajaxRecord.getShootingRecords(shootingListFirstIndex, numberOfShootingRec, createShootingRecEntriesMostViewed);	
}
function createTopUserEntries(data){
	newTopMikestarsContent = "";
	for (i=0; i < data.length; i++){
		newTopMikestarsContent += topMikestarUserFormatter(data[i]);
	}
}	
function contestUserFormatter(data, contestID) {
	if (data != null) {
		return '<div class="top_mikestar" style="height:120px;">' +																		
			   '<div class="userpic_frame_nofloat" style="position:relative">' +
			   '<a class="horizontal_rec_box" href="'+contextPath+'/Contest/detail?contest=' + contestID + '&record='+ data.recordID + '" ><img src="'+contextPath + ((data.webcam == true)?data.previewImage:((data.user.partner == 'MTV')?partnerImage:data.user.image.avatarThumb)) + '" style="width:74px;height:55px;" alt="' + data.user.username + '" title="' + data.user.username + '"/></a>' +
			   '</div>' +	
			   '<ul style="text-align:center;">' + 
			   '<li style="margin-bottom:5px;"><h3><a href="'+contextPath+'/Contest/detail?contest=' + contestID +'&record='+ data.recordID + '" class="user">' +
			   ( (data.user.partnerUsername.length < 15)?data.user.partnerUsername:data.user.partnerUsername.substring(0, 14)+"..." ) +
			   '</a></h3></li>' + 
			   '<li><a class="horizontal_rec_box" href="'+contextPath+'/Contest/detail?contest=' + contestID + '&record='+ data.recordID + '" >' + 
			   ((data.song.songTitle != 'Freestyle')?((data.song.songTitle.length < 25)?data.song.songTitle:data.song.songTitle.substring(0,24)+"..."):((data.title.length < 25)?data.title:data.title.substring(0,24)+"..."))+ 
			   '</a></li>' + 
			   '</ul>' + 		
		       '</div>';
	} else {
		return '<div class="top_mikestar" style="height:120px;">' +																		
			   '<div class="userpic_frame_nofloat" style="position:relative">' +
			   '<span>Kein weiterer Teilnehmer vorhanden. Jetzt mitmachen!</span>' +
			   '</div>' +	
			   '<ul style="text-align:center;">' + 
			   '<li style="margin-bottom:5px;"></li>' + 
			   '</ul>' + 		
		       '</div>';
	}	
}	
function topMikestarUserFormatter(data) {
	
	var username = data.username;
	var partnerUsername = data.partnerUsername;
	var avatar = data.image.avatarThumb;
	var numOfFans = data.numOfFans;
	var numOfRecords = data.numOfRecords;
	var country = data.country;

	
	return '<div class="top_mikestar" >' +																		
		'<div class="userpic_frame_nofloat" style="position:relative">' +
				'<a href="'+contextPath+'/Member/detail?user=' + username + '" ><img src="'+contextPath+ ((data.partner == 'MTV')?partnerImage:avatar) + '" alt="' + username + '" title="' + username + '"/></a>' +
		'</div>' +	
		'<h3><a href="'+contextPath+'/Member/detail?user=' + username +'" class="user">' +
		( (partnerUsername.length > 8)?partnerUsername:partnerUsername.substring(0, 7) ) +
		'</a></h3>' + 
		'<ul>' + 
			'<li><img class="stats_fan" src="'+contextPath+'/img/icons/star_little2.gif" /><span class="grey_thin_small">' + numOfFans + " "+((numOfFans == 1)?numOfFanLabel:numOfFansLabel) + '</span></li>' + 
			'<li><img class="stats_disc" src="'+contextPath+'/img/icons/disc_little.gif" /><span class="grey_thin_small">' + numOfRecords + " " + ((numOfRecords == 1)?numOfRecordLabel:numOfRecordsLabel) + '</span></li>' + 
		'</ul>' + 
	 '</div>';
}	
function recordListingFormatter(data) {
	return '<div class="top_mikestar" style="height:120px;"><div class="userpic_frame_nofloat" style="position:relative">' +
		   '<a class="horizontal_rec_box" href="'+contextPath+'/Record/play?record=' + data.recordID + '" ><img src="'+contextPath+ ((data.webcam == true)?data.previewImage:((data.user.partner == 'MTV')?partnerImage:data.user.image.avatarThumb)) + '" style="width:74px;height:55px;" alt="' + data.user.username + '" title="' + data.user.username + '"/></a>' +
		   '</div><ul style="text-align:center;"><li style="margin-bottom:5px;"><h3><a href="'+contextPath+'/Member/detail?user=' + data.user.username +'" class="user">' + ((data.user.partnerUsername.length < 15)?data.user.partnerUsername:data.user.partnerUsername.substring(0, 14)+"..." ) +
		   '</a></h3></li><li><a class="horizontal_rec_box" href="'+contextPath+'/Record/play?record=' + data.recordID +'">' + ((data.song.songTitle.length < 25)?data.song.songTitle:data.song.songTitle.substring(0,24)+"...")+ '</a></li></ul></div>';
}	
function showNextShootingEntriesLanding(frame1,prevButton,nextButton) {
	newShootingRecEntriesContent = "";
	shootingListFirstIndex += 7;
	ajaxRecord.getShootingRecords(shootingListFirstIndex, 7, function (data){
		for (i=0; i < data.length; i++){
			newShootingRecEntriesContent += recordListingFormatter(data[i]);
		}
		if (shootingListFirstIndex <= totalNumberOfShootingRec) {
		//Effect.Fade(frame1,{duration:0.5});
		window.setTimeout("showNextShooting('"+frame1+"')",100);
		
		} else {
			shootingListFirstIndex -= 7;
		}
	});
}