$(document).ready(function(){

	//$('.img, p, .wpcf7 form').hide();
	//$('.img, p, .wpcf7 form').fadeIn('fast');

	$(".navigation li a, #header h1 a, #rss a").click(function()
		{ 
			$("#content").css("border-bottom","none");
			//$('.img, p, .wpcf7 form').fadeOut('normal');
			$(".current_page_item a").css("background","#ffffff");
			$(".current_page_item a").stop().animate({backgroundPosition:"(-210px 0px)", color:"#474748"}, {duration:1000, complete:function(){
				$(this).css({backgroundPosition: "-210px 0px"})
			}});
			
		});
	
	$('.navigation li a')
		.css( {backgroundPosition: "-210px 0px"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0px 0px)" , color:"#474748"}, {duration:600})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(-210px 0px)", color:"#474748"}, {duration:600, complete:function(){
				$(this).css({backgroundPosition: "-210px 0px"})
			}})
		})
		
	$('.current_page_item a')
		.css( {backgroundPosition: "-210px 0px"} )
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0px 0px)", color:"#ffffff"}, {duration:600, complete:function(){
				$(this).css({backgroundPosition: "-210px 0px"})
			}})
		})          
});

   

function odump(object, depth, max){
  depth = depth || 0;
  max = max || 2;

  if (depth > max)
    return false;

  var indent = "";
  for (var i = 0; i < depth; i++)
    indent += "  ";

  var output = "";  
  for (var key in object){
    output += "\n" + indent + key + ": ";
    switch (typeof object[key]){
      case "object": output += odump(object[key], depth + 1, max); break;
      case "function": output += "function"; break;
      default: output += object[key]; break;        
    }
  }
  return output;
}    

function addSubCategory()
{
    if($('#addSubCategoryTable').is(":visible"))
    {
        $('#addSubCategoryTable').hide();
        $('#idbtnshowsubcategory').attr("value","Show add subcategory");
    }
    else
    {
        $('#addSubCategoryResult').html('');
        $('#id_category_subcategory').attr("value","");
        $('#subcategory_name').attr("value","");
        $('#subcategory_description').attr("value","");
        $('#subcategory_content').attr("value","");
        $('#addSubCategoryTable').show();
        $('#idbtnshowsubcategory').attr("value","Hide add subcategory");
    }      
}

function addCategory()
{
    if($('#addCategoryTable').is(":visible"))
    {
        $('#addCategoryTable').hide();
        $('#idbtnshowcategory').attr("value","Show add category");
    }
    else
    {
        $('#addCategoryResult').html('');
        $('#id_section_category').attr("value","");
        $('#category_name').attr("value","");
        $('#category_description').attr("value","");
        $('#category_content').attr("value","");        
        $('#addCategoryTable').show();
        $('#idbtnshowcategory').attr("value","Hide add category");
    }    
}

function addSection()
{
    if($('#addSectionTable').is(":visible"))
    {
        $('#addSectionTable').hide();
        $('#idbtnshowsection').attr("value","Show add section");
    }
    else
    {
        $('#addSectionResult').html('');
        $('#id_section').attr("value","");
        $('#section_name').attr("value","");
        $('#section_description').attr("value","");
        $('#section_content').attr("value","");        
        $('#addSectionTable').show();
        $('#idbtnshowsection').attr("value","Hide add section");
    }
}

function doAddSubCategory()
{
    var id_category = $('#id_category_subcategory').val();
    var subcategory_name = $('#subcategory_name').val();
    var subcategory_description = $('#subcategory_description').val();
    var subcategory_content = $('#subcategory_content').val();
    var editor1 = CKEDITOR.instances['subcategory_description'].getData();
    var editor2 = CKEDITOR.instances['subcategory_content'].getData();          
    if(typeof id_category == 'undefined' || id_category=='')
    {
        alert('Please choose the category name!');
        $('#section_name').focus();
        return false;
    }    
    if(typeof subcategory_name == 'undefined' || subcategory_name=='')
    {
        alert('Please complete the subcategory name!');
        $('#subcategory_name').focus();
        return false;
    }  
    if(typeof subcategory_description == 'undefined' || subcategory_description=='' )
    {
        if(typeof editor1 == 'undefined' || editor1=='' )
        {
            alert('Please complete the subcategory description!');
            $('#subcategory_description').focus();
            return false;
        }
    } 
    if(typeof subcategory_content == 'undefined' )
    {
        alert('Please complete the subcategory content!');
        $('#subcategory_content').focus();
        return false;
    }   
    $.post('index.php', { "doAddSubCategory": 1, "id_category": escape(id_category), "editor2": (editor2), "editor1": (editor1), "subcategory_name": (subcategory_name), "subcategory_description": (subcategory_description), "subcategory_content": (subcategory_content) }, function(data) {  $('#addSubCategoryResult').html(data); } );
    tblReset(); 
    return false;     
}

