/*
 * Page inits
 */
function initPage(entry) {
	handleEntry(entry);
	handleSubNavigation();
	handleMainContentBanner();
}

/*
 * Handles the page when it's the entry page
 */
function handleEntry(entry) {
	if (entry) {
		// first hide whole element, then appear element in. in case javascript is disabled, page is shown anyway
		//document.getElementById('pageWrapper').style.display = 'none';
		//Effect.Appear('pageWrapper', {duration: 2});
	}
	else {
		//do nothing
	}
}

/*
 * Checks if there is a sub navigation and hides it if there is none
 */
function handleSubNavigation() {
	//vars 
	var activeWithSub = document.getElementById('activeWithSub');
	var subNav = document.getElementById('subNav');
	//if there is no active element with subnav, hide the subnav
	if (activeWithSub == null) {
		subNav.style.display = 'none';
	}
}

/*
 * Fades out the visible player details (if any) and lets appear the details of the given player
 */
function togglePlayerDetails(uid) {
	//
	//hide all player details
	//
	//iterate through all divs till we find the active player details div (if any)
	var allDivs = document.getElementsByTagName("div");
	var i = 0;
	while (i < allDivs.length) {
		var div = allDivs[i];
		if (div.className == 'playerDetails' &&
			div.style.display != 'none') {
			//hide player details	
			var playerDetailsDivId = div.id;
			var command = 'Effect.Fade(\''+playerDetailsDivId+'\', {duration: 0.7})';
			setTimeout(command, 0);
			//break; //do not break but continue instead, in order to fade ALL divs of player details
			i++;
		}
		else {
			i++;
		}
	}
	
	//show player details of given player
	var playerDetailsDivId = 'playerDetails'+uid;
	var command = 'Effect.Appear(\''+playerDetailsDivId+'\', {duration: 1})';
	setTimeout(command, 750);
}

/*
 * Checks if there is an img inside mainContentBanner and shows it in that case.
 * Otherwise, nothing is done.
 */
function handleMainContentBanner() {
	//vars
	var mainContentBanner = document.getElementById('mainContentBanner');
	var mainContentBannerImg = document.getElementById('mainContentBannerImg');
	var ext = mainContentBannerImg.src.substring(mainContentBannerImg.src.lastIndexOf('.')+1);
	//decide whether to show mainContentBanner div or not. show it only if we have a correct jpg.
	if (ext == 'jpg') {
		//Effect.BlindDown('mainContentBanner', {duration: 0.75});
		mainContentBanner.style.display = 'block';
	}
}

/*
 * Toggles the main content banner image and changes the button (link) text accordingly
 */
function toggleMainContentBanner() {
	//vars
	var mainContentBannerImgWrapper = document.getElementById('mainContentBannerImgWrapper');
	var mainContentBannerButtonImg = document.getElementById('mainContentBannerButtonImg');
	var imgClose = 'fileadmin/img/icons/bannerClose.gif';
	var imgOpen = 'fileadmin/img/icons/bannerOpen.gif';
	//do correct action, set correct button
	if (mainContentBannerImgWrapper.style.display != 'none') {
		Effect.BlindUp('mainContentBannerImgWrapper', {duration: 0.5});
		mainContentBannerButtonImg.src = imgOpen;
	}
	else {
		Effect.BlindDown('mainContentBannerImgWrapper', {duration: 0.5});
		mainContentBannerButtonImg.src= imgClose;
	}
}

