$(document).ready(function() {

	$("a.slideToggle").click(function(){
		var element = $(this).parent().prev().find(".none");
		if(element.css("display")!='none'){
			$(this).children().children().html('mehr');
			$(this).parent().attr( 'class', 'more');
		} else {
			$(this).children().children().html('weniger');
			$(this).parent().attr( 'class', 'less');
		}
		
		element.slideToggle('slow');

		return false;
	});


	function criticjcarousel_initCallback(carousel, state) {
		if (state == 'init'){
			//carousel.container.css('display','block');
			carousel.container.parent().css('height','auto');
		}
	};

	jQuery(".criticjcarousel").jcarousel({
		scroll: 1,
		initCallback: criticjcarousel_initCallback
	});


	$(".ajax_get_kino_film_ov_berlin").typeWatch({ highlight: false, wait: 350, captureLength: 2, callback: function(){critic_ajax_call('film_ov_berlin',".ajax_get_kino_film_ov_berlin");}});
	$(".ajax_get_kino_kinofilm").typeWatch({ highlight: false, wait: 350, captureLength: 2, callback: function(){critic_ajax_call('kinofilm',".ajax_get_kino_kinofilm","rechts");}});
	$(".ajax_get_kino_ort").typeWatch({ highlight: false, wait: 350, captureLength: 2, callback: function(){critic_ajax_call('ort',".ajax_get_kino_ort");}});
	$(".ajax_get_kino_film").typeWatch({ highlight: false, wait: 350, captureLength: 2, callback: function(){critic_ajax_call('film',".ajax_get_kino_film","rechts");}});
	$(".ajax_get_kino_kino").typeWatch({ highlight: false, wait: 350, captureLength: 2, callback: function(){critic_ajax_call('kino',".ajax_get_kino_kino","rechts");}});
	
	
	function critic_ajax_call(typ,element,content_side){
		
		if(!content_side){
			content_side='links';
		}
		
		$.ajax({
			url: '/?type=5000',
			data: 'typ=' + typ + '&search_string=' + $(element).val(),
			success: function(result) {
				if(result.length) {
					$('.ajax_results_' + content_side).html(result);
					$('.ajax_results_' + content_side).show();
				} else {
					$('.ajax_results_' + content_side).html('');
					$('.ajax_results_' + content_side).hide();
				}
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
				$('.ajax_results_' + content_side).html('');
				$('.ajax_results_' + content_side).hide();
			}
		});
	}

	/*
	$('.ajax_get_kino_ort').bind('keyup', function() {
		if($(this).val().length>=3){
			$.ajax({
				url: '/?type=5000',
				data: 'typ=ort&search_string=' + $(this).val(),
				success: function(result) {
					if(result.length) {
						$('.ajax_results_links').html(result);
						$('.ajax_results_links').show();
					} else {
						$('.ajax_results_links').html('');
						$('.ajax_results_links').hide();
					}
				},
				error: function(XMLHttpRequest, textStatus, errorThrown) {
					$('.ajax_results_links').html('');
					$('.ajax_results_links').hide();
				}
			});
		}
	});
	*/
	
	if($('.show_ajax_results').length!=0) {
		$(window).bind("click", function() {
			$('.show_ajax_results').html('');
			$('.show_ajax_results').hide();
		});
	}


});

function ov_set_cinema(value){
	$("#tx_criticde_pi5_ovsearch_cinema_show").val(value);
	$("form[name='search_ov_berlin']").submit();
	return false;
}

function ov_set_movie(movie_number){
	$("#tx_criticde_pi5_ovsearch_movie").val(movie_number);
	$("form[name='search_ov_berlin']").submit();
	return false;
}

function ov_set_days(typ,value,days){
	if(typ=='cinema'){
		$("#tx_criticde_pi5_ovsearch_cinema_show").val(value);
	} else if(typ=='movie'){
		$("#tx_criticde_pi5_ovsearch_movie").val(value);
	}
	
	$("#tx_criticde_pi5_ovsearch_days").val(days);
	$("form[name='search_ov_berlin']").submit();
	return false;
}

	

