// $Id: jquery_x.js 22 2011-11-25 09:12:01Z Ian $
var originalLinkColour;

$(function() {
    // Collapse all content section boxes
    $('.content-section-box').hide();
    $('.content-section h2 span').css('cursor', 'pointer');
    $('.content-section h2.no-link').css('cursor', 'default');

    // Add title text to content section-links
    $('h2.section-link span').each(function() {
        $(this).attr('title', 'Expand this section');
    });

    // Content section link hover colour
    $('h2.section-link span').mouseover(function() {
        $(this).addClass('hover-text');
    }).mouseout(function() {
        $(this).removeClass('hover-text');
    });

    $('h2.section-link span.hl-pink').mouseover(function() {
        $(this).removeClass('hl-pink').addClass('hover-text');
    }).mouseout(function() {
        $(this).removeClass('hover-text').addClass('hl-pink');
    });

    // Toggle content section boxes
    $('h2.section-link span').click(function() {
        var innerScrollerTop = $('.inner-scroller-content').position().top;
        var id = $(this).parent().attr('id');

        id = id.replace(/^cs-/, 'csb-');

        if ($('#' + id).attr('rel') == 'hidden') {
            $('#' + id).fadeIn(1000);
            $('#' + id).attr('rel', 'shown');
            $('.inner-scroller, .inner-scroller-polish').animate({scrollTop: $('#' + id).position().top - (innerScrollerTop + 35)}, 1250);
            $(this).attr('title', 'Collapse this section');
        } else {
            $('#' + id).fadeOut(400);
            $('#' + id).attr('rel', 'hidden');
            $(this).attr('title', 'Expand this section');
        }
    });

    $('.links-list li a').click(function() {
        var url = $(this).attr('href');
        window.open(url);
        return false;
    });

    $('.photo-credit a').click(function() {
        var url = $(this).attr('href');
        window.open(url);
        return false;
    });

    // Popup window
    $('.pu').click(function() {
        var url = $(this).attr('href');
        window.open(url);
        return false;
    });

    // Launch video player
    $('.video-launch').click(function() {
        var videoSrc = $(this).attr('rel');
        showVideoPlayer(videoSrc, true, 50);
        $(this).fadeOut();
        return false;
    });

    // Close video player
    $('#video-close').click(function() {
        $('#vpo').hide();
        $(this).parent().fadeOut(function() {
            $('.video-launch').fadeIn(1000);
        });
    });

    // Show map
    $('.map-link').click(function(e) {
       e.preventDefault;
       $.facebox({div: '#map'});
       return false;
    });
});

function showVideoPlayer(videoSrc, autoStart, initVolume) {
    if ($('#video-player-container').length > 0) {
        // Get position of parent container
        var pos = $('.inner-scroller-content').offset();

        // Position player container in the centre
        $('.video-player-overlay').css({'left': pos.left + 'px', 'top': pos.top + 'px'});
        $('.close').attr('title', 'Close');

        // Clear the contents of the player container
        $('#video-player-container').empty();

        /*if (confirm('Use full overlay?')) {
            $('#vpo').css({
                width:          $(window).width(),
                height:         $(window).height()
            }).show();
        }*/

        // Init / display the player
        $('.video-player-overlay').show();

        // Define the player
        /*jwplayer('video-player-container').setup({
            flashplayer:            '/player.swf',
            file:                   '/_video/' + videoSrc + '.flv',
            width:                  580,
            height:                 440,
            autostart:              autoStart,
            controlbar:             'over'
        });*/

        $('#video-player-container').flash({
            src:                        '/vplayer.swf',
            width:                      600,
            height:                     460,
            allowfullscreen:            true,
            wmode:                      'transparent',
            flashvars:                  {
                flvpVideoSource:        '/_video/' + videoSrc + '.flv',
                flvpAutoStartMovie:     autoStart,
                flvpInitVolume:         initVolume,
                flvpWidth:              600,
                flvpHeight:             460
            }
        });
    }
}

