$(document).ready(
	function()
	{
		if ($.browser.version.charAt(0) < 7 && $.browser.msie){$("#mainnav li, #subnav li").hover(function(){$(this).addClass('hover');},function(){$(this).removeClass('hover');});}
                
        
        if($('body').attr('id') == 'home')
        {
            startHeader();
            headerButtons();
            
            projectRotator = setTimeout("projectDoMove('right')", 5000);
            projectButtons();    
        }
        
	}
);

/**************************************
 * Home header
 *************************************/
function headerButtons()
{
    $('.image-links li').click(function(){
        doHeader($(this));
        return false;
    });
}

function startHeader()
{
    var rand = Math.ceil(4*Math.random());

    doHeader($('.image-links li:nth-child('+rand+')'));
}

function doHeader(activeItem)
{        
    //Titel tekst wisselen.
    $('.image-text').fadeOut(600, function(){
        $('.image-text .title').html($(activeItem).find('a').html());
        $('.image-text .title').attr("href", $(activeItem).find("a").attr("href"));
        $('.image-text .slogan').html($(activeItem).find('span').html());
        $('.image-text').fadeIn(400);
    });
    
    //Afbeelding wisselen
    $('#content-image ul.image .no-active img').attr('src', activeItem.find('img').attr('src')).css('top','300px') ;

       
    $('#content-image ul.image .no-active img').animate({top: '0px'},600,function(){
        $('#content-image ul.image .active img').attr('src', $('#content-image ul.image .no-active img').attr('src'))   
    });

    //Knoppen wisselen.
    $('.image-links').animate({bottom: '290px', opacity: '0'}, 600, function(){
        
        $('ul.image-links li').removeClass('active');
        activeItem.addClass('active');
        //$('.image-links').animate({bottom: '0px', opacity: '1'}, 400);  
        //$('.image-links').css('bottom', '1px').animate({opacity: '1'}, 400);
        $('.image-links').css('bottom', '-20px');
        $('.image-links').animate({bottom: '0px', opacity: '1'}, 400);       
    });
        
    
}



/**************************************
 * Project
 *************************************/
function projectButtons()
{
     $('#project-left').click(function(e){
        e.preventDefault();
        projectDoMove('left');
    });
    
    $('#project-right').click(function(e){
        e.preventDefault();
        projectDoMove('right');
    });
}

function projectDoMove(direction)
{    
    //var d = new Date();
    //console.log(d.getHours() + ':' + d.getMinutes() + ':' + d.getSeconds());
    
    clearTimeout(projectRotator);
    
    switch(direction){
            case "left":
                $('#project-rotator li:last').prependTo("#project-rotator");
                $("#project-rotator").css("left", "-225px");
                                
                var move = 15;
                break;
            case "right":
                var move = -225;
                break;
    }
    
    $('#project-rotator').animate({
        left: move
    }, 1000,
    function()
    {
        if(direction == "right")
        {
            $('#project-rotator li:first').appendTo("#project-rotator");
            $("#project-rotator").css("left", "15px");    
        }
    });
    
    projectRotator = setTimeout("projectDoMove('right')", 5000);	

}

