$(document).ready(function(){
   	maxHeight = 160;
    minHeight = 22;

   	maxHeight2 = 100;
    minHeight2 = 0;

    minHeightDetails = 25;
	maxHeightDetails = 130;
	countItems = 1;
	klappStatus = 'zu';



   $(window).load(function() {
     $(".videoDownload").each( function() {
      	$(this).height(22);         
     });
     $(".videoDownloadLi").each( function() { 														
      	$(this).children(".videoDownloadDiv").height(0);          														
      	$(this).children(".videoDownloadDiv").children(".downloadSubline").show();          														
      	$(this).children(".videoDownloadDiv").children("ul.downloadBox").height(minHeightDetails);          														
	 });

     $("#faq h2.faq").each( function() { 														
      	this._saveHeight = $(this).next().height();
      	if(countItems>1){
      	$(this).next().height(0);
      	} else {
            $(this).addClass("aktiv");
            $(this).before("<div id='faqcontrol'>Alles ausklappen</div>");
        }  
      	countItems++;           	    	
	});
	
	
	

    $("#faqcontrol").click(
    	function(){
			if (klappStatus == 'zu'){
	       		$(this).html("Alles einklappen");
	       		klappStatus = 'auf';
	       		$("#faq h2.faq").each(
     			  function(){   
            		$animateContent = $(this).next();
			        $(this).addClass("aktiv");
            		newHeight = this._saveHeight;
            		$animateContent.animate({height: newHeight+"px"}, 0, function(){ $animateContent.height("auto"); 
            	});          
      }          													
     );

	       	} else {
		       	$("#faq h2.faq").each(
     			  function(){   
            		$animateContent = $(this).next();
			        $(this).removeClass("aktiv");
            		$animateContent.animate({height: "0px"}, { queue:false, duration:0});
            	});     
	       		$(this).html("Alles ausklappen");	       	
	       		klappStatus = 'zu';
	       	}
  		}
    ); 
  
  
  
  });


   $("#faq h2.faq").click(
     function(){   
            	$animateContent = $(this).next();

		 if ($(this).hasClass("aktiv")) {  
            	$animateContent.animate({height: "0px"}, { queue:false, duration:500});
				$(this).removeClass("aktiv"); 
            } else {
            	$(this).addClass("aktiv");
            	newHeight = this._saveHeight;
            	$animateContent.animate({height: newHeight+"px"}, 500, function(){ $animateContent.height("auto"); });
        }  
      }          													
     );



	 													
   $("li.videoDownload").click(
     function(){              
        if (this.status == "zu" || typeof(this.status)=="undefined") {  
        		$(this).animate({height: maxHeight+"px"}, { queue:false, duration:500});
            	$(this).addClass("aktiv");
            	this.status = "auf";
            } else {
            	this.status = "zu";
        		$(this).animate({height: minHeight+"px"}, { queue:false, duration:500 });  
            	$(this).removeClass("aktiv");          														
        }
        lastList = this;
     }          													
     );



											
$("span.videoDownloadLink").click(
     function(){                 
        if (this.status == "zu" || typeof(this.status)=="undefined") {  
        		$(this).parent().children(".videoDownloadDiv").animate({height: maxHeight2+"px"}, { queue:false, duration:500});
            	$(this).parent().addClass("aktiv");
            	this.status = "auf";
            } else {
            	this.status = "zu";         	
        		$(this).parent().children(".videoDownloadDiv").animate({height: minHeight2+"px"}, { queue:false, duration:500});
        		$(this).parent().children(".videoDownloadDiv").children("ul.downloadBox").animate({height: "25px"}, { queue:false, duration:500});   		
            	$(this).parent().children(".videoDownloadDiv").children("div.downloadSubline").text("Technische Details einblenden");   		
            	$(this).parent().removeClass("aktiv");          														
        }
     }          													
     );
				
$("div.downloadSubline").click(
     function(){              
        if ($(this).parent().children("ul.downloadBox").height() == minHeightDetails) {  
        		myNewHeight = $(this).parent().children("ul.downloadBox").children("li").height();
        		       		
        		$(this).parent().children("ul.downloadBox").animate({height: myNewHeight+"px"}, { queue:false, duration:500});
         		$(this).parent().animate({height: myNewHeight+80+"px"}, { queue:false, duration:500});
             	$(this).text("Technische Details ausblenden");
             	$(this).addClass("aktiv");
            } else {
				$(this).parent().children("ul.downloadBox").animate({height: "25px"}, { queue:false, duration:500});
         		$(this).parent().animate({height: maxHeight2+"px"}, { queue:false, duration:500});
             	$(this).text("Technische Details einblenden");            	
             	$(this).removeClass("aktiv");          														
        }
     }          													
     );	
     
     
/* Generisches Akkordeon */

 $("ul.tsAkkordeon li.drawer").each( function() { 														
      	this._saveHeight = $(this).next().height();
      	newHeight = $(this).children('div.drawerHandle').height();
		$(this).height(newHeight);
	});


$("ul.tsAkkordeon div.drawerHandle").click(
     function(){      
        newHeight = $(this).height()+$(this).next('div.drawerContent').height();
                
        if (this.status == "zu" || typeof(this.status)=="undefined") {  
        		$(this).parent().animate({height: newHeight+"px"}, { queue:false, duration:500});
            	this.status = "auf";
            } else {
            	this.status = "zu";         	
		        newHeight = $(this).parent().height()-$(this).next('div.drawerContent').height();
        		$(this).parent().animate({height: newHeight+"px"}, { queue:false, duration:500});
        }
     }          													
     );
     
     										
});


