/************************* PROFIL ***********************/
function profil(variable)
{
	advAJAX.get({
        url: baseHr+"ajax.php?action=profil&var=" + variable,
        onSuccess : function(obj) {
			pokazProfil( obj.responseText );
        }
    });
}

function pokazProfil( htmlSource ) {
	if (!$("profil_overlay")) {
        new Element('div').setProperty('id', 'profil_overlay').injectInside(document.body);
        $('profil_overlay').setOpacity(0);
        $("profil_overlay").setStyles({
			"height": '0px',
			"width": '0px'
		});
		$("profil_overlay").setStyles({
			"height": window.getScrollHeight() + 'px',
			"width": window.getScrollWidth() + 'px'
		});
        
        $('profil_overlay').set('tween', {
            duration: 400
        });
        $('profil_overlay').tween('opacity', 0, 0.6);
        
    }
	
	if (!$("profil")) {
        new Element('div').setProperty('id', 'profil').injectInside(document.body);
        $('profil').setOpacity(0);
    }
    
    $("profil_overlay").onclick = profilClose;
    
    window.onscroll = profilScroll;
    profilScroll();

    $("profil").innerHTML = htmlSource;
	
	$('profil').set('tween', {
		duration: 250
	});
	$('profil').tween('opacity', 0, 1);
        
    window.onresize = function(){
        profilScroll();
    }
    
    document.onkeyup = function(event){
        var event = new Event(event);
        if (event.code == 27) { // close
            profilClose();
        }
    }
}

function profilClose()
{
	$("profil_overlay").onclick = null;
	$('profil_overlay').set('tween', {
        duration: 400,
        onComplete: function(){
            $('profil_overlay').dispose();
        }
    });
    $('profil_overlay').tween('opacity', 0.6, 0);
    
    document.onkeyup = null;
    document.onkeydown = null;
    window.onresize = null;
    
    if($("TB_overlay"))
    {
		window.onscroll = position;
    }
    else
    {
		window.onscroll = null;
    }
	
	$('profil').set('tween', {
        duration: 250,
        onComplete: function(){
            $('profil').dispose();
        }
    });
    $('profil').tween('opacity', 1, 0);
}

function profilScroll()
{
	$('profil').morph({
		width: '626px',
		left: (window.getScrollLeft() + (window.getWidth() - 626) / 2) + 'px',
		top: (window.getScrollTop() + (window.getHeight() - 584) / 2) + 'px'
	});	
}

/************************* END ***********************/

/************************* LOGOWANIE ***********************/

function pokazLogin() {
	if (!$("TB_overlay")) {
        new Element('div').setProperty('id', 'TB_overlay').injectInside(document.body);
        $('TB_overlay').setOpacity(0);
        $("TB_overlay").setStyles({
			"height": '0px',
			"width": '0px'
		});
		$("TB_overlay").setStyles({
			"height": window.getScrollHeight() + 'px',
			"width": window.getScrollWidth() + 'px'
		});
        
        $('TB_overlay').set('tween', {
            duration: 400
        });
        $('TB_overlay').tween('opacity', 0, 0.6);
        
    }
    
    $('box_logowanie').setOpacity(0);
	$("box_logowanie").style.display = "block";
    
    $("TB_overlay").onclick = loginClose;
    
    window.onscroll = loginScroll;
    loginScroll();

	$('box_logowanie').set('tween', {
		duration: 250
	});
	$('box_logowanie').tween('opacity', 0, 1);
        
    window.onresize = function(){
        loginScroll();
    }
    
    document.onkeyup = function(event){
        var event = new Event(event);
        if (event.code == 27) { // close
            loginClose();
        }
    }
}

function loginClose()
{
	$('box_logowanie').set('tween', {
        duration: 250
    });
    $('box_logowanie').tween('opacity', 1, 0);
	
	$("TB_overlay").onclick = null;
	$('TB_overlay').set('tween', {
        duration: 400,
        onComplete: function(){
            $('TB_overlay').dispose();
        }
    });
    $('TB_overlay').tween('opacity', 0.6, 0);
    
    document.onkeyup = null;
    document.onkeydown = null;
    window.onresize = null;
	window.onscroll = null;
}

function loginScroll()
{
	$('box_logowanie').morph({
		width: '601px',
		left: (window.getScrollLeft() + (window.getWidth() - 601) / 2) + 'px',
		top: (window.getScrollTop() + (window.getHeight() - 300) / 2) + 'px'
	});	
}

/************************* SZCZEGOLY ***********************/

function zamknijSzczegoly() {
	/*$('szczegoly').set('tween', {
		duration: 500,
		onComplete: function(){
            //$('szczegoly').dispose();
            
        }
	});
	$('szczegoly').tween('opacity', 1, 0);
	$('szczegoly').setOpacity(0);*/
	$("szczegoly").style.display = "none";
	TB_remove();
}

