$(document).ready(function() {
	
	// LIGHTBOX
	
	$(function() {
        $('#gallery a').lightBox();
    });
	
	// GALERY
	
	$('<div class="clearer"></div>').insertAfter('#gallery a:odd');
	
	// MENU
	
	$('#menu ul').find('a:last').css('border-left', 'none').end().find('a:first').css('border-right', 'none');
	
	// FILTER
	
	if($('#filter-more-button').attr('rel') == 0) {
		$('#filter').css('background-position', '-552px 0px');
		$('#filter .second-table').hide();
		$('#filter-more-button').css('background-image', 'url(/images/structure/add.png)').html('Více možností');;
	}
		
	$('#filter-more-button').click(function() {
		
		if($(this).attr('rel') == 0) {
			$('#filter').css('background-position', '0px 0px');
			$('.second-table').show();
			$(this).attr('rel', 1).css('background-image', 'url(/images/structure/min.png)').html('Méně možností');
		} else {
			$('#filter').css('background-position', '-552px 0px');
			$('#filter .second-table').hide();
			$(this).attr('rel', 0).css('background-image', 'url(/images/structure/add.png)').html('Více možností');
		} // end: if
		
		return false;
	});
	
	// ORDER BY SELECT INPUT
	
	$("select[name='orderSelect']").change(function() {
	var orderValue = $(this).find('option:selected').attr('value');
		$.post( '/inc/scripts/setSession.php', { 'sessionName': 'orderBy', 'value': orderValue }, function(data) { 
			location.reload();					
		});
	});
	
	$("select[name='sortSelect']").change(function() {
	var orderValue = $(this).find('option:selected').attr('value');
		$.post( '/inc/scripts/setSession.php', { 'sessionName': 'sortSelect', 'value': orderValue }, function(data) { 
			location.reload();					
		});	
	});	
	
	// TERMINY TABLE
	
	$('.terminy_table > tbody > tr:not(.cena):odd').addClass('odd');
	
	$('.terminy_table tr').hover(function() {
		$(this).find('td').addClass('hover');
	}, function() {
		$(this).find('td').removeClass('hover');
	});
	
	$('.more-price-info').click(function() {	
		if($('.terminy_table .cena'+ $(this).attr('rel') ).attr('rel') == 1) {
			$('.terminy_table .cena'+ $(this).attr('rel') ).hide();
			$('.terminy_table .cena'+ $(this).attr('rel') ).attr('rel', 0);
		} else {
			$('.terminy_table .cena'+ $(this).attr('rel') ).show();
			$('.terminy_table .cena'+ $(this).attr('rel') ).attr('rel', 1);
		}
		return false;
	});
		
	// READ MORE PLUGIN
	
	$(".short").readmore({ substr_len: 500 });
	$(".short_program").readmore({ substr_len: 120 });
	
});


