// funkce pro otevreni noveho okna
function openwindow(address) {
  return !window.open(address, "new_window", "width=600,height=600,resizable=yes,scrollbars=yes");
};

/* Funkce pro vlozeni textu na konec obsahu prvku textarea se zpravou */
function emoticon(code) {
   $("textarea.add-emoticons").val($("textarea.add-emoticons").val() + " " + code + " ");
   $("textarea.add-emoticons").focus();
}

$(document).ready(function(){

  $(".nospam").hide();
  $("input.nospam").val("no" + "spam");

  $(".hide").hide();

  $('input.datepicker').datepicker({duration: 'fast', inline: true});

  $('#posts a').filter(function() {
    return this.hostname && this.hostname !== location.hostname;
  }).addClass('external');

  $('.delete').click(function(){
     var answer = confirm('Opravdu si p\u0159ejete záznam smazat?');
     return answer // answer is a boolean
  }); 

  $('.confirm').click(function(){
     var answer = confirm('Opravdu si p\u0159ejete provést danou akci?');
     return answer // answer is a boolean
  });
  
  $('.truncate').truncate({max_length: 160, more: '[více]', less: '[mén\u011b]'});

  $("#content a[href$=.jpg], #content a[href$=.jpeg], #content a[href$=.png], #content a[href$=.gif]").fancybox();
  
  // skryvani a prepinani prvku
  $("div.attr-types").hide();
  $('a.attr-types').click(function(){
     $('div.attr-types').toggle('slow');
  });

  //$("div.user-attributes").hide();
  $('a.user-attributes').click(function(){
     $('div.user-attributes').toggle('slow');
  });

  //$("div.user-contacts").hide();
  $('a.user-contacts').click(function(){
     $('div.user-contacts').toggle('slow');
  });
  
    // prilepime k poli pro text vyber smajlu
  $("textarea.add-emoticons").after(
           '<br /><span class="emoticons">' +
           'Vložit smajlíka: ' +
           '<a href="javascript:emoticon(\':-)\')"> <img src="/images/emoticons/happy.gif" alt=":-)" title=":-)" /> </a>' +
           '<a href="javascript:emoticon(\':-(\')"> <img src="/images/emoticons/sad.gif" alt=":-(" title=":-(" /> </a>' +
           '<a href="javascript:emoticon(\':-O\')"> <img src="/images/emoticons/shocked.gif" alt=":-O" title=":-O" /> </a>' +
           '<a href="javascript:emoticon(\':-D\')"> <img src="/images/emoticons/biggrin.gif" alt=":-D" title=":-D" /> </a>' +
           '<a href="javascript:emoticon(\';-)\')"> <img src="/images/emoticons/wink.gif" alt=";-)" title=";-)" /> </a>' +
           '<a href="javascript:emoticon(\':-P\')"> <img src="/images/emoticons/tongue.gif" alt=":-P" title=":-P" /> </a>' +
           '</span>'
        );

});

// skrývání flash zpráviček
$("div.flash").livequery(function () {
	var el = $(this);
	setTimeout(function () {
		el.animate({"opacity": 0}, 2000);
		el.slideUp();
	}, 7000);
});

// datepicker
$("input.datepicker:not([readonly])").livequery(function () {
	$(this).datepicker();
});

//funkce pro pridani Kategorie obrázků do článku
function addCategory()
{
    var categoryId = document.getElementById('imgCategory').value;
    var data;
    $.get("/admin/story/get-img-urls", {"categoryId": categoryId}, function(jsondata){
        var data=jsondata.data;
        var dataSplit = data.split("#");
        var urls = dataSplit[0].split("$");
        var alts = dataSplit[1].split("$");
        var noOfImgs = urls.length;
        if (urls == ""){alert("Kategorie je prázdná!")}
        else {
            CKEDITOR.instances.ckeditor.insertHtml( '<div id="CKEditorMassImageInsert">' );
            for (var i = 0; i < noOfImgs; i++){
                var element = CKEDITOR.dom.element.createFromHtml( '<a href="'+urls[i]+'" rel="gallery"><img alt="'+alts[i]+'" src="'+urls[i]+'?width=200&amp;height=132" style="width: 200px; height: 132px; border-width: 1px; border-style: solid;" /></ a>' );
                CKEDITOR.instances.ckeditor.insertElement( element );
            }
            CKEDITOR.instances.ckeditor.insertHtml( '</ div>' );
        }
    });
}

