/**
* Stretch the given elements to the highest elements hight.
*/
function stretch(e_col, pix_correction, subtract){
	col_long = 0;
	
	for(i=0; i < e_col.length; i++){
		if(e_col[i] !== 'false'){
			col_height = e_col[i].offsetHeight;
			col_long = (col_height > col_long) ? col_height : col_long;
		}
	}
	for(k=0; k < e_col.length; k++){
		if(e_col[k] !== 'false'){
			
			if(subtract){
				e_col[k].style.height = (col_long - pix_correction) + 'px';
			}
			else{
				e_col[k].style.height = (col_long + pix_correction) + 'px';
			}
		}
	}
}

/**
* Get the elements to stretch
*/
function getStretchElements(elements, tag, tag_class){
	
	var stretch = new Array();
	
	for(i=0; i < elements.length; i++){
		element = (document.getElementById(elements[i])) ? document.getElementById(elements[i]) : 'false';
		
		if(element !== 'false'){
		
			if(tag !== null && tag[i]){
				
				tag_element = (element.getElementsByTagName(tag[i])) ? element.getElementsByTagName(tag[i]) : 'false';
				
				if(tag_element !== 'false'){
					
					if(tag_class !== null && tag_class[i]){
						
						var searched_tags = new Array();
						
						for(k=0; k < tag_element.length; k++){
							
							if(tag_element[k].className && tag_element[k].className.match(tag_class[i])){
								
								searched_tags[searched_tags.length] = tag_element[k];
							}
						}
						
						if(searched_tags.length > 0){
							stretch[stretch.length] = searched_tags[0];
						}
					}
					else{
						stretch[stretch.length] = tag_element[0];
					}
				}
			}
			else {
				stretch[stretch.length] = element;
			}
		}
	}
	
	return stretch;
}

window.onload = function(){
	
	//DO THE COLUMN STRETCHING (textPage, newsPage and memberPage)
	
	if(!document.getElementById('imagePaletteModule')){
	
		if(document.getElementById('leftMenuContentColumn')){
			container_elements = new Array('leftMenuContentColumn', 'middleContentColumn', 'rightContentColumn');
			c_elements = getStretchElements(container_elements, null, null);
			stretch(c_elements, 0, false);
		}
	}
	
	
	//STRETCH MAIN MENU ACTIVE BAR
	
	//if we can find the main menu active item
	if(document.getElementById('mainMenuActiveItem')){
		//get it
		activeItem = document.getElementById('mainMenuActiveItem');
		//if we can find the active bar
		if(document.getElementById('activeBar')){
			
			//set the active bar width to the active item width (subtract 8px for padding, border etc.)
			activeMenuBar = document.getElementById('activeBar');
			activeMenuBar.style.width = (activeItem.offsetWidth - 8) + 'px';
		}
	}
	
	//IMAGE PALETTE
	
	//if we have a image palette
	if(document.getElementById('imagePaletteModule')){
		//create a image palette object
		imagePalette = new imagePalette();
		//init the image plaette (get number of images, rows pages etc.)
		imagePalette.init();
	}
	
	//ALPHABETIC MEMBERS LIST (KOOPERATIONEN SPECIFIC)
	
	//if we have a image palette
	if(document.getElementById('alphabeticSortingListModule')){
		//create a alphabetic sorting object
		alphaSorter = new alphabeticSorter();
	}
}