// JavaScript Document

var thisElement;

function showBox(element){
	thisElement = element;
	Element.hide($(thisElement));
	center(thisElement);
	return false;
}

function hideBox(){
    $(thisElement).hide();
	$('overlay').className = "hide";
	window.onresize = "";
	window.onscroll = "";
    return false;
}

/*function initBox (element){
	center(element);
	
}*/

function center(element, r){

  try{
        element = $(element);
    }catch(e){
        return;
    }
	

    element.style.position = 'absolute';
	element.style.zIndex   = 1000;


    var elementDimensions = Element.getDimensions(element);
	var browserHeight = getHeight();
	var browserWidth = getWidth();
	var browserScroll = getYScroll();
	var browserXScroll = getXScroll();

    var setX = ( browserWidth  - elementDimensions.width  ) / 2;
    var setY = ( browserHeight - elementDimensions.height ) / 2 +  browserScroll;

    setX = ( setX < 0 ) ? 0 : setX;
    setY = ( setY < 0 ) ? 0 : setY;

		if( element.className == 'boutiqueMap')
		{
			element.style.left = (setX + 165) + "px";
			element.style.top  = 179 + "px";
		}
		else
		{
			element.style.left = setX + "px";
			element.style.top  = setY + "px";
		}

			

	
	
	if (r){
			//alert(r);
			//Element.hide(element);
			//new Effect.Appear(element, {duration: .4});
			
		new Effect.Appear($('overlay'));
			$('overlay').style.height = browserHeight  + "px";
			}
		else{
			//$('overlay').style.height = browserHeight  + "px";
			$('overlay').style.height = browserHeight + browserScroll  + "px";
			$('overlay').style.width = browserWidth  + browserXScroll + "px";
			$('overlay').className = "show";
			}
	
	new Effect.Appear(element, {duration: .4});
	
	
	window.onresize = resizeThis;
	window.onscroll = scrollThis;
    //element.style.display  = 'block';
	
	/*if (window.scroll){alert('scroll');}
	alert(my_width);
	alert(my_height);*/
}

function getYScroll(){
	
    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;
    }
	return scrollY;

}

function getXScroll(){
	
    var scrollX = 0;

    if ( document.documentElement &&document.documentElement.scrollLeft ){
        scrollX = document.documentElement.scrollLeft;
    }else if ( document.body &&document.body.scrollLeft ){
        scrollX = document.body.scrollLeft;
    }else if ( window.pageXOffset ){
        scrollX = window.pageXOffset;
    }else if ( window.scrollX ){
        scrollX = window.scrollX;
    }
	return scrollX;

}

function getWidth(){
	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_height = document.body.clientHeight;
    }
	return my_width;
	
}

function getHeight(){
	//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_height = document.body.clientHeight;
    }
	return my_height;
	
}

function resizeThis(e){
	if (!e) e = window.event;
	var r = "resize";
	//Effect.Fade(thisElement, {duration: .1});
	center(thisElement, r);
	return true;
	
}

function scrollThis(e){
	if (!e) e = window.event;
	var elementDimensions = Element.getDimensions($('overlay'));
	var browserHeight = getHeight();
	var browserWidth = getWidth();
	var browserScroll = getYScroll();
    var setHeight =	(browserHeight + browserScroll);
	$('overlay').style.height = setHeight + "px";
	
}