/*
 * ImageSlider v0.1 for tagesschau.de
*/


$(window).load(function() {
	var dragging = false;
	var mouseX = 0;
	var mouseY = 0;
	var activeDrawer = null;   
	var maxRight = 0;
	var rightMargin = 0;
	var topMargin = 0;
	var mode = "horizontal";

	
	$('div.slider .off').each(function(){
		$(this).css('height', $(this).children('.maske').children('img').height()+14);
	});

	$('div.imgslider.horizontal .anfasser').each(function(){
		$(this).css('top', $(this).prev('.maske').height()/2-70);
	});

	$('div.imgslider.vertical .anfasser').each(function(){
		$(this).css('left', $(this).prev('.maske').width()/2-70);
	});

	$('div.anfasser').mousedown(function() {
		maxRight = $(this).prev('.maske').children('img').width()+$(this).prev('.maske').children('img').offset().left;
		rightMargin = $(this).prev('.maske').children('img').offset().left;

		maxTop = $(this).prev('.maske').children('img').height()+$(this).prev('.maske').children('img').offset().top;
		topMargin = $(this).prev('.maske').children('img').offset().top;

		if ($(this).parents(".imgslider").hasClass('vertical')){
			mode = "vertical";
		}
		activeDrawer = $(this);
		activeDrawer._dragging = true;
		dragging=true;
	});

	$().mouseup(function() {
		dragging = false;
	});

	$().mousemove( function(e) {
		if(dragging){
			mouseX = e.pageX;
			mouseY = e.pageY;

			if( mode == "horizontal" && mouseX < maxRight ) {
				activeDrawer.prev('.maske').width(mouseX-rightMargin);
			}
			if( mode == "vertical" && mouseY < maxTop ) {
				activeDrawer.prev('.maske').height(mouseY-topMargin);
			}
		}
	});

	$('div.anfasser').bind("touchstart",function() {
		maxRight = $(this).prev('.maske').children('img').width()+$(this).prev('.maske').children('img').offset().left;
		rightMargin = $(this).prev('.maske').children('img').offset().left;

		activeDrawer = $(this);
		activeDrawer._dragging = true;
		dragging=true;
	});
	
	$().bind( "touchend",function() {
		dragging = false;
	});
	
	$().bind("touchmove",function(e) {
		if(dragging){
			var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0];
			mouseX = touch.pageX;
			mouseY = touch.pageY;
			if( mode == "horizontal" && mouseX < maxRight ) {
				activeDrawer.prev('.maske').width(mouseX-rightMargin);
			}
			if( mode == "vertical" && mouseY < maxTop ) {
				activeDrawer.prev('.maske').height(mouseY-topMargin);
			}
		}
	});
});


