jQuery(document).ready(function() {
    
    /**
     * SHADOWBOX
     */
    Shadowbox.init();
    
    
    /**
     * EXTERNAL LINKS
     */
    $('A[rel="external"]').click( function() {
	window.open( $(this).attr('href') );
	return false;
    });


    /**
     * TABLES
     */
    $("tr:nth-child(odd)").addClass("odd");
    $("li:nth-child(even)").addClass("even");
    $("#kinderturnen #sidebar ul.kinderturnen li:nth-child(even)").addClass("even");
    $("#sticky ul li:nth-child(even)").removeClass("even");
   
   
    /**
     * FRONTPAGE CAROUSELL
     */
    $("#sticky_gallery").cycle({ 
		fx: "fade", 
		speed: 1500, 
		timeout: 5000, 
		pause: 1 
    });
    
 
    /**
     * SEARCH FORM
     */
    $("#input").css("color","#AAA");
    $("#input").focus(function() {
        $(this).val("");
        $(this).css("color","#000");
    });  
	$("#input").blur(function() {
        $(this).val("Suchen");
        $(this).css("color","#AAA");
    });
    
    
    /**
     * ARCHIVE PAGE
     * SEE FUNCTION BELOW
     */
    $("#archiv dl dd").hide();
    $("#archiv dl dt").click(function(){
    	$(this).nextUntil("dt").toggle("fast");
    });
   
    
    /**
     * SHITTY FUSSBALL.DE API
     */
    $('#table div div, #table iframe').each(function(idx,el){
  	  el.style.display='';
  	});
    $("#table div div").css( 
    	{
    		position : 'absolute',
    		right : '9999px'
    	}
    );
    $("#table iframe").css(
    	{
    		height : '0px',
    		overflow : 'hidden'
 		}
 	);
});


/**
 * ARCHIVE FUNCTION
 */
$.fn.nextUntil = function(expr) {
   var match = [];

   // FIGURE OUT ELEMENTS TO PUSH IN ARRAY
   this.each(function(){
       // TRAVERSE THROUGH NODES
       for( var i = this.nextSibling; i; i = i.nextSibling ) {
           // ONLY ELEMENTS
           if ( i.nodeType != 1 ) continue;
           // WE FOUND AN ELEMENT… STOP!
           if ( jQuery.filter( expr, [i] ).r.length ) break;
           // OTHERWISE ADD IT TO STACK
           match.push( i );
       }
   });
   return this.pushStack( match, arguments );
};

