function showBox(){
    $('showbox_overlay').show();
	overlayReload();
    center('box');
	
	//scroll to top, to fix height:100% bug with overlay (edit: no longer the best solution for that bug)
	//scroll(0,0);
	
    return false;
}

function hideBox(){
	 if ( typeof ( thecolorpicker ) == "object" )
	 {
		 thecolorpicker.close();
		 thecolorpicker = 0;
	 }
    $('box').hide();
    $('showbox_overlay').hide();
	
	//custom addition to close the epoch style
	if (document.getElementById('cal_calendar'))	{
		popupcalendar.hide();	
	}
	
    return false;
}

function clearBox(){
    $('box').innerHTML = "";
   return hideBox();
}

function center(element){
    try{
        element = $(element);
    }catch(e){
        return;
    }

    var my_width  = 0;
    var my_height = 0;

    if ( typeof( window.innerWidth ) == 'number' ){
        my_width  = window.innerWidth;
        my_height = window.innerHeight;
    }else if ( document.documentElement && 
             ( document.documentElement.clientWidth ||
               document.documentElement.clientHeight ) ){
        my_width  = document.documentElement.clientWidth;
        my_height = document.documentElement.clientHeight;
    }
    else if ( document.body && 
            ( document.body.clientWidth || document.body.clientHeight ) ){
        my_width  = document.body.clientWidth;
		//my_width  = document.body.scrollWidth;
		my_height = document.body.clientHeight;
    }

    element.style.position = 'absolute';
    element.style.zIndex   = 99;

    var scrollY = 0;

    if ( document.documentElement && document.documentElement.scrollTop ){
        scrollY = document.documentElement.scrollTop;
    }else if ( document.body && document.body.scrollTop ){
        scrollY = document.body.scrollTop;
    }else if ( window.pageYOffset ){
        scrollY = window.pageYOffset;
    }else if ( window.scrollY ){
        scrollY = window.scrollY;
    }

    var elementDimensions = Element.getDimensions(element);

    //var setX = ( my_width  - elementDimensions.width  ) / 2;
	//var setX = 0;
	//alert(document.body.scrollWidth);
	var setX = ( document.body.scrollWidth / 2) - (elementDimensions.width / 2);
    //var setY = ( my_height - elementDimensions.height ) / 2 + scrollY;
    var setY = scrollY + 20;
	//var setY = 100;
	//var setY = 100;
    
	setX = ( setX < 0 ) ? 0 : setX;
    setY = ( setY < 0 ) ? 0 : setY;

    element.style.left = setX + "px";
    element.style.top  = setY + "px";

    element.style.display  = 'block';
}

function overlayReload()
{
    if (window.innerHeight && window.scrollMaxY || window.innerWidth && window.scrollMaxX) {    
        yScroll = window.innerHeight + window.scrollMaxY;
        xScroll = window.innerWidth + window.scrollMaxX;
        var deff = document.documentElement;
        var wff = (deff&&deff.clientWidth) || document.body.clientWidth || window.innerWidth || self.innerWidth;
        var hff = (deff&&deff.clientHeight) || document.body.clientHeight || window.innerHeight || self.innerHeight;
        xScroll -= (window.innerWidth - wff);
        yScroll -= (window.innerHeight - hff);
    } else if (document.body.scrollHeight > document.body.offsetHeight || document.body.scrollWidth > document.body.offsetWidth){ // all but Explorer Mac
        yScroll = document.body.scrollHeight;
        xScroll = document.body.scrollWidth;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        yScroll = document.body.offsetHeight;
        xScroll = document.body.offsetWidth;
      }

    $('showbox_overlay').style.height = yScroll;
    $('showbox_overlay').style.width = xScroll;
}