//------------------------------------------------------------------------------
//  WAX 1.4 - general-purpose web application library
//  Copyright (C) 2000-2007 SnapWorks
//  Website : http://www.snapworks.com/
//  Email   : info@snapworks.com
//------------------------------------------------------------------------------

function countVisibleMenus() {
	
	var counter = 0;
	
	for (x in activeRelations) {
		if( $("menu_"+activeRelations[x]) ) {
			counter++;
		}	
	}
	
	return counter;

}

var infoVisible = false;

function showInfo() {
	if(isInfo) { 
		infoVisible = infoVisible ? false : true;
		setInfoStyle();
		showContentElement();
	}	
}

function showDelayedInfo() {
	setTimeout("showInfo()", 2000);	
}


function setInfoStyle() {
	if(isInfo) { 
		var info = $('info');
		info.style.fontWeight = infoVisible ? "bold" : "normal";
	}	
}

function showContentElement() {

	var content = $('content');
	var pw =  $('pw');
	
	if(infoVisible && (pw.style.display == '')) {
		pw.style.display = 'none';
	}

	//if( (!infoVisible) && (movieImagesPending > 0 )) {
//		pw.style.display = '';
//	}

	if( (imagesLoaded == 0)) {
		$('pw').style.display = '';
	}

	content.style.display = infoVisible ? "" : "none";
	
	if(!infoVisible) { closeThemeInfo(); }
}

var visibleThemeBox = false;

function showThemeInfo( id ) {
	
	var themeInfo = $('themeInfo' );
		themeInfo.style.display = '';
		
	if( visibleThemeBox ) {

		var themeInfo = $('themeInfoBox_' + visibleThemeBox );
			themeInfo.style.display = 'none';
	
	}
	
	var themeInfo = $('themeInfoBox_' + id );
		themeInfo.style.display = '';

		
	visibleThemeBox = id;
}

function closeThemeInfo() {

	if($('themeInfo')) {
		var themeInfo = $('themeInfo');
			themeInfo.style.display = 'none';
	}
			
	if( visibleThemeBox ) {
		var themeInfo = $('themeInfoBox_' + visibleThemeBox );
			themeInfo.style.display = 'none';
	}
}

function prepareContentElement() {

	var info = $('info');
	var content = $('content');
	var footer = $('footer');
	var menuHeight = $('menu_0').offsetHeight * (countVisibleMenus() - 1); 
		content.style.position = 'absolute';
		content.style.width = '100%';
		content.style.height = Math.floor(height / 1.6); 
		content.style.top = Math.floor(((height - content.offsetHeight) / 2) + (menuHeight / 2));

		applyAlpha(content, globalAlpha);
		
		content.style.backgroundColor = '#ffffff';
		
		if(isInfo) {
			info.style.display = ''
		}
		
		setInfoStyle();

	var imagebox = $('imagebox');
		imagebox.style.top = $('menu_0').offsetHeight;
		imagebox.style.height = height - ( 2 * $('menu_0').offsetHeight ) + 2;
		imagebox.style.width = width;
		
		// alert("width: " + imagebox.offsetWidth + "height: " + imagebox.offsetHeight);
		
	var title = $('title');
		title.style.left = "16px";
		title.style.top = "16px";	
		title.style.display = '';

	var close = $('close');
		close.style.right = "16px";
		close.style.top = "16px";	
		close.style.display = '';
		

	if($('text')) { 
		var text = $('text');
			text.style.left = (content.offsetWidth / 2) + 16;
			text.style.top = "48px";
			text.style.width = (content.offsetWidth / 2 )- 32;
			text.style.height = content.offsetHeight - 64;
			text.style.overflow = "auto";
			text.style.display = '';
	}
	
	if($('themeInfo')) { 
	var themeInfo = $('themeInfo');
		themeInfo.style.height = content.offsetHeight - 32; 
		themeInfo.style.top = Math.floor(((height - content.offsetHeight) / 2) + (menuHeight / 2)) + 16;
		themeInfo.style.width = "50%";
		themeInfo.style.left = "35%";
	}
	
	var introduction = $('introduction');
		introduction.style.left = "16px";
		introduction.style.top = "48px";
		
		if($('text')) {
			introduction.style.width = (content.offsetWidth / 2 )- 16;
			introduction.style.height = content.offsetHeight - 64;
		} else {
			introduction.style.width = (content.offsetWidth ) - 32;
			introduction.style.height = content.offsetHeight - 64;
		}
		
		introduction.style.overflow = "auto";
		introduction.style.display = '';


	content.style.display = 'none';
	content.style.visibility = "visible";		
}