function adjustHeightsPhotogaleryAlbum()  {
  var idEl = 'album';
  var insideLiTag = 'span';
  var columns = 3;
  if($(idEl) == null) return;

  var elements = $(idEl).getElements('li');
  var numItems = elements.length;
  var rows = Math.ceil(numItems/columns);

  // odkazy v nadpisech
  var links = $$('#album li h2 span a');
  var h = [];
  var count = 1;   
  links.each(function(item, index){
    item.setStyle('height','auto');
    var s = item.getSize();
    h.push(s.y - 12 - 12);
  });
  var rep = 1;
  for (l = 1; l <= rows; l++) {
    hSlice = h.slice(count-1,columns*l);
    hSlice.sort( function (a,b) { return b-a });
    for (i = 0; i < hSlice.length; i++) {
      $$('#'+idEl+' li:nth-child('+rep+') h2 span a' ).setStyle('height', hSlice[0]+'px');
      rep++;
    }
    count = l*columns+1;
  }
}

function adjustHeightsGuidepost()  {
  var idEl = 'rozcestnik';
  var insideLiTag = 'span';
  var columns = 3;

  if($(idEl) == null) return;

  var elements = $(idEl).getElements('li');
  var numItems = elements.length;
  var rows = Math.ceil(numItems/columns);

  // odkazy v nadpisech
  var links = $$('#rozcestnik li h2 span a');
  var h = [];
  var count = 1;   
  links.each(function(item, index){
    item.setStyle('height','auto');
    var s = item.getSize();
//     var top = item.getStyle('padding-top');
//     var bottom = item.getStyle('padding-bottom');
//     if (top.test('em')) top = top.toFloat()*14;
//     else top = top.toInt();
//     if (bottom.test('em')) bottom = bottom.toFloat()*14;
//     else bottom = bottom.toInt();
    h.push(s.y - 12 - 15);
  });
  var rep = 1;
  for (l = 1; l <= rows; l++) {
    hSlice = h.slice(count-1,columns*l);
    hSlice.sort( function (a,b) { return b-a });
    for (i = 0; i < hSlice.length; i++) {
      $$('#'+idEl+' li:nth-child('+rep+') h2 span a' ).setStyle('height', hSlice[0]+'px');
      rep++;
    }
    count = l*columns+1;
  }

  // texty
  var contents = $$('#rozcestnik li div.obsah');  
  var h = [];
  var count = 1; 
  contents.each(function(item, index){
    item.setStyle('height','auto');
    var s = item.getSize();
    h.push(s.y - 12 - 15);
  });
  var rep = 1;
  for (l = 1; l <= rows; l++) {
    hSlice = h.slice(count-1,columns*l);
    hSlice.sort( function (a,b) { return b-a });
    for (i = 0; i < hSlice.length; i++) {
      $$('#'+idEl+' li:nth-child('+rep+') div.obsah' ).setStyle('height', hSlice[0]+'px');
      rep++;
    }
    count = l*columns+1;
  }
}


function adjustHeights()  {
  var idEl = 'rozcestnik';
  var insideLiTag = 'span';
  var columns = 3;

  if($(idEl) == null) return;

  var elements = $(idEl).getElements('li');
  var numItems = elements.length;
  var rows = Math.ceil(numItems/columns);
  var count = 1; 
  var heightItems = [];
  var h = [];
  
  /****************************************************************************************
   * Rozsireni funkcionality, pokud je potreba nastaveni vysek elementu, uvnitr elementu li 
   ****************************************************************************************     
  // Ziskani vsech vysek vnitrnich tagu            
  elements.each(function(item, index){
    item.getElement(insideLiTag).setStyle('height','auto');
    
    var s = item.getElement(insideLiTag).getSize();
    h.push(s.y);
  });
  
  // Nejvetsi vyska vnitrnich tagu je nastavena pro ostatni tagy na jednom radku
  var rep = 1;
  for (l = 1; l <= rows; l++) {
    hSlice = h.slice(count-1,columns*l);
    hSlice.sort( function (a,b) { return b-a });

    for (i = 0; i < hSlice.length; i++) {
      $$('#'+idEl+' li:nth-child('+rep+') '+insideLiTag ).setStyle('height', hSlice[0]+'px');
      rep++;
    }

    count = l*columns+1;
  } */
  
  
  // Ziskani vsech vysek li tagu
  elements.each(function(item, index){
    item.setStyle('height','auto');
    
    var size = item.getSize();
    heightItems.push(size.y);
  });
  
  // Nejvetsi vyska li tagu je nastavena pro ostatni tagy li na jednom radku
  rep = 1;
  count = 1;
  for (l = 1; l <= rows; l++) {
    heightItemsSlice = heightItems.slice(count-1,columns*l);
    heightItemsSlice.sort( function (a,b) { return b-a });

    for (i = 0; i < heightItemsSlice.length; i++) {
      $$('#'+idEl+' li:nth-child('+rep+')').setStyle('height', (heightItemsSlice[0])+'px');
      if(i == heightItemsSlice.length-1 ) $$('#'+idEl+' li:nth-child('+rep+')').addClass('last_item_row');

      rep++;
    }

    count = l*columns+1;
  }
}





function adjustHeightsAlbum() {
  var idEl = 'album';
  var itemsH3 = 'h3';
  var columns = 5;
  var container = $(idEl);
  
  if(container == null) return;  
  
  var elements = container.getElements('li');
  var numItems = elements.length;
  var rows = Math.ceil(numItems/columns);
  var count = 1; 
  var heightItems = [];
  var heightItemsH3 = []; 
  
  // Ziskani vsech vysek vnitrnich tagu            
  elements.each(function(item, index){
    item.getElement(itemsH3).setStyle('height','auto');
    item.setStyle('height','auto');
    
    var sizeH3 = item.getElement(itemsH3).getSize();
    var size = item.getSize();
    
    heightItemsH3.push(sizeH3.y);
    heightItems.push(size.y);
  });
  
  
  // Nejvetsi vyska li a h3 tagu je nastavena pro ostatni na jednom radku
  rep = 1;
  count = 1;
  for (l = 1; l <= rows; l++) {
    heightItemsSlice = heightItems.slice(count-1,columns*l);
    heightItemsSlice.sort( function (a,b) { return b-a });
    
    heightItemsH3Slice = heightItemsH3.slice(count-1,columns*l);
    heightItemsH3Slice.sort( function (a,b) { return b-a });    

    for (i = 0; i < heightItemsSlice.length; i++) {
      $$('#'+idEl+' li:nth-child('+rep+')').setStyle('height', (heightItemsSlice[0])+'px');
      $$('#'+idEl+' li:nth-child('+rep+') h3').setStyle('height', (heightItemsH3Slice[0])+'px');
      if(i == heightItemsSlice.length-1 ) $$('#'+idEl+' li:nth-child('+rep+')').addClass('last_item_row');
      
      rep++;
    }

    count = l*columns+1;
  }  
  

}







function fontSizeListener() {
	height = 0;
	checkSize = function()  {    			
		element = document.getElementById('kontejner_menu_w');
		if(element.offsetHeight != height){
			height = parseInt(element.offsetHeight);
			adjustHeightsGuidepost();
			adjustHeightsPhotogaleryAlbum();
			//adjustHeights();
      //adjustHeightsAlbum();					
		}
	};
	
	fontSizeInterval = setInterval(checkSize, 100);			
};

window.addEvent('domready', function() {
    //adjustHeights();
    //adjustHeightsAlbum();
    adjustHeightsPhotogaleryAlbum();
    adjustHeightsGuidepost();
    fontSizeListener();
});

