/* 
 * Miscellaneous functionality.
 */

$(document).ready(function(e) {
    
    /*
     * Toggles fullscreen mode.
     */
    $('.fullscreen').click(function(e) {

        /* Toggles fullscreen window */
        window.open(window.location, 'fs', 'fullscreen=yes');
        window.close('fs');
        
    });
    
    /*
     * Video settings toggle.
     */
    $('label.settings_video').click(function(e) {

        /* Toggle classes */
        $('label.settings_video').toggleClass('selected');
        
        /* Find new value */
        var value = 'off';
        if ($(this).attr('id') == 'settings_video_on') {
            value = 'on';
        }
        
        /* Update server */
        $.ajax({
            type: 'POST',
            url: '/gruppe/video/' + value + '/',
            dataType: 'json'
        });
        
    });
    
    /*
	 * Handles clicks on the video archive to play a video.
	 */
	$('#popup_archive .video').click(function(e) {

		/* Close video archive menu */
		$(this).closest('.popup').trigger('mouseleave');
		
		/* Play video */
		var video_url = $(this).data('url');
		playVideo(video_url, 'opaque', 582, 350);
		
		return false;

	});
	
	/*
	 * Handles clicks on the steps list to go to a step.
	 */
	$('#popup_steps .step.enabled').click(function(e) {

		/* Close step menu */
		$(this).closest('.popup').trigger('mouseleave');
		
		/* Play video */
		var url = $(this).data('url');
		window.location.href = url;
		
		return false;

	});
    
});

