function correctLayoutHeight()
{
	var Layout			= document.getElementById('Layout');
	var ContentPusher	= document.getElementById('ContentPusher');
	if (!Layout || !ContentPusher) return false;

	var push_content	= Math.max(document.body.offsetHeight - Layout.offsetHeight, 0);
	if (!push_content) return true;
	ContentPusher.style.height	= ContentPusher.offsetHeight+push_content+'px';
	return true;
}

function correctWheelTrack()
{
	var ContentContainer	= document.getElementById('Content-container');
	var LeftTopGround		= document.getElementById('LeftTopGround');
	var LeftBottomGround	= document.getElementById('LeftBottomGround');
	var RightBottomGround	= document.getElementById('RightBottomGround');
	var ContentPusher		= document.getElementById('ContentPusher');
	if (!ContentContainer || !LeftTopGround || !LeftBottomGround || !RightBottomGround || !ContentPusher) return false;

	var wheel_tile_height	= 5;
	var push_content_height	= wheel_tile_height - (ContentContainer.offsetHeight - LeftTopGround.offsetHeight - LeftBottomGround.offsetHeight) % wheel_tile_height;
	if (push_content_height == 5) return correctBottomGround(ContentContainer, LeftBottomGround, RightBottomGround);

	ContentPusher.style.height	= ContentPusher.offsetHeight-(5-push_content_height)+'px';
	
	return correctBottomGround(ContentContainer, LeftBottomGround, RightBottomGround);

}

function correctBottomGround(ContentContainer, LeftBottomGround, RightBottomGround)
{
	if (ContentContainer.offsetHeight % 2 ==1)
	{
		LeftBottomGround.style.bottom	='-1px';
		RightBottomGround.style.bottom	='-1px';
	}

	return true;
}



function pushContentUnderContextMenu()
{
	var ContextMenuItems	= document.getElementById('ContextMenuItems');
	var Content				= document.getElementById('Content');
	var PageCaption			= document.getElementById('PageCaption');
	
	if (!ContextMenuItems || !Content || !PageCaption) return false;
	var push_page_caption	= (getAbsoluteRight(PageCaption) < getAbsoluteLeft(ContextMenuItems))? parseInt(getStyle(PageCaption, 'padding-bottom'))-PageCaption.offsetHeight : 0;
	var menu_push_out	= Math.max(getAbsoluteBottom(ContextMenuItems)-getAbsoluteTop(Content)+push_page_caption, 0);
	var content_margin_top = parseInt(getStyle(Content, 'margin-top'));
	if (menu_push_out) Content.style.marginTop	= content_margin_top+menu_push_out+'px';
}

function optimizeContextMenuSizes()
{
	
	var ContextMenuItems	= document.getElementById('ContextMenuItems');
	var ServicesMenu		= document.getElementById('ServicesMenu');
	if (!ContextMenuItems || !ServicesMenu) return false;
	var max_width		= getAbsoluteRight(ContextMenuItems) - getAbsoluteRight(ServicesMenu);
	if (ContextMenuItems.offsetWidth <= max_width) return;
	
	var paddings		= parseInt(getStyle(ContextMenuItems, 'padding-left'))+parseInt(getStyle(ContextMenuItems, 'padding-right'));
	var width			= ContextMenuItems.offsetWidth-paddings;
	ContextMenuItems.style.width = width+'px';
}


function getStyle(Node, style_prop)
{
	if (!Node) return false;
	if (Node.currentStyle) //IE
	{
		var ie_prop_name	= style_prop.replace(/-(.)/g, function (str0, str1) {return str1.toUpperCase();});
		var property 		= Node.currentStyle[ie_prop_name];
	}
	else if (window.getComputedStyle) 	var  property = document.defaultView.getComputedStyle(Node,null).getPropertyValue(style_prop);
	return property;
}


/* Status bar functions */
var status_bar_out_time		= false;
var status_bar_wait_time 	= 1*2000; /* wait before menu hiding milliseconds */


function showStatusBar()
{
	var StatusBar			= document.getElementById('StatusBar');
	if (!StatusBar) return false;
	
	status_bar_out_time		= false;
	if (StatusBar.style.display == 'block') return false; //already visible
	
	//Show bar
	StatusBar.style.display = 'block';
	progressOpacity('StatusBar', 340, 5);
}


function statusBarMouseOut()
{
	showStatusBar();
	status_bar_out_time = new Date();
	setTimeout("statusBarBeforeHide()", status_bar_wait_time+10);
}


function statusBarBeforeHide()
{
	if (!status_bar_out_time) return false;	//No need to hide
	var now	= new Date();
	if (status_bar_out_time.getTime() + status_bar_wait_time > now.getTime()) return false;
	hideStatusBar();
}


function hideStatusBar()
{
	var StatusBar	= document.getElementById('StatusBar');
	if (!StatusBar) return false;
	StatusBar.style.display = 'none';
}

function progressOpacity(nodeid, time, steps)
{
	stepOpacity(nodeid, time, 0, steps);
}

function stepOpacity(id, time, step, steps)
{
	var node	= document.getElementById(id);
	if (!id) return false;
	var opacity	= step*100/steps;
	setOpacity(node, opacity);
	if (step > steps) return;
	step++;
	setTimeout('stepOpacity("'+id+'", "'+time+'", "'+step+'", "'+steps+'")', time/steps);
	
}

function setOpacity(node, value)
{
	if (!node) return false;
	//IE
	try {node.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=\'" + value + "\')";} catch(e) {;}
	//FF and other
	try {node.style.opacity = value / 100; } catch(e) {;}
}



function getAbsoluteLeft(Element)
{
	if (!Element) return false;
	var left	= 0;
	var oParent	= Element;
	do {left+= oParent.offsetLeft;} while (oParent = oParent.offsetParent);
	if (navigator.userAgent.indexOf('Mac') != -1 && typeof document.body.leftMargin != 'undefined') left += document.body.leftMargin;
	
	return left;
}


function getAbsoluteTop(Element)
{
	if (!Element) return false;
	var top	= 0;
	var oParent	= Element;
	do {top+= oParent.offsetTop;} while (oParent = oParent.offsetParent);
	if (navigator.userAgent.indexOf('Mac') != -1 && typeof document.body.topMargin != 'undefined') top += document.body.topMargin;
	
	return top;
}

function getAbsoluteBottom(Element)
{
	if (!Element) return false;
	return getAbsoluteTop(Element)+Element.offsetHeight;
}


function getAbsoluteRight(Element)
{
	if (!Element) return false;
	return getAbsoluteLeft(Element)+Element.offsetWidth;
}

