$(document).ready(function() {
	var urlparam = location.href.split("/");

	$('.auto-submit-star').rating({
		callback: function(value, link){
			var param_voting = value.split("_");

			$.post("/_lib/ajax/voting.php", { filmid:param_voting[0],value:param_voting[1],format: "json" },
	  			function(data){
	  				$("#votingBewertung").html(data.votingBewertung);
	  				$("#votingStimmen").html(data.votingStimmen);
	  				$("#votingRating").html(data.votingRating);
	  				$("#votingStars").width(data.votingStars);

	  			}, "json");
			return false;
		},
		focus: function(value, link){
			var tip = $('#hover-test');
			tip[0].data = tip[0].data || tip.html();
			tip.html(link.title || 'value: '+value);
		},
		blur: function(value, link){
			var tip = $('#hover-test');
			$('#hover-test').html(tip[0].data || '');
		}
	});

	$("#voting").change( function() {
		var param_voting = $(this).val().split("_");

		$.post("/_lib/ajax/voting.php", { filmid:param_voting[0],value:param_voting[1],format: "json" },
  			function(data){
  				$("#votingBewertung").html(data.votingBewertung);
  				$("#votingStimmen").html(data.votingStimmen);
  				$("#votingRating").html(data.votingRating);
  				$("#votingStars").width(data.votingStars);

  			}, "json");
		return false;
	});

	$(".play").click( function() {
		$(this).hide();
		if($(this).parent("div").hasClass("fsk16") && ($.cookie("fsk")!="16" && $.cookie("fsk")!="18")){
			$(".age").fadeIn("fast");
			$.cookie("fsk_temp","16",{path:'/'})
		} else if(($(this).parent("div").hasClass("fsk18") || $(this).parent("div").hasClass("fskx")) && $.cookie("fsk")!="18"){
			$(".age").fadeIn("fast");
			$.cookie("fsk_temp","18",{path:'/'})
		} else {
			$(".size").fadeIn("fast");
		}
	});
	$(".age .ja").click( function() {
		$(".age").hide();
		$(".size").fadeIn("fast");
		$.cookie("fsk",$.cookie("fsk_temp"),{path:'/'})
	});
	$(".age .nein").click( function() {
		$(".age").hide();
		$(".play").fadeIn("fast");
	});
	$(".small").click( function() {
		$("#moviebox").empty();
		$(".size").hide();
		$(".hd_switch").hide();
		$("#T1").html("");
		$(".flashholder").show();
		var param = $(this).attr("href").split("/");
		var kkfilmid = param[0];
		$(".close_small").fadeIn("fast");
		$.post("/_lib/ajax/trailershow.php", {filmid:param[0],breite:param[1],fsk:param[2],format: "json "},
		function(data) {
			$(".flashholder").html($.base64Decode(data));
		});
		return false;
	});
	$(".big").click( function() {
		$("#moviebox").empty();
		/*
		if($(this).attr("rel")=='0' || $(this).attr("rel")==''){
			var hoehe = 420;
		} else {
			var hoehe = $(this).attr("rel");
		}
		*/
		var hoehe = 357;
		var param = $(this).attr("href").split("/");
		var kkfilmid = param[0];

		$.post("/_lib/ajax/trailershow.php", {filmid:param[0],breite:param[1],fsk:param[2],format: "json "},
		function(data) {
			$(".close_small").hide();
			$("#hd").slideDown("slow");
			$(".holder").slideUp("fast");
			$("#T1").fadeIn("fast");
			$(".size").hide();
			$(".close").fadeIn("fast");

			$("#T1").html($.base64Decode(data));

		});
 		$(".size").hide();
		$(".holder img").animate({
			width: '635', height: (parseFloat(hoehe)-15)
		}, "slow");
		$(".accordion").animate({
			top: (hoehe)
		}, "slow",function(){
		checkHeight(".accordion",(parseFloat(hoehe)+60));

		$(".holder img").hide();
		$("#big").fadeIn("fast");
		$(".close").fadeIn("fast");
		});
		return false;
	});
	$("#hd .close").click( function() {
		if(typeof _moviebox.init != 'undefined') _moviebox.shutdown();
		$("#moviebox").empty();
		$(this).hide();
		$("#flashflvplayerholder").remove();
		$("#hd").hide();
		$(".holder").show();
		$(".holder img").show();
		$(".holder img").animate({
		width: '430', height: '274'
		}, "slow");
		$(".accordion").animate({
			top: '0'
		}, "slow",function(){
		checkHeight(".accordion",40);
		$(".play").show();
		});

	});
	$(".close_small").click( function() {
		if(typeof _moviebox.init != 'undefined') _moviebox.shutdown();
		$("#moviebox").empty();
		$("#flashflvplayerholder").remove();
		$(this).hide();
		$("#hd").hide();
		$(".flashholder").hide();
		$(".hd_switch").show();
		$(".play").show();
	});
	$("#filter").keyup(function () {
		var filter = $(this).val();
		$(".filtered li").each(function () {
			if ($(this).text().search(new RegExp(filter, "i")) < 0) {
				$(this).addClass("hidden");
			} else {
				$(this).removeClass("hidden");
			}
		});
	});


	/* Accordion */

			$(".accordion h2 a").click( function() {
				$(".accordion ul").not($(this).parent("h2").next("ul")).hide();
				$(".accordion h2 a").addClass("closed");
				$(this).parent("h2").next("ul").slideToggle("fast",function(){
					$(this).prev("h2").children("a").removeClass("closed");
					checkHeight(".accordion",40);
				});
				return false;
			});
	/* Filmdetail ende */

	/*$("#detail-tabs li").removeClass("active");
	$("#detail-tabs li a."+$("body").attr("class")).parent("li").addClass("active");
	$(".tab-content div.movie-detail").hide();
	$(".tab-content div#"+$("body").attr("class")).fadeIn("fast");*/

	$("#detail-tabs a").click( function() {
		ReloadPixelImages('ProgrammFilme'+ $(this).attr("class"),'Krankikom');
		$("#detail-tabs li").removeClass("active");
		$("#detail-tabs li a."+$(this).attr("class")).parent("li").addClass("active");
		$(".tab-content div.movie-detail").hide();
		$(".tab-content div#"+$(this).attr("class")).fadeIn("fast");
		if($(this).attr("class")=="spielzeiten"){
			$.getScript("/_inc/jquery.accordion.min.js");
			for(var i=0; i<$(".time-carousel").length; i++){
				$(".time-carousel").eq(i).show();
				$(".time-carousel").eq(i).addClass("no_jcarousel");
				$(".loader").eq(i).css("background", "none");
				if($(".time-carousel").eq(i).children("li").length>7){
					$(".time-carousel").eq(i).removeClass("no_jcarousel");
					$('.time-carousel').eq(i).jcarousel({
						visible: 7,
						scroll: 7
					});
				}

			}
		}
		checkHeight(".accordion",40);
		return false;
	});
	if(urlparam[8] == 'spielzeiten') {
		$("#detail-tabs li").removeClass("active");
		$("#detail-tabs li a."+urlparam[8]).parent("li").addClass("active");
		$(".tab-content div.movie-detail").hide();
		$(".tab-content div#"+urlparam[8]).fadeIn("fast");
		if(urlparam[8]=="spielzeiten"){
			$.getScript("/_inc/jquery.accordion.min.js");
			for(var i=0; i<$(".time-carousel").length; i++){
				$(".time-carousel").eq(i).show();
				$(".time-carousel").eq(i).addClass("no_jcarousel");
				$(".loader").eq(i).css("background", "none");
				if($(".time-carousel").eq(i).children("li").length>7){
					$(".time-carousel").eq(i).removeClass("no_jcarousel");
					$('.time-carousel').eq(i).jcarousel({
						visible: 7,
						scroll: 7
					});
				}

			}
		}
		checkHeight(".accordion",40);
		return false;
	}


	checkHeight(".accordion",40);

});
