var BASE_HREF = BASE_HREF || '../';


Cufon.replace('.side-box h2', { textShadow: '0 -1px 0 #001c61' } );
Cufon.replace('.side-box-gears h2, .clients-box h2', { textShadow: '0 1px 0 #fff' });

$(document).ready(function()
{
	$('a.lightbox').kfBox();			
	$('table tr:nth-child(odd)').addClass('even');

	$('#print').html('<a href="#">Tisk strany</a> &nbsp; | &nbsp;').find('a').bind('click', function() { window.print(); return false; } );
	
	$('#q').inputDefaultText({ text: 'Hledaný výraz'});
		
	$(document).delegate('.tab-menu a', 'click', function(event){
		$e = $(event.currentTarget);		
		$($e.attr('href')).show();
		$e.closest('li').addClass('active');
		$e.parents('.tab-menu').find('a').not($e).each(function(){ $($(this).attr('href')).hide(); }).closest('li').removeClass('active');
		return false;
	});
	$('.tab-menu a').eq(0).trigger('click');
	
	/* Inicializace scrollovátka */
	var $prevnext = $('<div class="prevnext"><a href="#" class="prev">předchozí</a> <a href="#" class="next">další</a></div>');
    $('.clients-carousel').append($prevnext);
    var imageScroller = new kff.widgets.Scroller('.clients-carousel .hscroll-box', {
		carousel: 'ul',
		items: 'li',
		prev: '.prev',
		next: '.next',
		scrollWidth: 470,
		carouselWidth: 470
	});
	imageScroller.activate();
		
});

$(window).load(function(){

	if($.fn.cycle)
	{
		$('.motives').cycle({
			fx: 'scrollRight',
			speed: 1000,
			timeout: 10000
		});
	}
	
	fontSizeListener('#main', function()
	{
		$('.home-bottom').kfEqualizeColumns({ column: '.side-box' });
	});
});

$.fn.inputDefaultText = function(options)
{
	options = $.extend({
		text: 'Hledany vyraz'
	}, options);

	return this
		.val(options.text)
		.bind('focus', function(){ if(this.value == options.text) this.value = ''; })
		.bind('blur', function(){ if(this.value == '') this.value = options.text; });
};

$.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);
};

