$(document).ready(
	function()
	{
		if ($.browser.version.charAt(0) < 7 && $.browser.msie){$("#mainnav li, #subnav li").hover(function(){$(this).addClass('hover');},function(){$(this).removeClass('hover');});}
		
        doHomeTeaser();
        
        
        //Pirobox
        $().piroBox({
			my_speed: 400, //animation speed
			bg_alpha: 0.1, //background opacity
			slideShow : false, // true == slideshow on, false == slideshow off
			slideSpeed : 4, //slideshow duration in seconds(3 to 6 Recommended)
			close_all : '.piro_close,.piro_overlay'// add class .piro_overlay(with comma)if you want overlay click close piroBox
    	});
	}
);


/****************
 * TEASER
 ****************/


doHomeTeaser = function(){
    
    rotateNext(true);
    
    $("ul#teaser-list li a").hover(function(e)
    {
        e.preventDefault();
        
        clearTimeout(play);
            
        $('#teaser-list li').removeClass('active');
        $(this).parent().addClass("active");
        rotate(false);
    }, function(){
        rotate(true);
    });
    
    
}


//Afbeelding wisselen en functie opnieuw starten.
function rotate(timerStart){
    
    $('#teaser-bg').stop(true);
    $('#teaser-img-front').stop(true);
    $('#teaser-img-back').stop(true);
    
    
    $('#teaser-img-front').css("display","block");
    $('#teaser-img-back').attr("src", $('#teaser-list li.active .img-big').attr("src"));
    
    $("a.teaser-btn").attr("href",$('#teaser-list li.active a').attr("href"));
    $("p.teaser-txt").html($('#teaser-list li.active .txt b').html());
    
    //changeBg($("#teaser-list li.active").index());
    
    //achtergrond veranderen
        var beginPos    = -70;
        var stapGroote  = 94;
        
        var nwPos       = (stapGroote * ($("#teaser-list li.active").index() + 1)) +  beginPos;
        
        $('#teaser-bg').animate({
            top:   nwPos 
            }, 
        300, 
        function(){
            $('#teaser-img-back').fadeIn(500);
            $('#teaser-img-front').fadeOut(500, function(){
                
                $('#teaser-img-front').attr("src", $('#teaser-img-back').attr("src"));
        
                //console.log(timerStart);
                if(timerStart == true)
                {
                    play = setTimeout(rotateNext, 4000);    
                }
                 
            });            
            
         }); 
    
    

};

//Nieuw item instellen.
rotateNext = function(){
    var $active = $('#teaser-list li.active').next();
    if ( $active.length === 0) { 
        var $active = $('#teaser-list li:first'); 
    }
    
    $('#teaser-list li').removeClass('active');
    $active.addClass('active');
    
    rotate(true);
}

