$.globalData = {
    saved : "",
    closedWarning : ""
} 		

Cufon.replace("h1");

/* Czech initialisation for the jQuery UI date picker plugin. */
/* Written by Tomas Muller (tomas@tomas-muller.net). */
jQuery(function($){
	$.datepicker.regional['cs'] = {
		closeText: 'Zavřít',
		prevText: '&#x3c;Dříve',
		nextText: 'Později&#x3e;',
		currentText: 'Nyní',
		monthNames: ['leden','únor','březen','duben','květen','červen',
        'červenec','srpen','září','říjen','listopad','prosinec'],
		monthNamesShort: ['led','úno','bře','dub','kvě','čer',
		'čvc','srp','zář','říj','lis','pro'],
		dayNames: ['neděle', 'pondělí', 'úterý', 'středa', 'čtvrtek', 'pátek', 'sobota'],
		dayNamesShort: ['ne', 'po', 'út', 'st', 'čt', 'pá', 'so'],
		dayNamesMin: ['ne','po','út','st','čt','pá','so'],
		dateFormat: 'dd.mm.yy', firstDay: 1,
		isRTL: false};
	$.datepicker.setDefaults($.datepicker.regional['cs']);
});

function toggleEditor(id) {
	if (!tinyMCE.get(id))
		tinyMCE.execCommand('mceAddControl', false, id);
	else
		tinyMCE.execCommand('mceRemoveControl', false, id);
}

function doPopUp(msg, saving) {
	
	
	if(saving) {
		$("body").append('<div id="popAlert"><div id="popAlertText"></div></div>');
        $('#popAlertText').html(saving)
        .fadeIn('2000')
        .animate({opacity: 1.0}, 1000)
        .fadeOut('fast', function() {
        	$('#popAlertText').show();
        	$('#popAlertText').html(msg)
        });
	} else {
		$("body").append('<div id="popAlert"><div id="popAlertText"></div></div>');
	    $('#popAlertText').html(msg)
	}
	$(function () {

		var $alert = $('#popAlert');
		if($alert.length)
		{
			var alerttimer = window.setTimeout(function () {
				$alert.trigger('click');
			}, 5000);
			$alert.animate({height: $alert.css('line-height') || '50px'}, 200)
			.click(function () {
				window.clearTimeout(alerttimer);
				$alert.animate({height: '0'}, 200);
			});
		}
	});
}

$(document).ready(function(){
  // revize textu - zobrazeni skrytych polozek
	$('#showHiddenRevision').click(function() {	
	
    $(".hiddenRevision").css("display", "block");     // zobrazit skryte
    $('#showHiddenRevision').css("display", "none");  // skryt vyzvu
  	return false;
	}); 
	
	
	// menu
	$('#cmsMenu li').hover(
		
    function() { 
      $('ul', this).css('display', 'block');
      $(this).addClass('navOn'); 
    },
    
		function() { 
      $('ul', this).css('display', 'none');
      $(this).removeClass('navOn');  
    }
  );		
  
  // table 
	$('table tbody tr').hover(
		
    function() { 
      $(this).addClass('rowActive'); 
    },
    
		function() { 
      $(this).removeClass('rowActive');  
    }
  );	  
	
	
  // confirm 
	$('.confirm').click(function() {
    
    var response = confirm($(this).attr('title'));  
    return response;		
	});  	
	
	$(function(){ 
		  
		  settings = {
		          tl: { radius: 12 },
		          tr: { radius: 12 },
		          bl: { radius: 12 },
		          br: { radius: 12 },
		          antiAlias: true,
		          autoPad: true,
		          validTags: ["div"]
		      }


		  $('#content').corner(settings);
		  
	});
	/*
	$("input[name*='title']").get(0).focus();
	$("input[name*='name_obj']").get(0).focus();
	*/
	
	
	// externi odkazy
  $('a[rel="external"]').click(function(){
		window.open( $(this).attr('href') );
    return false;
	})
	
	
});




/*
  AJAX - table list
*/
function runAjaxRequest(href, postData) {

    $.ajax({
    
      type: "POST",
      url: href,
      data: postData,
      async: true,    
            
      success: function(msg) {         
        $('#ajaxWrap').html(msg);   
        runAjaxList();      
      },
      
      error: function (msg) {               
      }
      
    });

}

function runAjaxList() {

  var href = $("form").attr('action');
  
	$(".paginationControl a").click(function() {
      
    var href = $(this).attr('href');  
    var postData = $('form').serialize();      
    runAjaxRequest(href, postData);
  
    return false;			
  });  
  
  
	$("#setItemCount").change(function() {
    
    var postData = $('form').serialize();
    runAjaxRequest(href, postData);
            
    return false;			
  });    
  
	$("#searchBtn").click(function() {
    
    var postData = $('form').serialize();          
    runAjaxRequest(href, postData);
        
    return false;			
  });     
  
	$("#deleteCheckedBtn").click(function() {
      
    var response = confirm('Opravdu chcete smazat');  
    if (!response) {
      return false;
    }
    
    var hrefDelete = href+'/mode/delete';
    var postData = $('form').serialize();		          
    runAjaxRequest(hrefDelete, postData);            
    
    return false;			
  });   
  
  // hromadne ozanceni/odznaceni
	$("#checkAllDeleteBtn").change(function() {
    
    $(':checkbox').attr('checked', $("#checkAllDeleteBtn").attr('checked'));    
  }); 
}
/*
  AJAX - table list - END
*/