function doAddCategory()
{
    var id_section = $('#id_section').val();
    var category_name = $('#category_name').val();
    var category_description = $('#category_description').val();
    var category_content = $('#category_content').val();
    var editor1 = CKEDITOR.instances['category_description'].getData();
    var editor2 = CKEDITOR.instances['category_content'].getData();          
    if(typeof id_section == 'undefined' || id_section=='')
    {
        alert('Please choose the section name!');
        $('#section_name').focus();
        return false;
    }    
    if(typeof category_name == 'undefined' || category_name=='')
    {
        alert('Please complete the category name!');
        $('#category_description').focus();
        return false;
    }  
    if(typeof category_description == 'undefined' || category_description=='' )
    {
        if(typeof editor1 == 'undefined' || editor1=='' )
        {        
            alert('Please complete the category description!');
            $('#category_description').focus();
            return false;
        }
    } 
    if(typeof category_content == 'undefined' )
    {
        alert('Please complete the category content!');
        $('#category_content').focus();
        return false;
    }   
    $.post('index.php', { "doAddCategory": 1, "id_section": escape(id_section), "editor2": (editor2), "editor1": (editor1), "category_name": (category_name), "category_description": (category_description), "category_content": (category_content) }, function(data) {  $('#addCategoryResult').html(data); } );
    tblReset(); 
    return false;     
}

function doAddSection()
{
    var section_name = $('#section_name').val();
    var section_description = $('#section_description').val();
    var section_content = $('#section_content').val();
    var editor1 = CKEDITOR.instances['section_description'].getData();
    var editor2 = CKEDITOR.instances['section_content'].getData();          
    if(typeof section_name == 'undefined' || section_name=='')
    {
        alert('Please, complete the section name!');
        $('#section_name').focus();
        return false;
    }  
    if(typeof section_description == 'undefined' || section_description=='' )
    {
        if(typeof editor1 == 'undefined' || editor1=='' )
        {        
            alert('Please, complete the section description!');
            $('#section_description').focus();
            return false;
        }
    } 
    if(typeof section_content == 'undefined' )
    {
        alert('Please, complete the section content!');
        $('#section_description').focus();
        return false;
    }   
    $.post('index.php', { "doAddSection": 1, "section_name": (section_name), "editor2": (editor2), "editor1": (editor1), "section_description": (section_description), "section_content": (section_content) }, function(data) {  $('#addSectionResult').html(data); } );
    tblReset(); 
    return false;    
}

