function InitRichEditors() {
  tinyMCE.init({
    mode : "specific_textareas",
    theme : "simple",
    editor_selector : "mceSimple",
    convert_urls : false,
//    object_resizing : true,
/*    theme_simple_toolbar_location : "top",
    theme_simple_toolbar_align : "left",
    theme_simple_statusbar_location : "bottom",
    theme_simple_resizing : true, */
    content_css : "/css/tinymce/content.css",
    language : "cs"
//    table_inline_editing : true,
//    language : "cs"
//    mode : "exact",
//    elements : "frm-perex"
  });

  tinyMCE.init({
    mode : "specific_textareas",
    theme : "advanced",
    editor_selector : "mceAdvanced",
    convert_urls : false,

//    table_inline_editing : true,
//    content_css : "css/example.css",
    plugins : "safari,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template", //,imagemanager,filemanager",
// Theme options
    theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
    theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
    theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
    theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,pagebreak,|,insertfile,insertimage",
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "left",
    theme_advanced_statusbar_location : "bottom",
    theme_advanced_resizing : true,

    content_css : "/css/tinymce/content.css",
    language : "cs"
//    mode : "exact",
//    elements : "frm-perex"

  });
/*  $('form').bind('form-pre-serialize', function(e) {
    alert('aaa');
    //tinyMCE.triggerSave();
  }); */
}

function InitAjaxForms(context) {
  $(function () {
          // odeslání na formulářích
/*          $("form").submit(function () {
                  $(this).ajaxSubmit();
                  return false;
          }); */

          // odeslání pomocí tlačítek
          $("form :submit",context).click(function () {
                  if(this.name.indexOf('iupload') >= 0) {
                    return true;
                  }
                  else if(this.name.indexOf('delete') >= 0) {
                    if (confirm('Přejete si opravdu záznam smazat ?'))
                      $(this).ajaxSubmit();
                  }    
                  else {
//                    alert($('frm-perex'));
                    tinyMCE.triggerSave();
//                    alert($('frm-perex'));
                    $(this).ajaxSubmit();
                  }

                  return false;
          });
  });
}

function InitDatePickers() {
//  $(document).ready(function(){
    $('input.datepicker').datepicker({ duration: 'fast', dateFormat: 'dd.mm.yy', firstDay: 1, monthNames: ['leden','únor','březen','duben','květen','červen','červenec','srpen','září','říjen','listopad','prosinec'], dayNames: ['neděle','pondělí','úterý','středa','čtvrtek','pátek','sobota'], dayNamesMin: ['ne','po','út','st','čt','pá','so'], dayNamesShort: ['ned','pon','úte','stř','čtv','pát','sob'], showOn: 'button', showButtonPanel: true, closeText: 'Zavřít', currentText: 'Dnes', buttonImage: '/css/datepicker.png', buttonImageOnly: true, buttonText: 'Kalendář' });
    $('img.ui-datepicker-trigger').each(function () { $(this).attr("id",$(this).prev("input").attr("id")+'-calend'); });
    $('img.ui-datepicker-trigger').each(function () { $(this).css("display",$(this).prev("input").css("display")); });
//  }); 
}

$(document).ready(function(){   
  $('#s-login').focus(function(){
    var val1 = $(this).attr('title');
    var val2 = $(this).attr('value');
    if( val1==val2)
    {
      $(this).attr('value', '');
    }
  })

  $('#s-login').blur(function(){
    var val1 = $(this).attr('title');
    var val2 = $(this).attr('value');
    if( val2=='')
    {
      $(this).attr('value', val1);
    }
  })

  $('#s-password-show').focus(function(){
    $(this).addClass('hidden');
    $('#s-password').removeClass('hidden');
    $('#s-password').focus();
  })

  $('#s-password').blur(function(){
    if($(this).attr('value') == '')
    {
      $(this).addClass('hidden');
      $('#s-password-show').removeClass('hidden');
      $(this).blur();
    }
  })
})



function TestFunc () {
  alert('testovací alert');  
}

