
  /*portál*/

  $(document).ready(
     function(){
        $("ul.sf-menu").superfish();
        $(".fancybox").fancybox();
        $('.fancyboxPicture').fancybox({
           transitionIn: 'elastic',
           transitionOut: 'elastic',
           titlePosition: 'over'
        });

        initDivToEditorButtons();
        initDivToEditorLinks();
        initInputToEditorButtons();
          
     }
  );


  var originalContent = new Array();

  function focusLogin() {
     $("#login_name").focus();
  }

  function initDivToEditorLinks() {
     $('a[rel=divToEditor]').click(
        function () {
           $(this).unbind('click');
           $(this).attr('rel', 'editorToDiv');
           $(this).find('div[class="label"]').html('bezárás');
           initEditorToDivLinks();
           var id = $(this).attr('divToEditor');
           var tool = $(this).attr('toolBar');
           divToEditor(id, tool);
        }
     );
  }

  function initEditorToDivLinks() {
     $('a[rel=editorToDiv]').click(
        function () {
           $(this).unbind('click');
           $(this).attr('rel', 'divToEditor');
           $(this).find('div[class="label"]').html('szerkesztés');
           initDivToEditorLinks();
           var id = $(this).attr('divToEditor');
           var tool = $(this).attr('toolBar');
           editorToDiv(id, tool);
        }
     );
  }

  function initDivToEditorButtons() {
     $('input[rel=divToEditor]').click(
        function () {
           $(this).unbind('click');
           $(this).attr('rel', 'editorToDiv');
           $(this).attr('value', '[destroy editor]');
           initEditorToDivButtons();
           var id = $(this).attr('divToEditor');
           var tool = $(this).attr('toolBar');
           divToEditor(id, tool);
        }
     );
  }

  function initEditorToDivButtons() {
     $('input[rel=editorToDiv]').click(
        function () {
           $(this).unbind('click');
           $(this).attr('rel', 'divToEditor');
           $(this).attr('value', '[create editor]');
           initDivToEditorButtons();
           var id = $(this).attr('divToEditor');
           var tool = $(this).attr('toolBar');
           editorToDiv(id, tool);
        }
     );
  }

  function divToEditor(id, tool){
     originalContent[id] = $('#'+id).html();
     $('#'+id).replaceWith('<div class="inlineEditor"><textarea name="'+$('#'+id).attr('name')+'" id="'+id+'">'+$('#'+id).html()+'</textarea></div>');
     createEditor(id, tool);
  }

  function editorToDiv(id, tool){
     $('#'+id).tinymce().remove();
     $('#'+id).parent().replaceWith('<div id="'+id+'" name="'+id+'">'+originalContent[id]+'</div>');
  }

  function initInputToEditorButtons() {
     $('[rel=inputToEditor]').click(
        function () {
           $(this).unbind('click');
           $(this).attr('rel', 'toggleEditor');
           var id = $(this).attr('inputToEditor');
           var tool = $(this).attr('toolBar');
           createEditor(id, tool);
           initToggleEditorButtons();
        }
     );
  }

  function initToggleEditorButtons() {
     $('[rel=toggleEditor]').click(
        function () {
           var id = $(this).attr('inputToEditor');
           toggleEditor( id )
        }
     );
  }

  function array_unique(ar){
     var sorter = {};
     for(var i=0,j=ar.length;i<j;i++){
       sorter[ar[i]+typeof ar[i]] = ar[i];
     }
     ar = [];
     for(var i in sorter){
       ar.push(sorter[i]);
     }
     return ar;
  }

  $.fn.tagName = function() {
     return this.get(0).tagName;
  }

  function toggleEditor( id ) {
     hidden = $('#'+id).tinymce().isHidden();

     if (hidden == false) {
        $('#'+id).tinymce().hide();
     } else {
        $('#'+id).tinymce().show();
     }

  }


  function createEditor(id, tool) {
     b1 = b2 = b3 = b4 = '';

     if (tool=='all') {

        b1 = 'save,newdocument,|,bold,italic,underline,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,|,outdent,indent,blockquote,|,cut,copy,paste,pastetext,pasteword,|,undo,redo,|,search,replace';
        b2 = 'link,unlink,anchor,image,cleanup,help,code,|,styleselect,formatselect,fontselect,fontsizeselect,importTabularData,tabledraw,convertcelltype';
        b3 = 'tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,';
        b4 = 'insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,insertdate,inserttime,preview,|,forecolor,backcolor,|,visualchars,nonbreaking,fullscreen,|,template,imageplugin,videoplugin,rateplugin,|,relatedarticle,relatedfile';

     }

     if (tool=='basic') {
        b1 = 'newdocument,|,bold,italic,underline,|,justifyleft,justifycenter,justifyright,justifyfull,|,cut,copy,paste,|,link,|,code,|,pasteword';
     }

     $('#'+id).tinymce({
        // Location of TinyMCE script
        script_url : '/_editor/tiny_mce/tiny_mce.js',

        // General options
        theme : "advanced",
        skin : "o2k7",
        skin_variant : "black",
        plugins : "safari,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,importTabularData,tableextras,imageplugin,videoplugin,relatedarticle,relatedfile, rateplugin",

        // Theme options
        theme_advanced_buttons1 : b1,
        theme_advanced_buttons2 : b2,
        theme_advanced_buttons3 : b3,
        theme_advanced_buttons4 : b4,

        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_statusbar_location : "bottom",
        theme_advanced_resizing : true,

        // Example content CSS (should be your site CSS)
        content_css : "/_css/tinyMcecontent.css",

        //relative_urls : false,
        remove_script_host: true,
        extended_valid_elements : "iframe[src|width|height|name|align|scrolling|frameborder]",
        image_browser_callback: 'tinyMceGalery',
        file_browser_callback: 'tinyMceFile',
        convert_urls: false,
			template_templates : [
				{
					title : "Doboz",
					src : "/_editor/tiny_mce/plugins/template/template1.html",
					description : "Egy sima, szürke doboz (ha minden szöveget kitörölsz belőle, eltűnik, úgyhogy jelöld ki a dobozban lévő szöveget, és úgy írd át!)"
				},
				{
					title : "Fejléces doboz",
					src : "/_editor/tiny_mce/plugins/template/template2.html",
					description : "Szürke doboz, fejléccel (olyan, mint a kapcsolódó cikkek)"
				}
			]
      });

  }

  /* explorer hibat dob ha ez bent van - tib */
  function createEditorByClass(c,tool) {
     $('.'+c).each(function(k,v){createEditor($(v).attr('id'),tool);});
  }

  /**
   *
   * @param field_name
   * @param url           forrás URL-je
   * @param type
   * @param win
   * @return
   */
  function tinyMceGalery(field_name, url, type, win) {
		    //alert("Field_Name: " + field_name + "\nURL: " + url + "\nType: " + type + "\nWin: " + win); // debug/testing

		    /* If you work with sessions in PHP and your client doesn't accept cookies you might need to carry
		       the session name and session ID in the request string (can look like this: "?PHPSESSID=88p0n70s9dsknra96qhuk6etm5").
		       These lines of code extract the necessary parameters and add them back to the filebrowser URL again. */

	  		var connectionTypeField = tinyMCE.selectedInstance.editorId+"_galeryConnectionType";
	  		var connectionIdField = tinyMCE.selectedInstance.editorId+"_galeryConnectionId";

	  		var cType = $('#'+connectionTypeField).val();
	  		var cId = $('#'+connectionIdField).val();

	  		if ( (cType) && (cId) ) {
			    var cmsURL = '/tinymcegalery.php?cType='+cType+'&cId='+cId;    // script URL - use an absolute path!
	  		}
			else {
				var cmsURL = '/tinymcegalery.php';    						   // nem adunk át semmilyen paramétert akkor a portla common galery-at adja be
			}

	  		tinyMCE.activeEditor.windowManager.open({
	  			file : cmsURL,
	  			title : 'Galéria',
	  			width : 800,  // Your dimensions may differ - toy around with them!
	  			height : 600,
	  			resizable : "yes",
	  			inline : "yes",  // This parameter only has an effect if you use the inlinepopups plugin!
	  			close_previous : "no"
	  		}, {
	  			window : win,
	  			input : field_name
	  		});

	  		win.showPreviewImage(inurl); // elvileg ez csinál preview-t a "borwser" bezárása után

		    return '';
  }

 function tinyMceFile(field_name, url, type, win) {

	  		var connectionTypeField = tinyMCE.selectedInstance.editorId+"_galeryConnectionType";
	  		var connectionIdField = tinyMCE.selectedInstance.editorId+"_galeryConnectionId";

	  		var cType = $('#'+connectionTypeField).val();
	  		var cId = $('#'+connectionIdField).val();

	  		if ( (cType) && (cId) ) {
			    var cmsURL = '/tinymcefile.php?cType='+cType+'&cId='+cId;    // script URL - use an absolute path!
	  		}
			else {
				var cmsURL = '/tinymcefile.php';    						   // nem adunk át semmilyen paramétert akkor a portla common galery-at adja be
			}

	  		tinyMCE.activeEditor.windowManager.open({
	  			file : cmsURL,
	  			title : 'Fájl lista',
	  			width : 800,  // Your dimensions may differ - toy around with them!
	  			height : 600,
	  			resizable : "yes",
	  			inline : "yes",  // This parameter only has an effect if you use the inlinepopups plugin!
	  			close_previous : "no"
	  		}, {
	  			window : win,
	  			input : field_name
	  		});

		    return '';
 }

  function windowOpen(link, width, height) {
	  if (! window.focus)return true;

	  var href;

	  if (typeof(link) == 'string') href=link;
	  else href=link.href;

	  window.open(href, '_blank', 'status=yes,toolbar=yes,menubar=yes,width='+width+',height='+height+',scrollbars=yes,resizable=yes,directories=yes,location=yes');
	  return false;
  }

  /**
   * Meghívja az adott block-hoz tartozó ...Ajax.class.php-t a megfelelő paraméterekkel
   * @param id
   * @param blockId
   * @param blockUrl
   * @return void
   */
  function saveTinyMceContent(id, blockId, blockUrl) {
      D = new Date();
      h = D.getHours();
      if (h<10) { h = "0"+h }
      i = D.getMinutes();
      if (i<10) { i = "0"+i }
      s = D.getSeconds();
      if (s<10) { s = "0"+s }
      if ($("#saveDate").html() == null) { $("#"+id).parent().parent().parent().parent().append('<div style="padding: 1px 3px;">Mentve: <span id="saveDate"></span></div>'); }
      $("#saveDate").html('<b>'+h+':'+i+':'+s+'</b>');
      var data = $('#'+id).val();
      originalContent[id] = data;

      $.post(
     	  blockUrl,
         {
            ajax: blockId,
            tinyMceSave: true,
            content: data
         }
      );
   }

  /**
   * Bookmark save in browser
   * @param title
   * @param url
   * @return
   */
  function bookmarkSite(title, url){
     if (document.all) window.external.AddFavorite(url, title);
     else {
    	 if (window.sidebar) window.sidebar.addPanel(title, url, "");
    	 else alert('Nyomd le Ctrl+D könyvjelző létrehozásához Chrome-ban');
     }
  }

  (function($) {     var cache = [];
     // Arguments are image paths relative to the current page.
     $.preLoadImages = function() {        var args_len = arguments.length;
        for (var i = args_len; i--;) {           var cacheImage = document.createElement('img');
           cacheImage.src = arguments[i];
           cache.push(cacheImage);
        }
     }
  })(jQuery)


   function rate(id, blockId, rate) {
      $.post("/index.php",{
         ajax: blockId,
         id: id,
         rate: rate
      },
      function(resp) {
         $("div#rate_"+id).html(resp);
      });
   }

 //timeout Locker

 var timeOutLocker = 0;




