$.global = {
	/*image upload crossmodel*/
    idmodul_img : "",
    modul_img : "",
    tab_select : "",
} 



/*tab function*/

function initTabs(tabClass) {
	
	if(!tabClass) {
	 var tabClass = ".contentTabs"	
	}
	
  // Enable tabs on all tab widgets. If you define a callback for the 'select'
  // event, it will be executed for the selected tab whenever the hash changes.
  $(tabClass).tabs();
  
  // Define our own click handler for the tabs, overriding the default.
  $(tabClass+' .ui-tabs-nav a').click(function(){
    var state = {},
      
      // Get the id of this tab widget.
      id = $(this).closest( tabClass ).attr( 'id' ),
      
      // Get the index of this tab.
      idx = $(this).parent().prevAll().length;
    
    // Set the state!
    state[ id ] = idx;
    $.bbq.pushState( state );
    
    // And finally, prevent the default link click behavior by returning false.
    return false;
  });
  

  // Bind an event to window.onhashchange that, when the history state changes,
  // iterates over all tab widgets, changing the current tab as necessary.
  $(window).bind( 'hashchange', function(e) {
    
    // Iterate over all tab widgets.
    $(tabClass).each(function(){
      
      // Get the index for this tab widget from the hash, based on the
      // appropriate id property. In jQuery 1.4, you should use e.getState()
      // instead of $.bbq.getState(). The second, 'true' argument coerces the
      // string value to a number.
      var idx = $.bbq.getState( this.id, true ) || 0;
      
      // Select the appropriate tab for this tab widget (you could keep track of
      // what tab each widget is on using .data, and only select a tab if it has
      // changed).
      $(this).tabs( 'select', idx );
    });
  })
  
  // Since the event is only triggered when the hash changes, we need to trigger
  // the event now, to handle the hash the page may have loaded with.
  $(window).trigger( 'hashchange' );

}



//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 initListHover() {
	$(".listLeftSide").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");
      }
  	);
	
}
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:      '5px', 
	        right:     '10px', 
	        left:    '', 
	        border:   'none', 
	        padding:  '5px', 
	        opacity:   0.8, 
	        cursor:    null, 
	        color:    '#fff', 
	        backgroundColor: '#000', 
	        'z-index':	'1000',
	        '-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;

/*
function initTreeColapsed() {
	$("#radioTree").treeview({
		//control: "#treecontrol",
		persist: "cookie",
		cookieId: "treeview-black"
		//collapsed: true
	});
}
*/
$(document).ready(function(){
	
	initListHover();
	//initTreeColapsed();
	
  // form highlight	
  $(':input:not([type="submit"])').each(function() {
      $(this).focus(function() {
          $(this).addClass('formFieldFocus');
      }).blur(function() {
          $(this).removeClass('formFieldFocus');});
  });	
		    	
	
	$("input#search").ezpz_hint();
	
	
	$("input").attr("autocomplete", "off");
		
		/*
      layout
    */
     
/*
     
  	outerLayout = $('body').layout({
  			
  				west__size:			180
  			, 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:	17
			, resizeWhileDragging: true 




  			
  			,	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:			360
  			, west__fxName: "none"
			, resizeWhileDragging: true 
    //,	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:	17
    			


    			
    			
  			,	useStateCookie:		true
  			, cookie__name : "layoutEast"
  			  			  
  		});
  		
  		if ($('.center-west').length > 0) {
        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  		
			, resizeWhileDragging: true 
    		}); 	
      }

      	
  		innerLayout3 = $('div.center-center').layout({ 
  			center__paneSelector:	".mainColContent" 
  		,	north__paneSelector:		".mainColTop" 
  		,	north__resizable:			false
  		,	north__minSize:		23
  		,	north__spacing_open:		0
		, resizeWhileDragging: true 
  	
  		}); 
*/
	 /*
    layout END
   */	
	



// layout wave test


    /* Main Page Layout */
    mainLayout = $('body').layout({
        name: "outerLayout",
        triggerEventsOnLoad: true,
        resizeWhileDragging: true,
        resizeWithWindowDelay: 250, // ms
        noRoom: false,
        useStateCookie: false, // enable state-management - automatic!
        cookie__keys: "west.size,west.isClosed",

        // pane defaults
        closable: false,
        resizable: true,
        slidable: false,
        spacing_open: 0,
        triggerEventsWhileDragging: false,
        resizeContentWhileDragging: false, // default 
		// content selector
		contentSelector: ".content",
		//showOverflowOnHover: true,

        // top Pane
        north__paneSelector: "#top",
		north__size: 70,
		north__togglerLength_open: 0,
		north__togglerLength_close: -1,
		north__resizable: false,
		north__slidable: false,
		north__spacing_open: 0,
		north__showOverflowOnHover: true,


        // menu Pane
        west__paneSelector: "#filter",
        west__size: 170,
        west__minSize: 170,
        west__maxSize: 250,
        west__spacing_open: 13,
        west__closable: true,
        west__resizable: true,


        // List Pane
        center__paneSelector: "#list",
        center__size: 220,
        center__minWidth: 220,
        center__maxWidth: 300,
        center__spacing_open: 13,

        // Details Pane
        east__paneSelector: "#detail",
        east__size: "67%",
        east__minWidth: 450,
        east__spacing_open: 13
        
        
    });



// layout wave test END











	$(window).resize(function() {
	   var bodyHeight = $('body').height();
	   
	   if(bodyHeight < "500") {
		   var lastVisiblePortlet = $(".panelsBottomPadding:last:visible");
		   
		   $(".portlet-content", lastVisiblePortlet).hide();
		   $(".ui-icon", lastVisiblePortlet).removeClass("ui-icon-minusthick");
		   
		   if(bodyHeight < "300") {
			   var allPortlets = $(".panelsBottomPadding:visible");
			   
			   $(".portlet-content", allPortlets).hide();
			   $(".ui-icon-plusthick", allPortlets).removeClass("ui-icon-minusthick");
		   }
		   
	   }
	   
	   if(bodyHeight > "500") {
		   var hiddenPortlers = $(".panelsBottomPadding:hidde");
		   
		   $(".portlet-content", hiddenPortlers).show();
		   $(".ui-icon", allPortlets).addClass("ui-icon-minusthick");
	   }
	   
	});
































	

	 $(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, '', '', 'html')
				
		      }
		    }); 
	    
		$(".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 idString = $(this).parents(".pane").attr("id").split("_");
					
			var id = idString[1];
						
			$(this).parents(".portlet:first").find(".portlet-content").toggle(null, null, null, $.get(f13_baseUrl+"admin/panels/panel-status/id/"+id+"/status/"+status, '', '', 'html'));
		}); 	 
	 
		});

	 
	


	
	
	
	
	
	
	// 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;
	})

	
	$("#detail-resizer").append('<div class="detailResizerTop"></div>');
	
});




/*
  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
*/
