var layoutSettings_Content={
		center: {
			paneSelector:			".middle-center" 			
		,	minWidth:				200
		,	minHeight:				200
		}
	,	defaults:defNadoLayoutOptions 
	,	west: {
			paneSelector:			".middle-west"
		,	spacing_closed:			21			// wider space when closed
		}
	};
function tinyMCEContentInit(){
  tinyMCECustomInit("content");
};	
function derevoContentInit(){
			tree = new tree_component();
			tree.init($("#menuContent"),{  
				data		:	{ 
				          async : true,
				          type: "json",
				          url : baseurl+"content/admin/getmenu"
               },      
        ui :{      
                  dots :false, 
				          animation	: 500
				},
				rules		: {
					//use_inline	: true,
					use_inline	: false,
					clickable	: "all",
					draggable	: "all",
					deletable	: "all",
					createable : "all",
					dragrules	:"all",
					createat	: "top"
				},
        callback	: {
				 oncreate	: function(NODE,REF_NODE,TYPE,TREE_OBJ) {
            $.getJSON(baseurl+"content/admin/addpunkt","id_parent="+$(REF_NODE).attr('id'), function (data) {
              $(NODE).attr('id',data.id);
              $(NODE).find('a:first').text(data.name).addClass('treeAMy');
            })
         },
				 onrename	: function(NODE, LANG, TREE_OBJ) {
            $.getJSON(baseurl+"content/admin/renamepunkt","id="+$(NODE).attr('id')+"&newname="+$(NODE).find('a:first').html(), function (data) {
            })
         },
         onmove	: function(NODE, REF_NODE, TYPE, TREE_OBJ) 
          {
            $.getJSON(baseurl+"content/admin/movepunkt","id="+$(NODE).attr('id')+"&idto="+$(REF_NODE).attr('id')+"&type="+TYPE, function (data) {
            });
          },
				 ondelete	: function(NODE, TREE_OBJ) {
            $.getJSON(baseurl+"content/admin/deletepunkt","id="+$(NODE).attr('id'), function (data) {
            });
         }
         }
    }); 
    $("#contentTab0 form").submit(function() { 
       idMenu=$(this).find("input[@name=id]").val();
       beforeSubmitContentMenu(idMenu,0);
    }); 
    $("#contentTab1 form").submit(function() { 
       idMenu=$(this).find("input[@name=id]").val();
       beforeSubmitContentMenu(idMenu,1);
    }); 
    $("#contentTab2 form").submit(function() { 
       idMenu=$(this).find("input[@name=id_content]").val();
       beforeSubmitContentMenu(idMenu,2);
    }); 
    $(".addTree").click(function() { tree.create();});
    $(".renameTree").click(function() { tree.rename();});
    $(".deleteTree").click(function() { tree.remove();});
    $(".refreshTree").click(function() { tree.refresh();});
    $(".operationsContent").click(function() {
       objMenuClicked=$("#menuContent li a.clicked").parent();
       attrId=objMenuClicked.attr('id');
       if(attrId)
       {
       $('span.contentBeforeEditBlock').hide();
       $('span.contentEditBlock').hide();
       $('#contentRightPane').addClass('rightPanelHiddyContent');       
       $.getJSON(baseurl+"content/admin/getpunkt","id="+attrId, function (data) {
           $('#contentRightPane span.contentEditBlock span.notShowMap').html(data.name);
           $('#contentRightPane span.contentEditBlock span.formNotShowMap form').find("input[@name=idMenu]").val(data.id);
           if(data.notshowmap==0)
            $('#contentRightPane span.contentEditBlock span.formNotShowMap form').find("input[@name=notshowmap]").attr('checked',false);
           else 
            $('#contentRightPane span.contentEditBlock span.formNotShowMap form').find("input[@name=notshowmap]").attr('checked',true);
           if(data.notshowlink==0)
            $('#contentRightPane span.contentEditBlock span.formNotShowMap form').find("input[@name=notshowlink]").attr('checked',false);
           else 
            $('#contentRightPane span.contentEditBlock span.formNotShowMap form').find("input[@name=notshowlink]").attr('checked',true);
           if(data.notshowmenu==0)
            $('#contentRightPane span.contentEditBlock span.formNotShowMap form').find("input[@name=notshowmenu]").attr('checked',false);
           else 
            $('#contentRightPane span.contentEditBlock span.formNotShowMap form').find("input[@name=notshowmenu]").attr('checked',true);
           $('#contentRightPane').removeClass('rightPanelHiddyContent');
           $('span.contentEditBlock').show();
           $("#contentTab0 form input[@name=link]").val(data.link);
           $("#contentTab1 form span.tinyContent").html("<textarea style='width:90%' class='wysiwyg' ROWS=4 WRAP=VIRTUAL name='content'>"+data.content+"</textarea>");
           $("#contentTab1 form textarea[@name=meta_keywords]").val(data.meta_keywords);
           $("#contentTab1 form textarea[@name=meta_description]").val(data.meta_description);
           $("#contentTab0 form input[@name=id]").val(data.id);
           $("#contentTab1 form input[@name=id]").val(data.id);
           $("#contentTab2 form input[@name=id_content]").val(data.id);
           tinyMCEContentInit();
           $("#idTabMenu option[@value=-1]").attr('selected','true');
           $("#idTabMenu option[@id_content="+data.id+"]").attr('selected','true');
           valSelect=$("#idTabMenu option[@selected]").val();
           if(valSelect!=-1)
            {
             $("ul.contentPages a.tabSelect[@rel=2]").click();
            }
           else 
            {
              if(data.link)
                $("ul.contentPages a.tabSelect[@rel=0]").click();
              else
                $("ul.contentPages a.tabSelect[@rel=1]").click();  
            }
       });
       }
    });
    var flagOpenAllTree=true;
    $(".openAllTree").click(function() { 
           if(flagOpenAllTree)
           {
            openall_recursia(tree);
            flagOpenAllTree=false;
           }
           else
           {
            tree.close_all();
            flagOpenAllTree=true;
           } 
         }); 
         
         
     $.hotkeys.add('n',      { disableInInput: true }, function() { tree.create(); });
     $.hotkeys.add('d',      { disableInInput: true }, function() { tree.remove(); });
     $.hotkeys.add('l',      { disableInInput: true }, function() { tree.cycle_lang(); });
     $.hotkeys.add('r',      { disableInInput: true }, function() { tree.refresh(); });
     $.hotkeys.add('up',     { disableInInput: true }, function() { tree.get_prev(); });
     $.hotkeys.add('down',   { disableInInput: true }, function() { tree.get_next(); });
     $.hotkeys.add('left',   { disableInInput: true }, function() { tree.get_left(); });
     $.hotkeys.add('right',  { disableInInput: true }, function() { tree.get_right(); });
     $.hotkeys.add('return', { disableInInput: true }, function() { tree.select_branch(); });       
}
function beforeSubmitContentMenu(idMenu,flagTab){   
       if(flagTab==2)
        {
         valIdMenu=$("#idTabMenu option[@selected]").val();
         idContentlast=$("#idTabMenu option[@selected]").attr('id_content');
         $("#idTabMenu option[@id_content="+idMenu+"]").attr('id_content','0');
         if(valIdMenu!=-1)
           $("#idTabMenu option[@selected]").attr('id_content',idMenu);
         if(idContentlast!=idMenu && valIdMenu!=-1)
         {
         $.getJSON(baseurl+"content/admin/getpunkt","id="+idContentlast, function (dataNado) {
          if(dataNado.link)
            $('#menuContent').find("li[@id="+idContentlast+"] a:first").css('background-image',"url("+baseurl+"public/content/design/css/page_link.png)");
          else
            $('#menuContent').find("li[@id="+idContentlast+"] a:first").css('background-image',"url("+baseurl+"public/content/design/css/page.png)");
         });
         }
         if(valIdMenu==-1)
         {
         $.getJSON(baseurl+"content/admin/getpunkt","id="+idMenu, function (dataNado) {
          if(dataNado.link)
            $('#menuContent').find("li[@id="+idMenu+"] a:first").css('background-image',"url("+baseurl+"public/content/design/css/page_link.png)");
          else
            $('#menuContent').find("li[@id="+idMenu+"] a:first").css('background-image',"url("+baseurl+"public/content/design/css/page.png)");
         });
         }
         $('#menuContent').find("li[@id="+idMenu+"] a:first").css('background-image',"url("+baseurl+"public/content/design/css/page_gear.png)");
        }
        else
        {
         $("#idTabMenu option[@id_content="+idMenu+"]").attr('id_content','0');   
         if($("#contentTab0 form input[@name=link]").val()!="" && flagTab==0)
            {
             $('#menuContent').find("li[@id="+idMenu+"] a:first").css('background-image',"url("+baseurl+"public/content/design/css/page_link.png)");
            }
         else       
            {
             $('#menuContent').find("li[@id="+idMenu+"] a:first").css('background-image',"url("+baseurl+"public/content/design/css/page.png)");
            }       
        }
}
function initMapContent(){
  $("ul.ulMapContent").each(function (){ 
     $(this).appendTo("ul.ulMapContent li[@idLi="+$(this).attr('idParent')+"]");
  });
  $("div.divContent").show();
}
