var tapeta;
$(document).ready(function()
{
            
    $('#menu #butt div').css('left', 0);

    $('#close').click(function()
    {
        $('#contentBottom').slideToggle('fast');
        if($('#close').hasClass('toggle'))
        {
            $('#close').removeClass('toggle');
        }
        else
        {
            $('#close').addClass('toggle');
        }
    });

    $('#menu #butt div').click(function()
    {
        $('#content').slideUp('fast');

        if( jQuery('#siteWrapper table.imgs').width() != null )
        {
            jQuery('#siteWrapper').html('<div id="content"><div id="contentTop"><div id="leftCorner"></div><div id="rest"><div id="slideDown"></div></div></div><div id="contentBottom"></div></div>');
            jQuery('body').css('background', tapeta);
            jQuery('#siteFooter').html('');
        }

        jQuery('#imageContainer').hide();



    });



    //$('#rest').width( window.innerWidth-40
	$('#page').css('height', getWindowHeight() + 'px');
    setRandomBg();// setTimeout('checkHash();', 3500);

            

            



});

function loadPage( page )
{

    jQuery.ajax(
    {
        url: '/content.php?cont=' + page,
        async: true,
        dataType: 'text',
        error: function(){},
        success: function(src)
        {

            $("#content").slideDown("slow");
            jQuery("#contentBottom").html(src);
        }
    });
}

function hideText()
{
    $('#content').slideUp('slow');
}

function loadDialog()
{
    jQuery.ajax(
    {
        url: 'content.php?cont=1',
        async: true,
        dataType: 'text',
        error: function(){},
        success: function(src)
        {

            jQuery('body').append('<div id="zdjeciaDialog"></div>')
            jQuery( '#zdjeciaDialog' ).html(src);
            jQuery('#zdjeciaDialog').fadeIn('fast');

            jQuery('#zdjeciaDialog').mouseleave(function()
            {
                setTimeout('hideDialog();', 1000);

            });
        }
    });

                        
}

function deleteDialog()
{
            
    jQuery('#zdjeciaDialog').remove();
}

function hideDialog()
{
    jQuery('#zdjeciaDialog').fadeOut('slow');

    setTimeout('deleteDialog();',2000);
}

function loadGallery( gallery )
{
    jQuery('body').css('background', '#666768' );
    jQuery('#content').slideUp('slow');
    var wysokosc;
    var iRozmiar = 0;

    if(jQuery.browser.msie )
    {
        wysokosc = parseInt(document.body.clientHeight) - 155;
        if(wysokosc<0)
        {
            wysokosc = parseInt(document.documentElement.clientHeight) - 155;
        }

    }
    else
    {
        wysokosc = parseInt(window.innerHeight) - 155;
    }

    iRozmiar = getVerticalSize(wysokosc);




    jQuery.ajax(
    {
        url: 'gallery.php?galeria=' + gallery + '&rozmiar=' + iRozmiar,
        async: true,
        dataType: 'text',
        error: function(){},
        success: function(src)
        {
            var aZdjecia = src.split('||');
            var iIloscZdjec = aZdjecia.length-1;
            szerokosc = 0;
            jQuery('#siteFooter').html('<div id="mini"></div>');
            jQuery('#siteWrapper').html('<table class="imgs"><tr></tr></table>');

            for(var i = 0; i < iIloscZdjec; i++)
            {
                jQuery('#siteWrapper table tr').append( '<td><div class="photo"><img src="' + aZdjecia[i] + '" /></div></td>' );
                jQuery('#mini').append('<div class="miniPhoto"><a href="javascript:void(0);" onclick="scrollToImage(' + i + ');">' + (i + 1) +  '</a></div>');
                setTimeout('wait();', 1000);
            }

            jQuery('#siteWrapper div.photo').click(function()
            {
                $.scrollTo(this, 1000, {
                    offset:-20
                });
            });

            jQuery('#mini div.miniPhoto').mouseenter(function(e)
            {
                var iNr = parseInt(jQuery(this).children('a').html()) - 1;
                var stosunek = parseInt(jQuery('#siteWrapper table img').eq(iNr).width())/parseInt(jQuery('#siteWrapper table img').eq(iNr).height());
                jQuery('#miniature').html( '<img src="' + aZdjecia[iNr] + '" width="' + parseInt(stosunek * 50) + '" height="50" />' );
                             
                jQuery('#miniature').css('left', e.pageX - 30);
                jQuery('#miniature').fadeIn(200);

            });

            jQuery('#mini div.miniPhoto').mouseleave(function()
            {
                jQuery('#miniature').hide();

            });
        }
    });




}

function checkHeight()
{
    var szer;
    if(jQuery.browser.msie )
    {
        $('#content').width( document.body.clientWidth);
        szer = document.body.clientWidth;
    }
    else
    {
        $('#content').width( window.innerWidth);
        szer = window.innerWidth;
    }

    return szer;
}

function getWindowHeight()
{
	var wys;
    if(jQuery.browser.msie )
    {
		wys = document.documentElement.clientHeight;
		if(wys <= 0 )
        wys = document.body.clientHeight;
    }
    else
    {
        wys = window.innerHeight;
    }

    return wys;
}

function getSize( szerokosc )
{
    var iRozmiar = 1024;

    if( szerokosc > 1100 )
    {
        iRozmiar = 1152;
    }

    if( szerokosc > 1230 )
    {
        iRozmiar = 1280;
    }

    if( szerokosc > 1310 )
    {
        iRozmiar = 1360;
    }

    if( szerokosc > 1390 )
    {
        iRozmiar = 1440;
    }

    if( szerokosc > 1550 )
    {
        iRozmiar = 1600;
    }

    if( szerokosc > 1630 )
    {
        iRozmiar = 1680;
    }

    if( szerokosc > 1870 )
    {
        iRozmiar = 1920;
    }

    return iRozmiar;
}

function getVerticalSize( wysokosc )
{
    var iRozmiar = 0;

    if( wysokosc > 430 )
    {
        iRozmiar = 1;
    }

    if( wysokosc > 530 )
    {
        iRozmiar = 2;
    }

    if( wysokosc > 630 )
    {
        iRozmiar = 3;
    }

    if( wysokosc > 730 )
    {
        iRozmiar = 4;
    }

    if( wysokosc > 830 )
    {
        iRozmiar = 5;
    }

    if( wysokosc > 930 )
    {
        iRozmiar = 6;
    }

    return iRozmiar;
}


function setRandomBg()
{
    var szerokosc = checkHeight();
    var iRozmiar = getSize(szerokosc);
    var iTlo = Math.floor(Math.random()*100)%10;
    var background = 'url(/img/tlo/' + iRozmiar + '/' + iTlo + '.jpg) center no-repeat fixed ';
    tapeta = background;
    jQuery('#page').css('background', background);
    loadContent();
}

function scrollToImage(nr)
{
    var element = $('#siteWrapper div.photo').eq(nr);
    jQuery('#miniature').hide();
    $.scrollTo(element,1000, {
        offset:-20
    });

}

window.onresize = function(e)
{
		$('#page').css('height', getWindowHeight() + 'px');
}

function wait()
{

}
