//////////////////////////////////////////////////////////////////
// styles functions

// get element style value
function FWxGetStyle(Element, Name)
{
	// if style is in style array we can use it
	if(Element.style[Name])
		return Element.style[Name];
		
	// try IE method
	else if(Element.currentStyle)
		return Element.currentStyle[Name];
	
	// W3C method
	else if(document.defaultView && document.defaultView.getComputedStyle)
	{
		Name = Name.replace(/([A-Z])/g,"-$1");
		Name = Name.toLowerCase();
		
		var s = document.defaultView.getComputedStyle(Element, "");
		return s && s.getPropertyValue(Name);
	}
	else
		return null;
}

// get X offset in whole document
function FWxGetXInDocument(Element)
{
	// are we in root node?
	return Element.offsetParent ?
		Element.offsetLeft + FWxGetXInDocument(Element.offsetParent) :
		Element.offsetLeft;
}

// get Y offset in whole document
function FWxGetYInDocument(Element)
{
	return Element.offsetParent ?
		Element.offsetTop + FWxGetYInDocument(Element.offsetParent) :
		Element.offsetTop;
}

// get x offset in parent
function FWxGetXInParent(Element)
{
	return Element.parentNode == Element.offsetParent ? 
		Element.offsetLeft :
		FWxGetXInDocument(Element) - FWxGetXInDocument(Element.parentNode);
}

// get Y offset in parent
function FWxGetYInParent(Element)
{
	return Element.parentNode == Element.offsetParent ?
		Element.offsetTop :
		FWxGetYInDocument(Element) - FWxGetYInDocument(Element.parentNode);
}

// get X offset in CSS
function FWxGetXInCSS(Element)
{
	return parseInt(FWxGetStyle(Element, "left"));
}

// get Y offset in CSS
function FWxGetYInCSS(Element)
{
	return parseInt(FWxGetStyle(Element, "top"));
}

// set X offset 
function FWxSetX(Element, Val)
{
	Element.style.left = Val + "px";
}

// set Y offset
function FWxSetY(Element, Val)
{
	Element.style.top = Val + "px";
}

// add X offset to the actual X offset
function FWxAddX(Element, Val)
{
	FWxSetX(FWxGetXInCSS(Element) + Val);
}

// add Y offset to the actual Y affset
function FWxAddY(Element, Val)
{
	FWxSetY(FWxGetYInCSS(Element) + Val);
}

// get height of element
function FWxGetHeight(Element)
{
	return parseInt(FWxGetStyle(Element, "height"));
}

function FWxSetHeight(Element, h)
{
	Element.style.height = h + "px";
}

// get width of element
function FWxGetWidth(Element)
{
	return parseInt(FWxGetStyle(Element, "width"));
}

function FWxSetWidth(Element, w)
{
	Element.style.width = w + "px";
}

// get maximal height
function FWxGetMaxHeight(Element)
{
	// if element is visible we use offsetHeight atribut of function GetStyle()
	if(FWxGetStyle(Element, 'display') != 'none')
		return Element.offsetHeight || FWxGetHeight(Element);
		
	// we must repair display style
	var old = FWxResetCSS(Element, {
						  display: '',
						  visibility: 'hidden',
						  position: 'absolute'
						  });

	var v = Element.clientHeight || FWxGetHeight(Element);
	
	FWxRepairCSS(Element, old);
	
	return v;
}

// get maximal width
function FWxGetMaxWidth(Element)
{
	if(FWxGetStyle(Element, 'display') != 'none')
		return Element.offsetWidth || FWxGetWidth(Element);
		
	var old = FWxResetCSS(Element, {
						  display: '',
						  visibility: 'hidden',
						  position: 'absolute'
						  });
	
	var s = Element.clientWidth || FWxGetWidth(Element);
	
	FWxRepairCSS(Element, old);
	
	return s;
}

// set CSS style and return old style settings
function FWxResetCSS(Element, set)
{
	var old = {};
	
	for(var i in set)
	{
		old[i] = Element.style[i];
		Element.style[i] = set[i];
	}
	
	return old;
}

// repair CSS style
function FWxRepairCSS(Element, set)
{
	for(var i in set)
		Element.style[i] = set[i];
}

// make element hidden
function FWxHidde(Element)
{
	var ActualDisplay = FWxGetStyle(Element, 'display');
	
	if(ActualDisplay != 'none')
		Element.$OldDisplay = ActualDisplay;
		
	Element.style.display = 'none';
}

// make element visibility
function FWxVisible(Element)
{
	Element.style.display = Element.$OldDisplay || '';
}

// set opacity
function FWxSetOpacity(Element, level)
{
	Element.style.opacity = level / 100;
	Element.style.filter = 'alpha(opacity=' + level +')';
}

// unroll element
function FWxUnroll(Element)
{
	Element.style.height = '0px';
	
	FWxVisible(Element);
	
	var v = FWxGetMaxHeight(Element);
	
	for(var i = 0; i <= 100; i += 5)
	{
		(function(){
				  var poz = i;
				  
				  setTimeOut(function(){
									  Element.style.height = ((poz / 100) * v ) + 'px';
									  }, (poz + 1) * 10);
				  })();
	}
}

//fadein element
function FWxFadeIn(Element)
{
	FWxSetOpacity(Element, 0);
	
	FWxVisible(Element);
	
	for(var i = 0; i <= 100; i += 5)
	{
		(function(){
				  var poz = i;
				  
				  setTimeOut(function(){
									  FWxSetOpacity(Element, poz);
									  }, (poz + 1) * 10);
				  })();
	}
}

// get mouse X offset in whole document 
function FWxGetMouseXInDocument(e)
{
	e= e || window.event;
	
	return e.pageX || e.clientX + document.body.scrollLeft;
}

// get mouse Y offset in whole document
function FWxGetMouseYInDocument(e)
{
	e = e || window.event;
	
	return e.pageY || e.clientY + document.body.scrollTop;
}

// get mouse X offset in parent
function FWxGetMouseXInParent(e)
{
	return (e && e.layerX) || window.event.offsetX;
}

// get mouse Y offset in parent
function FWxGetMouseYInParent(e)
{
	return (e && e.layerY) || window.event.offsetY;
}

// get page height
function FWxGetPageHeight()
{
	return document.body.scrollHeight;
}

// get page width
function FWxGetPageWidth()
{
	return document.body.scrollWidth;
}

// get page scroll offset X
function FWxGetPageScrollX()
{
	var de = document.documentElement;
	
	return self.pageXOffset || (de && de.scrollLeft) || document.body.scrollLeft;
}

// get page scroll offset Y
function FWxGetPageScrollY()
{
	var de = document.documentElement;
	
	return self.pageYOffset || (de && de.scrollTop) || document.body.scrollTop;
}

// get viewport height
function FWxGetViewportHeight()
{
	var de = document.documentElement;
	
	return self.innerHeight || (de && de.clientHeight) || document.body.clientHeight; 
}

// get viewport width
function FWxGetViewportWidth()
{
	var de = document.documentElement;
	
	return self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
}