function pokazSzczegoly() {
	position();
	//$('szczegoly').setOpacity(0);
	$("szczegoly").style.display = "block";
	$("TB_overlay").style.display = "block";
	new Element('div').setProperty('id', 'TB_overlay').injectInside(document.body);
	$('TB_overlay').setOpacity(1);
	TB_overlaySize();
	
	/* $('TB_overlay').set('tween', {
		duration: 400,
		onComplete: function() {
			$('szczegoly').set('tween', {
				duration: 500
			});
			$('szczegoly').tween('opacity', 0, 1);
		}
	});
	$('TB_overlay').tween('opacity', 0, 0.6);*/
	
	//fadeInMySzczegoly();
	window.onscroll = position;
	
	$("TB_overlay").onclick = zamknijSzczegoly;
	
	document.onkeyup = function(event){
        var event = new Event(event);
        if (event.code == 27) { // close
            zamknijSzczegoly();
        }
    }
}

function TB_remove()
{
	$("TB_overlay").onclick = null;
	$('TB_overlay').set('tween', {
        duration: 400,
        onComplete: function(){
            $('TB_overlay').dispose();
        }
    });
    $('TB_overlay').tween('opacity', 0.6, 0);
    
    document.onkeyup = null;
    document.onkeydown = null;
    window.onscroll = null;
    window.onresize = null;
}

function TB_overlaySize(){
    // we have to set this to 0px before so we can reduce the size / width of the overflow onresize 
    $("TB_overlay").setStyles({
        "height": '0px',
        "width": '0px'
    });
    $("TB_overlay").setStyles({
        "height": window.getScrollHeight() + 'px',
        "width": window.getScrollWidth() + 'px'
    });
}

function position()
{
	if(facebook)
	{	
	$('szczegoly').morph({
			width: '680px',
			left: '35px',
			top: (window.getScrollTop() + (window.getHeight() - 1100) / 2) + 'px'
		});	
	}
	else
	{
		$('szczegoly').morph({
		width: '800px',
		left: (window.getScrollLeft() + (window.getWidth() - 1100) / 2) + 'px',
		top: (window.getScrollTop() + (window.getHeight() - 1300) / 2) + 'px'
	});	
}
}

var TB_doneOnce = 0;

function layerOpen( htmlSource )
{
	//alert("layerOpen");
	if (!document.getElementById("TB_overlay")) {
		//alert("TU CHUJ");
        new Element('div').setProperty('id', 'TB_overlay').injectInside(document.body);
       // document.getElementById('TB_overlay').setOpacity(0);
       // TB_overlaySize();
        
        /*document.getElementById('TB_overlay').set('tween', {
            duration: 400
        });*/
        //document.getElementById('TB_overlay').tween('opacity', 0, 0.6);
        
    }
	
	if (!document.getElementById("TB_window")) {
		//alert("TAM CHUJ");
        new Element('div').setProperty('id', 'TB_window').injectInside(document.body);
        //document.getElementById('TB_window').setOpacity(0);
    }
	//alert("CHUJA NIE MA");
	$("TB_window").style.display = "block";
	$("TB_overlay").style.display = "block";
	//alert("CHUJ BYC POWINIEN");
	
	$("TB_overlay").onclick = layerClose;
    
    //window.onscroll = TB_scroll;
    TB_scroll();
    
    $("TB_window").innerHTML = htmlSource;
    $("TB_window").style.display = "block";
	
	//TB_showWindow();
    
    document.onkeyup = function(event){
        var event = new Event(event);
        if (event.code == 27) { // close
            layerClose();
        }
    }
}

/**********************INFORMACJE SZCZEGÓLNE******************************/
function layerMessageOpen(href, htmlSource )
{
	if (!document.getElementById("TB_window_message")) {
        new Element('div').setProperty('id', 'TB_window_message').injectInside(document.body);
    }
	
	$("TB_window_message").style.display = "block";
    
	$("TB_window_message").style.top = (window.getScrollTop() + (window.getHeight() - 200) / 2) + 'px';
	
	if(facebook)
		$("TB_window_message").style.left = '50px';
	else
	$("TB_window_message").style.left = (window.getScrollLeft() + (window.getWidth() - 625) / 2) + 'px';
    
    $("TB_window_message").innerHTML =
    	'<div style="background-color: #eee; color: #184EB0; width: 100%;height: 100%;padding-bottom: 10px; ">'+
    	'<div style="margin-left: 10px; padding-top: 10px; font-weight: bold; text-align: left;">'+
		'<img src="'+href+'/gfx/icons/information2.gif" style="margin-top: 5px; margin-right: 5px; vertical-align: middle;" alt="informacja" />'+
		htmlSource+
		'<br /></div>'+
		'<a href="#" onClick="layerMessageClose();return false;" class="message_ok">OK</a></div>';
   
    $("TB_window_message").style.display = "block";
	
    document.onkeyup = function(event){
        var event = new Event(event);
        if (event.code == 27) { // close
            layerClose();
        }
    }
}

