﻿// Pass true or false to show or hide the given element
function SS_ShowElement(Element, State){
	Element=SS_GetElement(Element);
	if (Element.style!=null){
		if (State){
	    	Element.style.visibility="visible";
		} else {
	    	Element.style.visibility="hidden";
		}
	}
}


// Toggles an element as visible/hidden
function SS_ToggleElement(Element){
	Element=SS_GetElement(Element);
	if (Element!=null){
		SS_ShowElement(Element, Element.style.visibility=="hidden");
	}
}


// Either show or hide the element based on if there is content within it
function SS_ShowElementOnContent(Element){
	Element=SS_GetElement(Element);
	if (Element!=null){
		SS_ShowElement(Element, Element.innerHTML.length>0);
	}
}


// Return the absolute left of the given element
function SS_GetElementX(Element){
	var CurrX=0;
	Element=SS_GetElement(Element);
	if (Element!=null){
		CurrX+=Element.offsetLeft;
		while (Element.offsetParent!=null){
			Element=Element.offsetParent;
			CurrX+=Element.offsetLeft;
		}
	}
	return CurrX;
}


// Return the absolute top of the given element
function SS_GetElementY(Element){
	var CurrY=0;
	Element=SS_GetElement(Element);
	if (Element!=null){
		CurrY+=Element.offsetTop;
		while (Element.offsetParent!=null){
			Element=Element.offsetParent;
			CurrY+=Element.offsetTop;
		}
	}
	return CurrY;
}


// Return the width of the given element
function SS_GetElementW(Element){
	Element=SS_GetElement(Element);
	if (Element!=null){
		return Element.offsetWidth;
	}
	return 0;
}


// Return the height of the given element
function SS_GetElementH(Element){
	Element=SS_GetElement(Element);
	if (Element!=null){
		return Element.offsetHeight;
	}
	return 0;
}


// Return the opacity of the given element between 0-100
// Return 100 if undefined
function SS_GetElementOpacity(Element){
	Element=SS_GetElement(Element);
	if (Element!=null){
		if (Element.style.opacity!="" && Element.style.opacity!=null){
			return parseInt(Element.style.opacity*100);
		}
	}
	return 100;
}


// Set the left of the given element in relation to it's containing element
function SS_SetElementX(Element, X){
	Element=SS_GetElement(Element);
	if (Element.style!=null){
		Element.style.left=X+"px";
	}
}



// Set the top of the given element in relation to it's containing element
function SS_SetElementY(Element, Y){
	Element=SS_GetElement(Element);
	if (Element.style!=null){
		Element.style.top=Y+"px";
	}
}



// Set the width of the given element
function SS_SetElementW(Element, W){
	Element=SS_GetElement(Element);
	if (Element.style!=null){
		Element.style.width=W+"px";
	}
}


// Set the height of the given element
function SS_SetElementH(Element, H){
	Element=SS_GetElement(Element);
	if (Element.style!=null){
		Element.style.height=H+"px";
	}
}


// Set the opacity of the given element between 0-100
function SS_SetElementOpacity(Element, Opacity){
	Element=SS_GetElement(Element);
	if (Element.style!=null){
		SS_SetElementW(Element, SS_GetElementW(Element)); // IE requires a width for setting opacity
    	Element.style.visibility=(Opacity==0?"hidden":"visible");
	    Element.style.filter="alpha(opacity="+Opacity+")";
		Element.style.MozOpacity=Opacity/100;
		Element.style.KhtmlOpacity=Opacity/100;
		Element.style.opacity=Opacity/100;
	}
}


// Set the x, y of the given element
function SS_SetElementPosition(Element, X, Y){
	SS_SetElementX(Element, X);
	SS_SetElementY(Element, Y);
}



// Set the w, h of the given element
function SS_SetElementSize(Element, W, H){
	SS_SetElementW(Element, W);
	SS_SetElementH(Element, H);
}
