
/*
    jako konstruktor przekazujemy tylko obiekt jquery który zawiera w sobie warstę
    potem będzie ona odsłaniana i ukrywana tak żęby znajdowała się zawsze na środeczku ekraniu
*/


function warstwa(obiekt, color, opacity) {
    
    this.obiekt      = obiekt;
    this.background  = null;
                                        //flaga informująca o tym w jakim stanie znajduje się warstwa
    this.show_window = false;
    
	this.background = document.createElement('div');
	document.body.appendChild(this.background);
    
    this.background = jQuery(this.background);
    
    
    this.background.css('display'          , 'block');
    this.background.css('visibility'       , 'hidden');
    this.background.css('position'         , 'absolute');
    this.background.css('width'            , '100%');
    this.background.css('height'           , '100%');
    this.background.css('top'              , '0');
    
    
                                                                //ustawienie koloru jeśli podano
    if (typeof(color) === 'undefined') {
        
        this.background.css('background-color' , 'black');
        }
    else {
        this.background.css('background-color' , color);
        }
    
    
                                                                //ustawienie przeźroczystości domyślnie brak
    if (typeof(opacity) === 'undefined') {
        
        this.background.css('opacity'          , '0');
        this.background.css('filter'           , 'alpha (opacity=0)');
        /*
        this.background.css('opacity'          , '0.7');
        this.background.css('filter'           , 'alpha (opacity=70)');
        */
        }
    
    else {
        this.background.css('opacity'          , parseInt(opacity) / 100);
        this.background.css('filter'           , 'alpha (opacity=' + opacity  + ')');
        }
    
    
    this.obiekt.css('position'  , 'absolute');
    this.obiekt.css('visibility', 'hidden');
    this.obiekt.css('display'   , 'block');
    this.obiekt.css('z-index'   , '10000');
    };


//.................................................................................................


warstwa.prototype.show = function() {
    
                                                //wycentrowanie warstwy
    this.repositionElement();

    this.obiekt.show();
    
    
    this.obiekt.css    ('visibility', 'visible');
    this.background.css('visibility', 'visible');
    
    this.show_window = true;
    };


//.................................................................................................


warstwa.prototype.hide = function() {    
    
    this.background.css('visibility', 'hidden');
    this.obiekt.css    ('visibility', 'hidden');
    
    this.show_window = false;
    };


//.................................................................................................


warstwa.prototype.repositionElement = function() {
    
    var layer = this.obiekt.get(0);
    
    
    var frameWidth  = getWindowWidth();
    var frameHeight = getWindowHeight();
    
    
    var all_width  = null;
    var all_height = null;
    
    if (document.documentElement && document.documentElement.clientWidth) {
        
        all_width  = document.documentElement.clientWidth;
        all_height = document.documentElement.clientHeight;
        }
    
    else if (document.body) {
        
        all_width  = document.body.clientWidth;
        all_height = document.body.clientHeight;
        }
    
    this.background.width(all_width);
    this.background.height(all_height);
    
    
    var y = getScrollY();
    
    layer.style.left =     (frameWidth  - layer.offsetWidth ) / 2 + 'px';
    layer.style.top  = y + (frameHeight - layer.offsetHeight) / 2 + 'px';
    };


//.................................................................................................


// Wysokość zawartości całego okna
window.getContentHeight = function()
{
	if (document.documentElement && document.documentElement.scrollHeight)
		return document.documentElement.scrollHeight;
	else if (document.body && document.body.scrollHeight)
		return document.body.scrollHeight;
	return false;
}

// Szerokość zawartości całego okna
window.getContentWidth = function()
{
	if (document.documentElement && document.documentElement.scrollWidth)
		return document.documentElement.scrollWidth;
	else if (document.body && document.body.scrollWidth)
		return document.body.scrollWidth;
	return false;
}

// Wysokość okna przeglądarki
window.getWindowHeight = function()
{
	if (window.innerHeight)
		return window.innerHeight;
	else if(document.documentElement && document.documentElement.clientHeight)
		return document.documentElement.clientHeight;
	else if (document.body && document.body.clientHeight)
		return document.body.clientHeight;
	else if(document.body && document.body.scrollHeight)
		return document.body.scrollHeight;
	return false;
}

// Szerokość okna przeglądarki
window.getWindowWidth = function()
{
	if (window.innerWidth)
		return window.innerWidth;
	else if(document.documentElement && document.documentElement.clientWidth)
		return document.documentElement.clientWidth;
	else if (document.body && document.body.clientWidth)
		return document.body.clientWidth;
	else if(document.body && document.body.scrollWidth)
		return document.body.scrollWidth;
	return false;
}

// pobiera położenie scrolla poziomego
window.getScrollX = function()
{
	if(document.documentElement && document.documentElement.scrollLeft)
		return document.documentElement.scrollLeft;
	else if(document.body && document.body.scrollLeft)
		return document.body.scrollLeft;
	else if( window.pageXOffset )
		return window.pageXOffset;
	else if( window.scrollX )
		return window.scrollX;
	return 0;
}

// pobiera położenie scrolla pionowego
window.getScrollY = function()
{
	if(document.documentElement && document.documentElement.scrollTop)
		return document.documentElement.scrollTop;
	else if(document.body && document.body.scrollTop)
		return document.body.scrollTop;
	else if( window.pageYOffset )
		return window.pageYOffset;
	else if( window.scrollY )
		return window.scrollY;
	return 0;
}

// zwraca wysokość obiektu el
window.getObjectHeight = function(el)
{
	if (!el) return false;
	if (el.style && el.style.height)
		return el.style.height;
	else if (el.offsetHeight)
		return el.offsetHeight;
	return 0;
}

// zwraca szerokość obiektu el
window.getObjectWidth = function(el)
{
	if (!el) return false;
	if (el.style && el.style.width)
		return el.style.width;
	else if (el.offsetWidth)
		return el.offsetWidth;
	return 0;
}

// pobiera pozycje x,y  - wskaznika myszy
window.getMouseXY = function(e)
{
	res = new Array();
	IE = new RegExp('Internet Explorer$').test(navigator.appName)?true:false;
	if (IE)
	{
		res[0] = event.clientX + document.documentElement.scrollLeft;
		res[1] = event.clientY + document.documentElement.scrollTop;
	}
	else
	{
		res[0] = e.pageX;
		res[1] = e.pageY;
	}
	if (res[0] < 0){res[0] = 0;}
	if (res[1] < 0){res[1] = 0;}
	res['height'] = res[1];
	res['width'] = res[0];
	return res;
}


