
function initContent()
{
    $('#content-bg').stop(true, true).animate({'opacity':'0.7'}, 0);
    RPContent();
}

function RPContent()
{
    if (pageType == 2)
    {
        $('#content').height($('#content-fix').height()+20);
        $('#content-scroll').height($('#content-fix').height());
    }
    else if (pageType == 3)
    {
        $('#content').height($('#content-fix').height()+20);
        $('#content-scroll').height($('#content-fix').height()-30);
    }
    else
    {
        $('#content').height($(window).height()-100);

        if ($('#content-fix').css('display') == 'block')
        {
            if ($('#content-scroll').css('display') == 'block')
            {
                if ($('#content').height() < $('#content-fix').height()+80) $('#content').height($('#content-fix').height()+80);
                $('#content-scroll').height($('#content').height()-$('#content-fix').height()-30);

                if ($('#content-scroll').height() > $('#content-scroll-content').height())
                {
                    $('#content').height($('#content').height()-$('#content-scroll').height()+$('#content-scroll-content').height());
                    $('#content-scroll').height($('#content-scroll-content').height());
                }
            }
            else
            {
                $('#content').height($('#content-fix').height()+20);
            }
        }
        else
        {
            if ($('#content').height() < 120) $('#content').height(70);
            $('#content-scroll').height($('#content').height()-20);

            if ($('#content-scroll').height() > $('#content-scroll-content').height() && $('#content-scroll-content').height() > 100)
            {
                $('#content').height($('#content').height()-$('#content-scroll').height()+$('#content-scroll-content').height());
                $('#content-scroll').height($('#content-scroll-content').height());
            }
        }
    }
    $('#content-bg').height($('#content').height());

    $('#content').css('margin-left', $('#menu').width()+($(window).width()-$('#menu').width()-$('#content').width())/2);
    $('#content').css('margin-top', ($(window).height()-$('#content').height())/2);

    $('#content-loader').css('margin-left', $('#menu').width()+($(window).width()-$('#menu').width()-$('#content-loader').width())/2);
    $('#content-loader').css('margin-top', ($(window).height()-$('#content-loader').height())/2);

    initScroll();
}

function initPageType1()
{
    pageType = 1;
    $('#content-fix').html('');
    $('#content-scroll-content').html('');
    $('#content-fix').width(700);
    $('#content-fix').height(450);
    $('#content-fix').css('position', 'relative');
    $('#content-fix').css('margin-left', 0);
    $('#content-scroll').width(700);
    $('#content-scroll').css('position', 'relative');
    $('#content-scroll').css('margin-top', 10);
    $('#content-scroll').css('margin-left', 10);
    $('#content-scroll-content').width(690);
}

function displayGalleryWithContent(title, galleryID, textID)
{
    clearClick = false;
    if (isIE)
    {
        if ($('#content').css('display') == 'none')
        {
            $('#home-text').stop(true, true).animate({'opacity':'1'}, 600, function(){$('#home-text').css('display', 'none');});
            $('#news').stop(true, true).animate({'margin-top':$(window).height()}, 600, function()
            {
                $('#news').css('display', 'none');
                $('#home-text').stop(true, true).animate({'opacity':'1'}, 600);
                $('#content').css('display', 'block');
                initGalleryWithContent(title, galleryID, textID);
            });
        }
        else
        {
            $('#content').animate({'margin-left':$(window).width()}, 600, function()
            {
                initGalleryWithContent(title, galleryID, textID);
            });
        }
    }
    else
    {
        if ($('#content').css('display') == 'none')
        {
            $('#content').stop(true, true).animate({'opacity':'0'}, 0,  function()
            {
                $('#home-text').stop(true, true).animate({'opacity':'1'}, 600, function(){$('#home-text').css('display', 'none');});
                $('#news').stop(true, true).animate({'margin-top':$(window).height()}, 600, function()
                {
                    $('#news').css('display', 'none');
                    $('#content').css('display', 'block');
                    initGalleryWithContent(title, galleryID, textID);
                });
            });
        }
        else
        {
            $('#content').animate({'margin-left':$(window).width(), 'opacity':'0'}, 600, function()
            {
                initGalleryWithContent(title, galleryID, textID);
            });
        }
    }
}

function initGalleryWithContent(galleryID, textID, title)
{
    var TITLE_HTML = '';

    initPageType1();
    
    if (title != undefined)
    {
        if (galleryID == 9 || galleryID == 10 || galleryID == 11 || galleryID == 13 || galleryID == 17)
        {
            TITLE_HTML += '<h1>'+title+'</h1>';
            TITLE_HTML += '<h2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:displayBungalow();">'+EXTRA_BUNGALOW_TITLE+'</a></h2>';
            TITLE_HTML += '<input type="submit" name="book-room" id="book-room" class="submit_style_book" onclick="backMenu2(); displayRates()" value="'+BOOK+'" />';
        }
        if (galleryID == 12 || galleryID == 14 || galleryID == 15 || galleryID == 16)
        {
            TITLE_HTML += '<h1>'+title+'</h1>';
            TITLE_HTML += '<h2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:displayBungalow();">'+DELUXE_BUNGALOW_TITLE+'</a></h2>';
            TITLE_HTML += '<input type="submit" name="book-room" id="book-room" class="submit_style_book" onclick="backMenu2(); displayRates()" value="'+BOOK+'" />';
        }
    }

    var galleryData = '';
    
    $('#content-loader').css('display', 'block');
    $.post('libraries/com/dop/php/ThumbnailGallery.php', {galleryID:galleryID}, function(data)
    {
        galleryData = data;

        $.post('includes/php/text.php', {id:textID}, function(data)
        {
            $('#content-loader').css('display', 'none');

            $('#content-fix').css('display', 'block');
            $('#content-scroll').css('display', 'block');

            gallery.reset();
            $('#content-scroll-content').html(data);

            if (title != undefined)
            {
                $('#content-fix').html('<div id="content-gallery"></div><div id="content-title"></div>');
                $('#content-gallery').height(424);
                $('#content-title').html(TITLE_HTML);
                gallery.init(galleryID, "#content-gallery", galleryData);
            }
            else gallery.init(galleryID, "#content-fix", galleryData);

            RPContent();

            if (isIE) clearClick = true;
            else $('#content').stop(true, true).animate({'opacity':'1'}, 300, function(){clearClick = true;});
        });
    });
}
