var BASE_HREF = BASE_HREF || '../';

Cufon.replace('.side-box h2, #slogan, .home-box h2, #intro-box h2, #intro-box .btn-more .in');
Cufon.replace('#main-menu a', { hover: true, textShadow: '0 1px 1px #333;', fontSize: '13px' });

$(document).ready(function()
{
	$('a.lightbox').kfBox();
	$('.dekor-list').each(function(){ 
		$(this).find('a').kfBox();
	});
	$('table tr:nth-child(odd)').addClass('even');			

	
	/* Links */
	$('a.external').bind("click", function() { return !window.open($(this).attr("href"))} );
	$("a.print").bind("click", function() { window.print(); return false; } );
	
	
	$('.dekor-list').each(function()
	{
		if($(this).find('ul>li').size() > 12 * 3)
		{
			var minHeight = 172;			
			var $ul = $(this).find('ul');
			var actualHeight = $ul.height();
			var $switchButton = $('<a href="#" class="btn-expand"><span class="in">zobrazit vše</span></a>');
			$ul.after($switchButton);
			$switchButton.wrap('<div class="expand-box"></div>');
			$ul.height(minHeight).css({ overflow: 'hidden' });
			
			$switchButton.bind('click', function(){
				if($(this).hasClass('btn-expand-expanded'))
				{
					$ul.animate({height: minHeight}, 200);
					$(this).removeClass('btn-expand-expanded').find('.in').html('zobazit vše');
				}
				else
				{
					$ul.animate({height: actualHeight}, 200);
					$(this).addClass('btn-expand-expanded').find('.in').html('skrýt');
				}
				return false;
			});
		}
	});

});

$(window).bind('load', function()
{

	fontSizeListener('#footer', function()
	{
		$('.row-home-bottom').kfEqualizeColumns({ column: '.home-box .inner' });
	});

});

$.fn.kfEqualizeColumns = function(options)
{
	options = $.extend({
		column: '>li' 
	}, options);
	
	return this.each(function(i)
	{
		var $columns = $(options.column, this);
		var maxHeight = 0;
		$columns
			.height('auto')
			.each(function(){
				var h = $(this).height(); 
				if(h > maxHeight) maxHeight = h;  
			})
			.height(maxHeight);
	});
}

function fontSizeListener($el, callback)
{
	$el = $($el);
	var h = 0;
	var interval = setInterval(function()
	{	
		if($el.height() != h){
			h = parseInt($el.height());
			callback();	
		}
	}, 200);	
};

