$(document).ready(
	function()
	{
		if ($.browser.version.charAt(0) < 7 && $.browser.msie){$("#mainnav li, #subnav li").hover(function(){$(this).addClass('hover');},function(){$(this).removeClass('hover');});}
		
        doBackground();
        doFotoAlbum();
        /*
        $().piroBox({
            my_speed: 300, //animation speed
            bg_alpha: 0.5, //background opacity
            slideShow : 'true', // true == slideshow on, false == slideshow off
            slideSpeed : 3, //slideshow
            close_all : '.piro_close' // add class .piro_overlay(with comma)if you want overlay click close piroBox
        });
        */
	}
);



function doBackground()
{
    var achtergronden = new Array();
    
    $('.bg-afbeeldingen').each(function(afbeelding) {
        var nw_array = new Array();
        nw_array["src"] = $(this).attr('src');
        nw_array["fade"] = 1000;
        
        achtergronden[afbeelding] = nw_array;
        
    });
    

    $.vegas('slideshow', {
        backgrounds: achtergronden,
        preload:     true
    })('overlay');
}



/* Fotoalbum */
var curFoto     = 0;
var totalFoto   = 0;

function doFotoAlbum()
{
    $('.popup').click(function(){
        totalFoto   = $('#gallery li').length;
        curFoto     = $(this).parent().index();
        startMenuToggle();
        
        $('#gallery').fadeOut(500);
        $('#foto-details').fadeIn(500, showFoto());
        fotoButtons();
        fotoCheckButtons();
    });
}

function startMenuToggle()
{
    $('#mainnav').animate({top: '-35px'},500);
    
    $('#layout-header').hover(
        function(){
            $('#mainnav').animate({top: '0px'},500);
        },
        function(){
            $('#mainnav').animate({top: '-35px'},500);
        }
    );
}

function fotoButtons()
{
    $("#foto-detail-nav-next").click(function(){
        curFoto++;
        
        fotoCheckButtons();
        showFoto();
    });
    
    $("#foto-detail-nav-prev").click(function(){
        curFoto--;
        
        fotoCheckButtons();
        showFoto();
    });
}

function fotoCheckButtons()
{
    if((curFoto + 1) >= totalFoto)
    {
        if(curFoto >= totalFoto)
        {
            curFoto--;   
        }
        
        $("a#foto-detail-nav-next").addClass("inActive");                      
    }else{
        $("a#foto-detail-nav-next").removeClass("inActive");
    }
    
    if(curFoto <= 0)
    {
        curFoto = 0;
        $("a#foto-detail-nav-prev").addClass("inActive");
    }else{
        $("a#foto-detail-nav-prev").removeClass("inActive");   
    }
}

function showFoto()
{
    var foto = $("#gallery li").eq(curFoto);
    
    $('#foto-details-content').fadeOut(500,function()
    {    
        
        var fotoBeschrijving = foto.find('img.gallery-images').attr('title');
        $('#foto-details-titel').html(fotoBeschrijving);
        //alert(foto.html());
        $('#foto-details-content').html(foto.find('div.gallery-fotoDetails').html());
        $('#foto-details-content').fadeIn(400);

        fotoZoom();
    });
}

function fotoZoom()
{
    $('#foto-details-content .pirobox').click(function(e){
        e.preventDefault();
        
        if($(this).hasClass("staand"))
        {
            $('#foto-zoom').addClass("staand");
        }else{
            $('#foto-zoom').removeClass("staand");
        }
        
        $('#foto-zoom-img').attr('src',$(this).attr('href'));
        
        $('#foto-zoom-bg').width($(document).width());
        $('#foto-zoom-bg').height($(document).height());
        $('#foto-zoom-bg').fadeIn();
        
        $('#foto-zoom').fadeIn(1000);
    });
    
    $('#foto-zoom-close').click(function(e){
        e.preventDefault();
        fotoZoomClose();
    });
    
    $('#foto-zoom-bg').click(function(e){
        e.preventDefault();
        fotoZoomClose();
    });
}

function fotoZoomClose()
{
    $('#foto-zoom').fadeOut(500, function(){
        $('#foto-zoom-bg').fadeOut(250);
    });
}



