function bind_inputs()
{
  $('input[type=text], textarea').each( function () {
                                if ( $(this).val() == '' ) $(this).val($(this).attr('alt'));

                                $(this).bind('focus', function() {
                                                            if ( $(this).val() == $(this).attr('alt') ) $(this).val('');
                                                         }
                                            )

                                $(this).bind('blur', function() {
                                                            if ( $(this).val() == '' ) $(this).val($(this).attr('alt'));
                                                         }
                                            )
                              }
                            );
}

function unbind_inputs()
{
  $('input[type=text], textarea').each( function () { if ( $(this).val() == $(this).attr('alt') ) $(this).val(''); } );
}

function create_papers()
{
  $('.paper').each( function() {
                    css = $(this).attr('class');
                    if ( css.indexOf('nopaper') != -1 ) return;

                    html = $(this).html();

                    if ( html.indexOf('class="content"') == -1 ) html = '<div class="content">' + html + '</div>';

                    $(this).html(html);

                    $(this).prepend('<span class="lt"></span>' +
                                    '<span class="rt"></span>');
                    $(this).append('<div class="float_limiter"></div>' +
                                    '<span class="rb"></span>' +
                                    '<span class="lb"></span>');
                    }
                  );

  $('.paper2, .paper3').each( function() {
                    css = $(this).attr('class');
                    if ( css.indexOf('nopaper') != -1 ) return;

                    //html = $(this).html();

                    //if ( html.indexOf('class="content"') == -1 ) html = '<div class="content">' + html + '</div>';

                    $(this).append('<div class="float_limiter"></div>' +
                                    '<span class="rb"></span>' +
                                    '<span class="lb"></span>');
                    }
                  );
}

var do_not_close = false;

function create_select_tags()
{
  $('.select select').each( function() {
    $(this).attr('name', $(this).parent().attr('id') + '[]');
    $(this).attr('size', Math.min(8, $('option', this).length));
    $('label[for='+$(this).parent().attr('id')+']').bind('click', function() { $('#' + $(this).attr('for') + ' a.click').click(); } );
  });
  $('.select select, .select2 .selection').bind('blur', function() { $(this).css('display', 'none'); } );
  $('.select select').bind('change', function()
                                     {
                                       if ( $('option:selected', this).attr('value') == '' ) var value = $(this).prev('a.click').attr('title');
                                       else var value = $('option:selected', this).html();


                                       $(this).siblings('span.caption').each( function()
                                                                              {
                                                                                $(this).html( value );
                                                                              }
                                                                            );
                                       $(this).css('display', 'none');
                                     } );
  $('.select a.click, .select span.caption, .select2 a.click, .select2 span.caption').bind('click', function()
                                             {
                                               $('.selection', $(this).parent()).toggle(0);
                                               $('select', $(this).parent()).focus();

                                               return false;
                                             } );
}

function update_select_caption( sender )
{
  if ( $('option:selected', sender).attr('value') == '' ) var value = $(sender).parent('div').parent('div.selection').prev('a.click').attr('title');
  else var value = $('option:selected', sender).html();

  $('span.caption', $(sender).parent('div').parent('div.selection').parent('.select2')).html(value);
}

function decode_emails()
{
  $('a.mail').each( function()
                    {
                      email = $(this).html();
                      if ( email ) email = email.replace('[zavináč]', '@');

                      $(this).attr('href', 'mailto:' + email);
                      $(this).html(email);
                    } );
}

function select_top_filter( sender, locID )
{
  $('#filter_location').val(locID);

  if ( !locID ) $('#location_filter span').html($(sender).parent().parent().parent().prev('a').attr('title'));
  else $('#location_filter span').html($(sender).html());

  $('#location_filter span').click();
}

function hide_location_filter(){
  //$('#location_filter .selection').fadeOut(0);
}
