// Header slideshow
function slideSwitch() {
    var $active = $('#slideshow li.actief');

    if ( $active.length == 0 ) $active = $('#slideshow li:last');

    var $next =  $active.next().length ? $active.next()
        : $('#slideshow li:first');

    $active.addClass('last-actief');

    $next.css({opacity: 0.0})
        .addClass('actief')
        .animate({opacity: 1.0}, 2000, function() {
            $active.removeClass('actief last-actief');
        });
}

// Detailpagina project
function detailFotos()
{
	// Bij klik op foto deze foto in vergroting zetten
	var imgLoader = null;

	$("#projectdetail .fotos .thumbs li a").hover(function()
	{
		var link = this,
            fotogrootbox = $("#projectdetail .fotos .fotogroot");

		if( fotogrootbox.find('a').hasClass( $(link).attr('class') ) )
        {
            return false;
        }

        fotogrootbox.find('p').fadeOut(200, function()
		{
			imgLoader = new Image();
			imgLoader.onload = function()
			{
                fotogrootbox.find('a').attr({
                   'href': imgLoader.src,
                   'title': $(link).attr("title"),
                   'class': $(link).attr("class")
                });
				fotogrootbox.find('img').attr({ src: $(link).attr("rel").split(" ")[1], alt: $(link).attr("title") });
				setTimeout( function() {
					fotogrootbox.find('p').fadeIn(200);
				}, 300);
			}
			imgLoader.src = $(link).attr("href");
		});
	},
    function()
    {

    });

   $("#projectdetail .fotos .fotogroot a").bind('click', function(e)
    {
        $("#projectdetail .fotos .thumbs li a."+$(this).attr('class')).trigger('click');
        e.preventDefault();
    });
}


$(function()
{
	
	setInterval( "slideSwitch()", 6000 );
	
	/* Hover op menu voor ie6 */
	var thisclass = '';
	$('#menu li strong').hover(
	function()
	{
		thisclass = $(this).attr("class");
		$(this).removeClass(thisclass).addClass(thisclass+'hover');
	},
	function()
	{
		$(this).removeClass(thisclass+'hover').addClass(thisclass);
	});
	
	/* Submenu */
	$("#menu ul").hide();
	$("#menu li.actief ul").show();
	
	$("#menu>li>strong").click(
	function()
	{
		$("#menu>li>ul").not( $("ul", this.parentNode) ).slideUp(200);
		$("#menu>li").not( $(this).parent() ).removeClass("open");
		if( $(this).parent().hasClass("open") )
		{
			$("ul", this.parentNode).slideUp(500);	
			$(this).parent().removeClass("open");
		}
		else
		{
			$("ul", this.parentNode).slideDown(500);	
			$(this).parent().addClass("open");
		}
	});
	
	/* Subsubmenu */
	var menu = {};

	menu.laatstGeopend = null;
	menu.timeoutTime = 2000;
	menu.timeout = null;
	
	menu.init = function()
	{		
		/* hover op li */
		$("#menu>li>ul>li").hover(
			function() 
			{ 		
				// als laatstegeopend dezelfde is als de huidige, dan de timeout verwijderen
				if($(this).hasClass("hover"))
				{
					clearTimeout(menu.timeout);
				}
				// nieuwe uitschuiven
				else
				{
					$("#menu>li>ul>li>ul").hide();
					$("#menu>li>ul>li").not(this).removeClass("hover");
					
					$(this).addClass("hover");
					$(">ul", this).show();									
				}
			},
			function() 
			{ 
				// timeout zetten om na x aantal sec te sluiten
				menu.laatstGeopend = this;
				menu.timeout = setTimeout(function()
				{
					$(menu.laatstGeopend).removeClass("hover"); 
					
				}, menu.timeoutTime);
			}
		);
	}

	menu.init();

	
});

sIFR.replaceElement(named({ sSelector:"h1.bijzonder", sFlashSrc: submap+"/fla/vagrounded.swf", sColor:"#FFFFFF", sBgColor:"#ed1c24" }));
sIFR.replaceElement(named({ sSelector:"h1", sFlashSrc: submap+"/fla/vagrounded.swf", sColor:"#ed1c24", sBgColor:"#FFF", sCase:"upper", sWmode:"transparent" }));
sIFR.replaceElement(named({ sSelector:"#content #projectdetail h2", sFlashSrc: submap+"/fla/vagrounded.swf", sColor:"#ed1c24", sBgColor:"#FFF", sWmode:"transparent" }));
sIFR.replaceElement(named({ sSelector:"h2", sFlashSrc: submap+"/fla/vagrounded.swf", sColor:"#000000", sBgColor:"#FFF", sWmode:"transparent" }));

