/* JavaScript Document

--------------------------------
IFM-SEI
(c) Adam Kudrna & Ondrej Machulda 2011
Last edited: 2011-04-21
--------------------------------

*/



// Initialize
$(document).ready(function () {

	// External Links, except google custom search results
	$('a[href^="http://"]').not('.gs-title').click(function() {
		this.target = '_blank';
	});

	// E-mails
	$('a[href^="mailto:"]').click(function() {
		var email = this.href.match(/[^:]*$/);

		return true;
	});

	// Files
	$('a.file').click(function() {
		this.target = '_blank';

		// Get file extension
		var result = this.href.match(/[^.]*$/);
		var extension = result? result[0].toUpperCase() : 'unknown';

		return true;
	});

	// Show Effect
	$('.show-toggle-next').next().hide();
	$('.show-toggle-next').click(function() {
		$(this).toggleClass('selected');
		$(this).next().animate(
			{'height': 'toggle', 'opacity': 'toggle'},
			{duration: 200, queue: true}
		);
		return false;
	});
	$('.hide-parent').click(function() {
		$(this).parent().animate(
                        {'height': 'toggle', 'opacity': 'toggle'},
			{duration: 200, queue: true}
		).parent().find('.show-toggle-next').toggleClass('selected');
		return false;
	});

	// Fancybox
	$('a.popup, a.gallery, a[rel^=lightbox]').fancybox({
		'centerOnScroll'	:	true,
		'hideOnContentClick':	true,
        'speedIn'			:	300,
        'speedOut'			:	1,
		'titlePosition'		:	'over',
        'transitionOut'		:	'none',
		'overlayColor'		:	'#000',
		'overlayOpacity'	:	0.5,
        'overlayShow'			:	true,
		'onComplete'		:	function() {
			// Show/hide title on hover
			$("#fancybox-wrap").hover(function() {
				$("#fancybox-title").show();
			}, function() {
				$("#fancybox-title").hide();
			});

		}
	});



 	// Tabs
	$('.tabs').tabs();

	// Header Slideshow
	$('#header-slideshow').cycle({
		fx:                 'fade',
		timeout:            3000,
		speed:              1250,
		pause:              false
	});

	// Search Box
	$('#search a.show-toggle-next').click(function() {
	});

    // Hide dummy submits (placed to send form by pressing enter)
    $('.submit-dummy').parent().hide();

});



// Login form field defaults
function fieldReset (field) {
	if (field.defaultValue == field.value) {
		field.value = "";
	}
}


// search toolbox form dynamic options
function searchToolboxOptions(suffix) {
    if (typeof suffix == 'undefined') {
        suffix = '';
    }

    var allowed = new Array();
    allowed['fulltext'] = true;
    allowed['language'] = true;
    allowed['theme']    = true;
    allowed['age']      = true;
    $('#search_in' + suffix + '-element input').each(function() {
        if ($(this).is(':checked')) {
            switch ($(this).val()) {
                case 'tools':
                    break;
                case 'notes':
                    allowed['age']      = false;
                    break;
                case 'events':
                    allowed['age']      = false;
                    break;
                case 'videos':
                    allowed['age']      = false;
                    break;
                case 'articles':
                    allowed['age']      = false;
                    allowed['language'] = false;
                    break;
            }
        }
    });

    if (!allowed['fulltext']) {
        $('input#q' + suffix + '').attr('disabled', 'disabled');
    } else {
        $('input#q' + suffix + '').removeAttr('disabled');
    }
    if (!allowed['language']) {
        $('select#lang' + suffix + '').attr('disabled', 'disabled');
    } else {
        $('select#lang' + suffix + '').removeAttr('disabled');
    }
    if (!allowed['theme']) {
        $('select#themes' + suffix + '').attr('disabled', 'disabled');
    } else {
        $('select#themes' + suffix + '').removeAttr('disabled');
    }
    if (!allowed['age']) {
        $('select#age' + suffix + '').attr('disabled', 'disabled');
    } else {
        $('select#age' + suffix + '').removeAttr('disabled');
    }
}