function doSectionEdit(id_section,section_name)
{ 
    $.post('index.php', { "doSectionEdit": 1, "id_section": escape(id_section), "section_name": (section_name) }, function(data) {  $('#editSectionTable').html(data); } );
}
function doCategoryEdit(id_category,section_name,category_name)
{
    $.post('index.php', { "doCategoryEdit": 1, "id_category": escape(id_category), "category_name": (category_name) }, function(data) {  $('#editCategoryTable').html(data); } );   
}
function doSubCategoryEdit(id_subcategory,category_name,subcategory_name)
{
    $.post('index.php', { "doSubCategoryEdit": 1, "id_subcategory": escape(id_subcategory), "subcategory_name": (subcategory_name) }, function(data) {  $('#editSubCategoryTable').html(data); } );   
}
function doEditSubCategory(id_subcategory)
{
    var id_category = $('#id_category_edit').val();
    var subcategory_name = $('#subcategory_name_edit').val();
    var subcategory_description = $('#subcategory_description_edit').val();
    var subcategory_content = $('#subcategory_content_edit').val();
    var editor1 = CKEDITOR.instances['subcategory_description_edit'].getData();
    var editor2 = CKEDITOR.instances['subcategory_content_edit'].getData();        
    if(typeof id_category == 'undefined' || id_category=='')
    {
        alert('Please choose the category!');
        $('#id_category_edit').focus();
        return false;
    }     
    if(typeof subcategory_name == 'undefined' || subcategory_name=='')
    {
        alert('Please complete the category name!');
        $('#subcategory_name_edit').focus();
        return false;
    }  
    if(typeof subcategory_description == 'undefined' || subcategory_description=='' )
    {
        alert('Please complete the category description!');
        $('#subcategory_description_edit').focus();
        return false;
    } 
    if(typeof subcategory_content == 'undefined' )
    {
        alert('Please complete the category content!');
        $('#subcategory_content_edit').focus();
        return false;
    }    
    $.post('index.php', { "doEditSubCategory": 1, "id_subcategory": escape(id_subcategory), "editor2": (editor2), "editor1": (editor1), "id_category": escape(id_category), "subcategory_name": (subcategory_name), "subcategory_description": (subcategory_description), "subcategory_content": (subcategory_content) }, function(data) {  $('#editSubCategoryResult').html(data); } );
    tblReset(); 
    return false;      
}
function doEditCategory(id_category)
{
    var id_section = $('#id_section_category').val();
    var category_name = $('#category_name_edit').val();
    var category_description = $('#category_description_edit').val();
    var category_content = $('#category_content_edit').val();
    var editor1 = CKEDITOR.instances['category_description_edit'].getData();
    var editor2 = CKEDITOR.instances['category_content_edit'].getData();        
    var ord_category = $('#ord_category').val();
    if(typeof id_section == 'undefined' || id_section=='')
    {
        alert('Please choose the section!');
        $('#id_section_category_edit').focus();
        return false;
    }     
    if(typeof category_name == 'undefined' || category_name=='')
    {
        alert('Please complete the category name!');
        $('#category_name_edit').focus();
        return false;
    }  
    if(typeof category_description == 'undefined' || category_description=='' )
    {
        alert('Please complete the category description!');
        $('#category_description_edit').focus();
        return false;
    } 
    if(typeof category_content == 'undefined' )
    {
        alert('Please complete the category content!');
        $('#category_content_edit').focus();
        return false;
    }    
    $.post('index.php', { "doEditCategory": 1, "ord_category": ord_category, "id_category": escape(id_category), "editor2": (editor2), "editor1": (editor1), "id_section": escape(id_section), "category_name": (category_name), "category_description": (category_description), "category_content": (category_content) }, function(data) {  $('#editCategoryResult').html(data); } );
    tblReset(); 
    return false;      
}
function doEditSection(id_section)
{         
    var section_name = $('#section_name_edit').val();
    var section_description = $('#section_description_edit').val();
    var editor1 = CKEDITOR.instances['section_description_edit'].getData();    
    var editor2 = CKEDITOR.instances['section_content_edit'].getData();
    var section_content = $('#section_content_edit').val();
    var ord_section = $('#ord_section').val();
    if(typeof section_name == 'undefined' || section_name=='')
    {
        alert('Please complete the section name!');
        $('#section_name_edit').focus();
        return false;
    }  
    if(typeof section_description == 'undefined' || section_description=='' )
    {
        alert('Please complete the section description!');
        $('#section_description_edit').focus();
        return false;
    } 
    if(typeof section_content == 'undefined' )
    {
        alert('Please complete the section content!');
        $('#section_content_edit').focus();
        return false;
    }    
    $.post('index.php', { "doEditSection": 1, "id_section": escape(id_section), "ord_section": ord_section, "section_name": (section_name), "editor2": (editor2), "editor1": (editor1), "section_description": (section_description), "section_content": (section_content) }, function(data) {  $('#editSectionResult').html(data); } );
    tblReset(); 
    return false;       
}

function doSectionDelete(id_section,section_name)
{
    if(confirm('Are you sure you want to delete section \''+section_name+'\' ?'))
    {
        $.post('index.php', { "doSectionDelete": 1, "id_section": escape(id_section), "section_name": (section_name) }, function(data) {  $('#editSectionTable').html(data); setTimeout('$(\'#editSectionTable\').html(\'\');', 10000); } );
        tblReset();    
    }
    return false;
}

function doCategoryDelete(id_category,section_name,category_name)
{
    if(confirm('Are you sure you want to delete category \''+category_name+'\' from section \''+section_name+'\' ?'))
    {
        $.post('index.php', { "doCategoryDelete": 1, "id_category": escape(id_category), "category_name": (category_name) }, function(data) {  $('#editCategoryTable').html(data); setTimeout('$(\'#editCategoryTable\').html(\'\');', 10000); } );
        tblReset();    
    }
    return false;
}

function doSubCategoryDelete(id_subcategory,category_name,subcategory_name)
{
    if(confirm('Are you sure you want to delete subcategory \''+subcategory_name+'\' from category \''+category_name+'\' ?'))
    {
        $.post('index.php', { "doSubCategoryDelete": 1, "id_subcategory": escape(id_subcategory), "subcategory_name": (subcategory_name) }, function(data) {  $('#editSubCategoryTable').html(data); setTimeout('$(\'#editSubCategoryTable\').html(\'\');', 10000); } );
        tblReset();    
    }
    return false;
}
