// JQUERY Initialization 

$(function() {
    $('#slideshow').cycle({
        fx:     'fade',
        cleartype:  1,
   	cleartypeNoBg:  true,
        speed:  1000,
        timeout: 5000,
	pagerEvent:   'mouseover',
        pager:  '#newsticker',
	manualTrump:   true,  // causes manual transition to stop an active transition instead of being ignored 
        pagerAnchorBuilder: function(idx, slide) {
         //  return sel string for existing anchor
           return '#newsticker li:eq(' + (idx) + ') a';
       }

    });
   
});

$(document).ready(function(){
	
		 //$("ul.sf-menu li.mainmenu > a").append("<span></span");
	 // Navigation
        $("ul.sf-menu").supersubs({ 
            minWidth:    20,   // minimum width of sub-menus in em units 
            maxWidth:    50,   // maximum width of sub-menus in em units 
            extraWidth:  1     // extra width can ensure lines don't sometimes turn over 
                               // due to slight rounding differences and font-family 
        }).superfish(
		{ 
            delay:       0,                            // one second delay on mouseout 
            animationOpen:   {opacity:'show',height:'show'},  // fade-in and slide-down animation 
			animationClose:   {opacity:'hide',height:'hide'},  // fade-in and slide-down animation 
            speed:       300,                          // faster animation speed 
            autoArrows:  false,                           // disable generation of arrow mark-up 
            dropShadows: true                            // disable drop shadows 
        }
		);  // call supersubs first, then superfish, so that subs are 
                         // not display:none when measuring. Call before initialising 
                         // containing tabs for same reason. 
		
		startYear = new Date(1963,7,23,17,00,0);
		$('#countup').countdown({since: startYear , format: 'YDHMS'});
		
       		var refreshId = setInterval(function(){
		$(".header-teaser").fadeTo(500, 0.33)
   			 .animate({opacity: '0.33'}, 6000)   // Does nothing for 2000ms
   			.fadeTo(500, 1)
   			.animate({opacity: '1'}, 9000);   // Does nothing for 2000ms		
    		}, 9000); 	    
	
		
		//Count nes items Info
		var n = ($("div.tt_newsCounter").length)-6;
		var itemcount = $("div.tt_newsCounter");
		$("div.tt_newsCounter").each(function(index){
		 	var counter = index-2;
		 	$(this).text(+counter + "/"+n);
		});

		
});
$(window).load(function() {
 // start slideshow 
    $('#homeslideshow').cycle({ 
        fx:      'fade', 
        timeout:  3000, 
        before:   onBefore 
    }); 
 
    // set totalSlideCount var; 
    // we'll be adding slides beach3.jpg - beach8.jpg to the slideshow 
    var totalSlideCount = 5; 
     
    function onBefore(curr, next, opts) { 
        // on the first pass, addSlide is undefined (plugin hasn't yet created the fn); 
        // when we're finshed adding slides we'll null it out again 
        if (!opts.addSlide) 
            return; 
 
        // on Before arguments: 
        //  curr == DOM element for the slide that is currently being displayed 
        //  next == DOM element for the slide that is about to be displayed 
        //  opts == slideshow options 
             
        var currentImageNum = parseInt(next.src.match(/Pixlie_(\d)/)[1]); 
             
        if (currentImageNum == totalSlideCount) { 
            // final slide in our slide slideshow is about to be displayed 
            // so there are no more to fetch 
            opts.addSlide = null; 
            return; 
        } 
         
        // add our next slide 
        opts.addSlide('<img src="fileadmin/Slideshow/Pixlie_'+(currentImageNum+1)+'.jpg" width="230" />'); 
    }; 
});
