$.globalData = {
    saved : "",
    closedWarning : "",
    clicked : 0,
    
} 		

function f13_ajax(url, data, type) {

	var type = (type == null) ? "POST" : type;

	
	
	$.ajax({
	      type: type,
	      url: url,
	      data: data,
	      dataType: json,
	      async: true,          
	      success: function(msg) {   
			return msg;
	      },
	      error: function (msg) {
	    	  
	      }
	   });


}

function f13_search(url) {
	var ret = f13_ajax(url, "a");
	
	alert(ret);
	return ret;
}



function dump(arr,level) {
	var dumped_text = "";
	if(!level) level = 0;
	
	//The padding given at the beginning of the line.
	var level_padding = "";
	for(var j=0;j<level+1;j++) level_padding += "    ";
	
	if(typeof(arr) == 'object') { //Array/Hashes/Objects 
		for(var item in arr) {
			var value = arr[item];
			
			if(typeof(value) == 'object') { //If it is an array,
				dumped_text += level_padding + "'" + item + "' ...\n";
				dumped_text += dump(value,level+1);
			} else {
				dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
			}
		}
	} else { //Stings/Chars/Numbers etc.
		dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
}




//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);
			});
		}
	});
}

function blockElement(elementName, text) {

}


function growl(msg, title) {
	if(!title) {
		var title = "Notifikace";
	}
	// override these in your code to change the default behavior and style 
	$.blockUI.defaults = { 
	    // styles applied when using $.growlUI 
	    growlCSS: { 
	        width:    '350px', 
	        top:      '10px', 
	        left:     '10px', 
	        right:    '', 
	        border:   'none', 
	        padding:  '5px', 
	        opacity:   0.8, 
	        cursor:    null, 
	        color:    '#fff', 
	        backgroundColor: '#000', 
	        '-webkit-border-radius': '10px', 
	        '-moz-border-radius':    '10px' 
	    }, 
	}; 
	$.growlUI(title, msg); 
}

function external() {
	  
	  $('a[rel="external"]').click(function(){
		  
			window.open( $(this).attr('href') );
	    return false;
		})
}

var outerLayout, eastLayout, innerLayout2, innerLayout3;

$(document).ready(function(){

	
	
	
	$("#test").click(function() {
		var test = f13_search(url+"admin/index/test/");		
	});
	// 
	$("#radioTree").treeview({
		//control: "#treecontrol",
		persist: "cookie",
		cookieId: "treeview-black"
		//collapsed: true
	});
  
  	
	
	$("input#search").ezpz_hint();
	
	
	$("input").attr("autocomplete", "off");

	$(".itemsListItem").click(function() {
		$(this).fadeOut('fast', function(){ $(this).fadeIn('fast').html('<div class="itemAjaxLoading">Probíhá nahrávání...</div>')});
	});
	
	
    $(".itemsListItem").hover(
      function () {
        $(this).addClass("listHover");
      }, 
      function () {
        $(this).removeClass("listHover");
      }
  	);
		
		/*
      layout
    */
     

     
  	outerLayout = $('body').layout({
  			
  				west__size:			200
  			, west__fxName: "none"
  			,	north__size:				70
  			,	north__togglerLength_open:	0
  			,	north__togglerLength_close:	-1
  			,	north__resizable:			false
  			,	north__slidable:			false
  			,	north__spacing_open:		0
  			, north__showOverflowOnHover:	true
  			, spacing_open:	12




  			
  			,	center__onresize:		'eastLayout.resizeAll'
 	  		
  
  			,	useStateCookie:		true
  			, cookie__name : "layoutOuter"
    			
  		});
  		

  		eastLayout = $('div.ui-layout-center').layout({
  
  				center__paneSelector:	".center-center"
  			,	west__paneSelector:	".center-west"
  			,	west__size:			300
  			, west__fxName: "none"
        
    //,	west__spacing_open:			9			// wider space when closed
	   	,	west__spacing_closed:	  12			// wider space when closed
		
	//	,	west__togglerLength_open:		0			// NONE - using custom togglers INSIDE west-pane

	//	, west__initClosed:						true
	
		, west__togglerLength_closed: -1
		, west__togglerLength_open: -1
		,	west__togglerAlign_open:	"top"		// align to top of resizer
		,	west__togglerAlign_closed:	"top"		// align to top of resizer
		
		,	west__togglerTip_open:		"Zavřít"
		,	west__togglerTip_closed:		"Otevřít"
		,	west__resizerTip_open:		"Resize West Pane"
		,	west__slideTrigger_open:		"click" 	// default
		

      	
      	,	west__onresize:		'innerLayout2.resizeAll'
      	,	center__onresize:		'innerLayout3.resizeAll'
      	
        , spacing_open:	12
    			


    			
    			
  			,	useStateCookie:		true
  			, cookie__name : "layoutEast"
  			  			  
  		});
  		
     eastLayout.addToggleBtn( "#centerWestToogler", "west" );  		


  		  		
  		
  		
  		innerLayout2 = $('div.center-west').layout({ 
  			center__paneSelector:	".listColContent" 
  		,	north__paneSelector:		".listColTop" 
  		,	north__resizable:			false
  		,	north__minSize:		23
  		,	north__spacing_open:		0  		
  	
  		}); 	
  		
  		innerLayout3 = $('div.center-center').layout({ 
  			center__paneSelector:	".mainColContent" 
  		,	north__paneSelector:		".mainColTop" 
  		,	north__resizable:			false
  		,	north__minSize:		23
  		,	north__spacing_open:		0
  	
  		}); 	  		



	 /*
    layout END
   */	
		

	 $(function() {
	    $("#ordering").sortable({
		      axis: 'y',
		      opacity: 0.6,	
		      handle: ".portlet-header",
		      placeholder: 'ui-state-highlight',
		      forcePlaceholderSize: true,
		      update : function () {
				var order = $('#ordering').sortable('serialize');		
				$.get(f13_baseUrl+"admin/panels/panel-order/?"+order)
				
		      }
		    }); 
	    
		$(".portlet").addClass("ui-widget ui-widget-content ui-helper-clearfix ui-corner-all")
		.find(".portlet-header")
			.addClass("ui-widget-header ui-corner-all")
			.end()
		.find(".portlet-content");
		
		

		$(".portlet-header .ui-icon").click(function() {
			$(this).toggleClass("ui-icon-minusthick");
			
			var status = $(this).parents(".portlet:first").find(".portlet-content").is(':hidden');
			var id = $(this).parent().parent().parent().attr("id");
						
			$(this).parents(".portlet:first").find(".portlet-content").toggle(null, null, null, $.get(f13_baseUrl+"admin/panels/panel-status/id/"+id+"/status/"+status));
		}); 	 
	 
		});

	 
	


	
	
	
	
	
	
	// externi odkazy
	external();
	
  // revize textu - zobrazeni skrytych polozek
	$('#showHiddenRevision').click(function() {	
	
    $(".hiddenRevision").css("display", "block");     // zobrazit skryte
    $('#showHiddenRevision').css("display", "none");  // skryt vyzvu
  	return false;
	}); 
	
	
	// menu
	
	$('#cmsMenu').hover(
		
    function() { 
      $(this).addClass('menuOver'); 
    },    
		function() { 
      $(this).removeClass('menuOver');  
    }
  );		
	
	$('#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
*/