/* Static variables */

//var avoidElements = new Array('head','foot'); // <- example
var avoidElements = new Array();

/* End static variables */



/* Standard framework function to give mCCWrapper the remaining window height if avoidElements is defined */

function autosize_mCCWrapper()
{
	try 
	{ 
		var offsetHeight = 0;
		var windowHeight = window.getSize().y;
		Array.each(avoidElements,function(el,i)
		{
			offsetHeight += $(el).getSize().y;
		});
		var totalElementHeight = offsetHeight + $('mCC').getSize().y;
		if(totalElementHeight < windowHeight)
		{
			var newHeight = windowHeight - offsetHeight;
			$('mCCWrapper').setStyle('height', newHeight+'px');
		}
	} 
	catch (e){ }
}

/* Standard framework function to maximize mCCWrapper to full window height and centering mCC horizontaly within it. */

function center_center(CC,C)
{
	try 
	{
		var objType = 'element';
		if(typeOf($('head'))==objType) $('head').setStyle('display','none');
		if(typeOf($('foot'))==objType) $('foot').setStyle('display','none');
		if(typeOf(CC)==objType && typeOf(C)==objType)
		{
			var windowHeight = window.getSize().y;
			var space = (windowHeight-C.getSize().y)/2;
			var newHeight = windowHeight - space;
			CC.setStyle('padding-top',space+'px');
			CC.setStyle('height',newHeight+'px');
		}
	} 
	catch (e){ }
}

/* Standard framework function to mark left and right sibling */

function markSiblings()
{
	try 
	{
		// find all lists with .mark_siblings class
		Array.each($$('.mark_siblings'),function(list,i){
			// find all li's
			lis = list.getChildren('li');
			// set false index
			var active_index = false;
			// Loop lis
			Array.each(lis,function(li,j){
				// find active li
				if(li.hasClass('active'))
					active_index = j;	
			});
			// if index is set
			if(active_index !== false)
			{
				// set left sibling style
				if(active_index > 0)
					lis[(active_index-1)].addClass('left_sibling');
				// set right sibling style
				if(active_index < lis.length)
					lis[(active_index+1)].addClass('right_sibling');
			}			
		});
	}
	catch (e){ }
}

/* Standard framework function to make columns with same classname the same height as the highest one */

function makeSameHeight(elements)
{
	try 
	{
		var heighest = 0;
		Array.each(elements,function(el,i)
		{
			heighest = (el.getSize().y>heighest ? el.getSize().y : heighest);
		});
		Array.each(elements,function(el,i)
		{
			el.setStyle('height',heighest+'px');
		});
	}
	catch (e) {}
}

/* [Beta] Function to give style .last on last li-element in all uls  */

function markLastLis()
{
	try 
	{
		var uls = $$('ul,ol');
		Array.each(uls,function(el,i)
		{
			lis = el.getChildren('li');
			lis[lis.length-1].addClass('last');	
		});
	}
	catch(e){}
}


/* [Beta] Function to center element within its parent */

function centerElement(el)
{
	try
	{
		var parent = el.getParent('div');
		var width = el.getSize().x;
		var widthParent = parent.getSize().x;
		var padding = Math.floor((widthParent - width) / 2);
		var newWidthParent = widthParent - (padding*2);
		el.setStyles(
		{
			'width':width+'px'
		});	
		parent.setStyles(
		{
			'padding-left':padding+'px',
			'padding-right':padding+'px',
			'width': newWidthParent+'px'
		});
	}
	catch(e){}
}

/* Mootools 1.2 legacy function - to support deprecated $chk() */

var $chk = function(obj){
	return !!(obj || obj === 0);
};


/* [Beta] Custom function to make min-height functionality work in all browsers (kind of) */

function myMinHeight(elements,minheight)
{
	try
	{
		Array.each(elements,function(el,i){
			if(el.getSize().y < minheight)
				el.setStyle('height',minheight+'px');
			else
				el.setStyle('height',el.getSize().y+'px');
		});
	} catch (e){}
}

