/**
 * @author Jeff Stirn
 * 
 */

//global var
//var iCurrentContentElement = 0;

/**
 * 
 * @param {integer} pContentID
 * id of the content element to show
 * 
 * @param {boolean} pMode
 * true: to show all the content elements
 * false: to hide all the content elements
 * 
 * @param {string} pHash
 * prefix of the id
 * 
 */
function showHideElement(pContentID, pMode, pHash){
	//var iNbrContentElements = document.getElementsByName('r_content_element').length;
	var iNbrContentElements = 0;
	
	var arrDocumentDivs = document.getElementById('ct_r_content').getElementsByTagName('div');
	for (i = 0; i < arrDocumentDivs.length; i++){
		if (arrDocumentDivs[i].className == "r_content_element"){
			iNbrContentElements ++;
		}
	}
	if (iNbrContentElements > 0){
		//hide all the content elements
		toggleContentElements(false, iNbrContentElements, pHash);
		
		//set the content navigation
		showHideContentNavigation(pContentID, iNbrContentElements, pHash);
		
		//now show the current requested content element
		if (pMode){
			document.getElementById(pHash + 'id' + pContentID.toString()).style.display = 'block';
		}else{
			document.getElementById(pHash + 'id' + pContentID.toString()).style.display = 'none';
		}
	}else{
		//set the content navigation
		showHideContentNavigation(0, iNbrContentElements, pHash);
	}
	
}

/**
 * 
 * @param {integer} pCurrentElement
 * id of the current shown element
 * 
 * @param {integer} pTotalElements
 * total number of all Content Elements
 * 
 * @param {string} pHash
 * prefix of the id
 * 
 */
function showHideContentNavigation(pCurrentElement, pTotalElements, pHash){
	//first hide the navigation arrows
	document.getElementById(pHash + 'next').style.display = 'none';
	document.getElementById(pHash + 'prev').style.display = 'none';
	
	//check if we have to show the next arrow
	if (pCurrentElement < pTotalElements){
		//we have to show the next arrow
		document.getElementById(pHash + 'next').style.display = 'block';
		
		//set the a href link
		var oHrefElement = document.getElementById(pHash + 'next').getElementsByTagName('a')[0];
		oHrefElement.setAttribute('href', 'javascript:showHideElement(' + (pCurrentElement + 1).toString() + ', true, \'' + pHash + '\');');
	}
	//check if we have to show the previous arrow
	if (pCurrentElement > 1){
		//we have to show the previous arrow
		document.getElementById(pHash + 'prev').style.display = 'block';
		
		//set the a href link
		var oHrefElement = document.getElementById(pHash + 'prev').getElementsByTagName('a')[0];
		oHrefElement.setAttribute('href', 'javascript:showHideElement(' + (pCurrentElement - 1).toString() + ', true, \'' + pHash + '\');');
	}
	
}

/**
 * 
 * @param {boolean} pMode 
 * true: to show all the content elements
 * false: to hide all the content elements
 * 
 * @param {integer} pCount
 * number of content elements 
 * 
 * @param {string} pHash
 * prefix of the id
 * 
 */
function toggleContentElements(pMode, pCount, pHash){
	//loop through all the elements
	for (i = 1; i <= pCount; i++){
		//now switch the visible state of the concerned elements
		if (pMode){
			document.getElementById(pHash + 'id' + i.toString()).style.display = 'block';
		}else{
			document.getElementById(pHash + 'id' + i.toString()).style.display = 'none';
		}
	}
}
function SetEmptyAreaShapes() {
	var _arrMaps = document.getElementsByTagName('map');
	//loop throught all the maps
	for (var i = 0; i < _arrMaps.length; i++){
		//get the areas of the current map
		var _arrAreas = _arrMaps[i];
		//loop throught all the areas
		for (var j=0; j<_arrAreas.areas.length;j++){
			var _oArea = _arrAreas.areas[j];
			//check if the href attribut of the area has been set
			if(navigator.appName.indexOf('Microsoft') > -1){
		    	/* IE */
				var _href = _oArea.getAttributeNode('href').nodeValue;
		    } else {
		    	/* FF */
				var _href = _oArea.getAttribute('href');
		    }
			if (_href.search('id')==-1){
				_oArea.removeAttribute('href');
				_oArea.style.cursor = 'default';
			}
		}
	}
 }