//
// Returns page URL, based on input page
// public ID.
//
function get_page_url(page_id)
{
    return INDEX_URL+'?page&'+FLD_PAGE_ID+'='+page_id+'&'+FLD_TOKEN+'='+get_current_token();
}

//
// Displays google ad.
//
function display_google_ad(type)
{
    //
    // Parse google ad data from global.
    //
    var ad = google_ads[type];

    google_ad_client = ad['client'];
    google_ad_slot = ad['slot'];
    google_ad_width = ad['width'];
    google_ad_height = ad['height'];
    var align = ad['align'];
    
    //
    // Call google JS file.
    //
    document.write('<div style="text-align: '+align+'; clear: both;">');
    document.write('<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>');
    document.write('</div>');
}

//
// Displays google ad.
//
function display_google_ad_new(client, slot, width, height, align)
{
    //
    // Set globals.
    //
    google_ad_client = client;
    google_ad_slot = slot;
    google_ad_width = width;
    google_ad_height = height;
    
    //
    // Call google JS file.
    //
    document.write('<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>');
}

//
// Re-links all a.modal with fancybox.
//
// Needed following online generation of
// theses links. 
//
// Currently this function is uses following
// re-display of page blocks and page rss.
//
// Input box ID was added, since this program
// was inoprable following display of data
// through ajax. I don't know why, but applying
// it with box ID before class name, made it work.
//
// Also, If called with box ID, BEFORE calling it
// without box ID - it failed. That is why the 
// global g_modals_ignited was added.
//
// http://flowplayer.org/tools/overlay/index.html
//
var g_modals_ignited = false;

function make_modals(box)
{
    if (box != null && ! g_modals_ignited)
    {
        return false;
    }
    
    g_modals_ignited = true;
    
    var sel = box == null ? '* .modal_input' : box + ' .modal_input';
    
    $(sel).overlay(
    {
        mask: 
        {
            color: '#ccc',
            loadSpeed: 200,
            opacity: 0.9
        },

        closeOnClick: true,        
        fixed: false        
    });
    
    return false;
    
    /*$("a.modal").fancybox(
    {
        'autoDimensions': true,
        'width': 600,
        'height': 500,
        'hideOnContentClick': false,
        'titleShow': false,
        'transitionIn': 'elastic',   // 'elastic', 'fade', 'none'
        'transitionOut': 'elastic',
        'speedIn': 200, 
        'speedOut': 200, 
        //'modal': true,
        'enableEscapeButton' : true,
        'centerOnScroll' : true,
        'overlayShow': true
    });*/        
}

//
// Closes all modal windows.
//
// NOTE the use of each (every modal is closed
// separately) and the IF statement.
//
function close_modals()
{
    $('.modal_input').each
    (
        function()
        {
            if ($(this).data('overlay') != null) // Because it sometimes errored that the 'overlay' method was not present.
            {
                if ($(this).data('overlay').isOpened())
                {
                    $(this).data('overlay').close();
                }
            }   
        }
    );
}

//
// Makes slideshow and image gallery work.
//
// Called upon page load and changes of
// image gallery / slideshow.
//
function make_slideshow_and_gallery()
{
    $('.slideshow').cycle(
    {
        fx: 'fade',
        fit: 1,
        pause: 1
    });
    
    //
    // Gallery. See http://fancybox.net/api
    //
    $("a.gallery").fancybox(
    {
        'cyclic': true,
        'hideOnContentClick': true,  // Clicking image (not on arrows) will close the image.
        'titlePosition': 'over',     // 'over', 'inside', 'outside'
        'transitionIn': 'elastic',   // 'elastic', 'fade', 'none'
        'transitionOut': 'elastic',
        'speedIn': 600, 
        'speedOut': 200, 
        'enableEscapeButton' : true,
        'centerOnScroll' : true,
        'overlayShow': false
    });        
}