/** 
 * Copyright (c) 2009-2010 Datenpark, Philip Iezzi
 * http://www.datenpark.ch/
 *
 * JQuery UI elements setup
 */

$(document).ready(function() {
    // Form Field Value Swap
    swapValues = [];
    $('.swap_value').each(function(i){
        swapValues[i] = $(this).val();
        $(this).focus(function(){
            if ($(this).val() == swapValues[i]) {
                $(this).val('');
            }
        }).blur(function(){
            if ($.trim($(this).val()) == '') {
                $(this).val(swapValues[i]);
            }
        });
    });

    $('a.fancybox').fancybox({
        // 'overlayOpacity': 0.6
    });

    $('a.fancyframe').fancybox({
        'frameWidth':  430,
        'frameHeight': 365
    });

    $('.accordion .head').click(function() {
        $(this).next().toggle('fast');
        return false;
    }).next().hide();

    // jQuery.dialog - access each element individually
    $('a.modalDialog').each(function()
    {
        $(this).click(function(e) {
            title = this.getAttribute('title');
            if (title == 'download-confirm') {
                document.getElementById('modalDialog').innerHTML = document.getElementById('download-confirm').innerHTML;
            } else {
                document.getElementById('modalDialog').innerHTML = title;
            }
            redirectUrl = this.getAttribute('href');

            $('#modalDialog').dialog({
                bgiframe: true,
                autoOpen: false,
                draggable: true,
                modal: true,
                resizable: false,
                title: 'Bestätigung',
                closeOnEscape: true,
                buttons: {
                    'OK': function() { window.location.href = redirectUrl; },
                    'Abbrechen': function() { $(this).dialog('close'); }
                }
            });
            
            $('#modalDialog').dialog('open');
            e.preventDefault();
        });
    });
});