function ComAsk(event,question) {
  var result = confirm(question);
  
  if (result == false) {
    event.stopPropagation();    
  }
  
  return result;
}


jQuery(function($) {
//  $.nette.registerAfterUpdate();

/*  $.ajaxSetup({
    success: $.nette.success,
    dataType: 'json'
  });

  // pĹ?i AJAXovĂŠm poĹžadavku bude zobrazovat animaci
  $.nette.createSpinner();
*/
  // pĹ?iĹ?aÄ? vĹĄem souÄ?asnĂ˝m i budoucĂ­m odkazĹŻm s tĹ?Ă­dou ajax po kliknutĂ­ tuto funkci
  $('a.ajax').live('click', function(event) {
    event.preventDefault();
    if ($.active) return;
    
    if (event.button == 2) return;    

    $.post(this.href, $.nette.success);

    $.nette.spinner.css({
      position: 'absolute',
      left: event.pageX,
      top: event.pageY
    });
  });

  // ajaxovĂŠ odeslĂĄnĂ­ na vĹĄech souÄ?asnĂ˝ch i budoucĂ­ch formulĂĄĹ?Ă­ch
  $("form.ajax").live("submit", function() {
    $(this).ajaxSubmit();
    return false;
  });

  // ajaxovĂŠ odeslĂĄnĂ­ pomocĂ­ tlaÄ?Ă­tka na vĹĄech souÄ?asnĂ˝ch i budoucĂ­ch formulĂĄĹ?Ă­ch
  $("form.ajax :submit").live("submit", function () {
    $(this).ajaxSubmit();
    return false;
  });

  // ajaxovĂŠ odeslĂĄnĂ­ vĹĄech souÄ?asnĂ˝ch i budoucĂ­ch formulĂĄĹ?ĹŻ i pomocĂ­ zmÄ?ny selectboxu
  $("form.ajax select.ajax").live('change', function() {
    $(this.form).ajaxSubmit();
    return false;
  });
  
  // ajaxovĂŠ odeslĂĄnĂ­ vĹĄech souÄ?asnĂ˝ch i budoucĂ­ch formulĂĄĹ?ĹŻ i pomocĂ­ zmÄ?ny selectboxu
  $("input.kfileuploadbtn").live('click', function() {
//    alert('aaa');
//    $('input.kfileuploadori').value();
//    $('#frmmybookcase227-file1').click();
//    $('input.kfileuploadori').focus();
//    $('input.kfileuploadori').mousedown();
//    $('input.kfileuploadori').val('aaaa');
    $('input.kfileuploadori').next().click();
    
    alert('aaa');
    return false;
  });

  $("input.kfileuploadori").live('change', function() {
//    alert('aaa');
    $('input.kfileuploadtxt').val($('input.kfileuploadori').val());
    return false;
  });
  
  
  $("form.ajax").live("submit", function() {
    $(this).ajaxSubmit();
    return false;
  });

//  alert (' aaaa ');

  $('.locopanchor').livequery('mouseenter', function () { $(this).find('.locopanel').show(); });
  $('.locopanchor').livequery('mouseleave', function () { $(this).find('.locopanel').hide(); });
  $('.locopanchor1').livequery('mouseenter', function () { $(this).find('.locopanel1').show(); });
  $('.locopanchor1').livequery('mouseleave', function () { $(this).find('.locopanel1').hide(); });
  $('.locopanchor2').livequery('mouseenter', function () { $(this).find('.locopanel2').show(); });
  $('.locopanchor2').livequery('mouseleave', function () { $(this).find('.locopanel2').hide(); });
  $('.locopanchor3').livequery('mouseenter', function () { $(this).find('.locopanel3').show(); });
  $('.locopanchor3').livequery('mouseleave', function () { $(this).find('.locopanel3').hide(); });
  
  
//  alert (' bbbb ');
  
//  $('.locopanchor').live(function () { $(this).children('.locopanel').first().hide(); });
  InitRichEditors();
  InitDatePickers();
});