function layerMessageOpen1( htmlSource )
{
	if (!document.getElementById("TB_window_message")) {
        new Element('div').setProperty('id', 'TB_window_message').injectInside(document.body);
    }
	
	$("TB_window_message").style.display = "block";
    
	$("TB_window_message").style.top = (window.getScrollTop() + (window.getHeight() - 500) / 2) + 'px';
	
	if(facebook)
		$("TB_window_message").style.left = '50px';
	else
		$("TB_window_message").style.left = (window.getScrollLeft() + (window.getWidth() - 825) / 2) + 'px';
    
    $("TB_window_message").innerHTML =
    	'<div style="background-color: #eee; color: #184EB0; width: 100%;height: 100%;padding-bottom: 10px;position: relative;float: left; ">'+
    	'<div style="margin-left: 10px; padding-top: 10px; font-weight: bold; text-align: left;float: left;">'+
		htmlSource+
		'</div>'+
		'<a href="#" style="position: absolute; top: 2px; right: 2px;" onClick="layerMessageClose();return false;">'+
			'<img src="/html//gfx/new/btn_close_x.png" style="float: right;"/>'+
		'</a></div>';
   
    $("TB_window_message").style.display = "block";
	
    document.onkeyup = function(event){
        var event = new Event(event);
        if (event.code == 27) { // close
            layerClose();
        }
    }
}

function layerMessageClose()
{
	$("TB_window_message").style.display = "none";
}


/**********************ZAPROSZNENIA******************************/
function layerOpen1( htmlSource )
{
	if(facebook)
	{
	if (!document.getElementById("TB_overlay")) {
        new Element('div').setProperty('id', 'TB_overlay').injectInside(document.body);
    }

	if (!document.getElementById("TB_window")) {
        new Element('div').setProperty('id', 'TB_window').injectInside(document.body);
    }
	$("TB_window").style.display = "block";
		$("TB_window").style.background = "none";
		$("TB_window").style.border = "none";
	$("TB_overlay").style.display = "block";
	
	$("TB_overlay").onclick = layerClose;
    
	$('TB_window').morph({
		width: '500px',
			height: '595px',
			left: '150px',
			top: (window.getScrollTop() + 450) + 'px'
	});
    
    $("TB_window").innerHTML = htmlSource;
    $("TB_window").style.display = "block";

    document.onkeyup = function(event){
        var event = new Event(event);
        if (event.code == 27) { // close
            layerClose();
        }
    }
}
	else
	{
		if (!document.getElementById("TB_overlay")) {
	        new Element('div').setProperty('id', 'TB_overlay').injectInside(document.body);
	    }
		
		if (!document.getElementById("TB_window")) {
	        new Element('div').setProperty('id', 'TB_window').injectInside(document.body);
	    }
		$("TB_window").style.display = "block";
		$("TB_window").style.background = "none";
		$("TB_window").style.border = "none";
		$("TB_overlay").style.display = "block";
		
		$("TB_overlay").onclick = layerClose;
	    
	$('TB_window').morph({
			width: '900px',
			height: '363px',
			left: (window.getScrollLeft() + (window.getWidth() - 1100) / 2) + 'px',
			top: (window.getScrollTop() + (window.getHeight() - 300) / 2) + 'px'
		});
	    
	    $("TB_window").innerHTML = htmlSource;
	    $("TB_window").style.display = "block";
		
	    
	    document.onkeyup = function(event){
	        var event = new Event(event);
	        if (event.code == 27) { // close
	            layerClose();
	        }
	    }
	}
}

function zamknijZaprosznie() {
	//$("szczegoly").style.display = "none";
	$("TB_window").style.display = "none";
	TB_remove();
}



function TB_scroll()
{
	if(facebook)
	{
		$('TB_window').morph({
			width: '600px',
			left: '100px',
			//left: (window.getScrollLeft() + (window.getWidth() - 800) / 2) + 'px',
		top: (window.getScrollTop() + (window.getHeight() - 200) / 2) + 'px'
	});	
}
	else
	{
		$('TB_window').morph({
			width: '800px',
			left: '100px',
			//left: (window.getScrollLeft() + (window.getWidth() - 800) / 2) + 'px',
			top: (window.getScrollTop() + (window.getHeight() - 200) / 2) + 'px'
		});	
	}
	
}

function TB_showWindow(){
    if (TB_doneOnce == 0) {
        TB_doneOnce = 1;
        
        $('TB_window').set('tween', {
            duration: 250
        });
        $('TB_window').tween('opacity', 0, 1);
        
    }
    else {
        $('TB_window').setStyle('opacity', 1);
        if ($('TB_load')) {
            $('TB_load').dispose();
        }
    }
}

function layerClose()
{
	$("TB_window").style.display = "none";
	//TB_doneOnce = 0;
	//TB_remove();
	
	/*($('TB_window').set('tween', {
        duration: 250,
        onComplete: function(){
            $('TB_window').dispose();
        }
    });
    $('TB_window').tween('opacity', 1, 0);*/
}

/************************* END ***********************/
