$(document).ready(
	function()
	{
		//$("div#carrousel").cccarrousel();
      
        //Slogan('');
        
        rotatingHeader();
        rotatingHeaderHover();

        
        if($("#actie li").length > 1){
            changeItem("home","actie");
            bindNieuwsHome("home","actie");
    		rotater = setTimeout("rotate('home','actie')", 5000);
        }else{
            changeItem("home","actie");
            $("#actie").css('display','none'); 
        }
        
	}
);


function Slogan(vorig)
{
    //alt tekst van active item ophalen
    huidigItem = $("#carrousel-thumbs li.active a img").attr('alt');
    
    //bij een wijziging even aanpassen.
    if(vorig != huidigItem)
    {
        $('#header-slogan p').text(huidigItem);
    }
    
    //en opniew starten
    setTimeout('Slogan(huidigItem)',250);
}


function bindNieuwsHome(locatie, item)
{
	$("#" + item + " li").hover(
		function()
		{
			clearTimeout(rotater);
			rotater = setTimeout("rotate('" + locatie + "','" + item + "')", 5000);	

			$("#" + item + " li.active").removeClass("active");

			$(this).addClass("active");
			
            changeItem(locatie, item);
		}
	);
}

function rotate(locatie, item)
{
        var active    = $("#" + item + " li.active");
		var next      = active.next();

		if (next.length == 0)
		{
			next = $("#" + item + " li:first");
		}

		$("#" + item + " li.active").removeClass("active");
		next.addClass("active");

        changeItem(locatie, item);

		rotater = setTimeout("rotate('" + locatie + "','" + item + "')", 5000);
}

function changeItem(locatie, item)
{
    $(".block-"+ locatie + "-image-" + item + " a img").attr("src", $("#" + item + " li.active a img").attr("src"));
	$(".block-"+ locatie + "-text-" + item + " a.text-title").text($("#" + item + " li.active a span.titel").text());
    $(".block-"+ locatie + "-text-" + item + " p span").text($("#" + item + " li.active a span.omschrijving").text());
            
    $(".block-"+ locatie + "-image-" + item + " a").attr("href", $("#" + item + " li.active a").attr("href"));
    $(".block-"+ locatie + "-text-" + item + " a.text-title").attr("href", $("#" + item + " li.active a").attr("href"));
	$(".block-"+ locatie + "-text-" + item + " p.lees-meer a").attr("href", $("#" + item + " li.active a").attr("href"));
}







/* Rotate header
**************************/
function rotatingHeader()
{
    if($("#carrousel-thumbs li.active").length == 0)
    {
        var iIndex = 0;
    }else{
        var iIndex = $("#carrousel-thumbs li.active").attr("id").replace("thumbsID","");
        
        if (iIndex >= 0)
        {
            iIndex++;
 
            if (iIndex >= $("#carrousel-thumbs li").size())
            {
               var iIndex = 0;
            }
        }
    }
      
    wisselHeader(iIndex);
}

function rotatingHeaderHover()
{
	$("#carrousel-thumbs li").click(
		function()
		{
            curID   = $("#carrousel-thumbs li.active").attr("id").replace("thumbsID","");
            id      = $(this).attr("id").replace("thumbsID","");
            if(curID != id)
            {
                clearTimeout(headerTimer);
                wisselHeader(id);              
            }
		}
	);
}

function wisselHeader(iIndex)
{          
    /*
    $(".header-slogan").fadeOut(500,function(){
        $(".header-slogan").html($("#home"+iIndex).attr("alt"));
    });
    */
    
    $(".image-content").fadeOut(1000);
  
    $("#bigImage"+iIndex).fadeIn(1000);

    
    
    //$(".header-slogan").fadeIn(500);
    //$("#home"+iIndex).css('display','block');
    
    $("#carrousel-thumbs li.active").removeClass("active");
    $("#thumbsID"+iIndex).addClass('active');
    
    
            
    headerTimer = setTimeout("rotatingHeader()", 5000);	
 
}
