$(document).ready(function()
{
	$.fn.kfBox && $('.lightbox').kfBox();

	$('table tr:nth-child(even)').addClass('even');

	$('#q').inputDefaultText({ text: 'Hledaný výraz'});

	$('a.external').click(function(){return !window.open($(this).attr("href"))});

	$.fn.cycle && $('#motive-box').cycle({
		fx: 'fade',
		speed: 2000,
		timeout: 5000
	});

	$('a.taconite').live('click', function(){
		$(this).parents('ul').eq(0).find('a').removeClass('active').parent().removeClass('active');
		$(this).addClass('active').parent().addClass('active');
		$(this.rel).html('<div class="loading">Nahrávám…</div>');
		$.get(this.href, function(){
			$('.col-products-c').find('.item').eq(0).addClass('item-active');
			$('.row').kfEqualizeColumns({ column: '.col-products-a .blblist, .col-products-b .blblist, .col-products-c .blblist' });
		});
		return false;
	});
	
	$('.col-products-b a').live('mouseover', function(){
		var i = $(this).parents('ul').find('a').index(this);
		$('.col-products-c').find('.item-active').removeClass('item-active').end().find('.item').eq(i).addClass('item-active');
		$('.row').kfEqualizeColumns({ column: '.col-products-a .blblist, .col-products-b .blblist, .col-products-c .blblist' });
		return false;
	});
	
	$('.col-products-b a').eq(0).each( function(){
		var i = $(this).parents('ul').find('a').index(this);
		$('.col-products-c').find('.item-active').removeClass('item-active').end().find('.item').eq(i).addClass('item-active');
		$('.row').kfEqualizeColumns({ column: '.col-products-a .blblist, .col-products-b .blblist, .col-products-c .blblist' });
		return false;
	});
	$('.row').kfEqualizeColumns({ column: '.col-products-a .blblist, .col-products-b .blblist, .col-products-c .blblist' });
	
	$('.flash-player').each(function(){
 		flashsize = $(this).find('a').attr('data-flashsize');
 		flashsize = flashsize.split("x");
 		$(this).flash(
        {
             src: '/inc/flash/player.swf',
             width: flashsize[0],
             height: flashsize[1],
             wmode: 'opaque',
             allowfullscreen: true,
             flashvars: {file: $(this).find('a').attr('href'), searchbar: 'false', autostart: 'false', frontcolor: '0x666666', image: $(this).find('img').attr('src')}
        });
     	// nebudeme zobrazovat alt
     	$(this).find('.alt').css("display","none");
	});
	
});

$.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);
	});
}
