
$(document).ready(
	function()
	{
		
        replaceLogos();
		doSponsors();
		doNieuws();

		doCountDown();
//        $(".galerij").ccgallery();
        rotatingHeader(-1);
        
        
        $("input[name=check2]").val($("input[name=check]").val()*3);
        
        inschrijfformulier();
        
        $().piroBox({
			my_speed: 400, //animation speed
			bg_alpha: 0.1, //background opacity
			slideShow : true, // 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

	});
	}

);

function doCountDown()
{
	var datum = new Date(2011, 9, 30, 10, 0, 0);
	$('#countdown').countdown({	until: datum,  
							    description: 'Tot de volgende Spinningmarathon!'});
}

/************************************************
 * Sponsoren
 ************************************************/

function doSponsors()
{
	$("ul#sponsors").animate({
		left: "-182px"
	},
	2000,
	function()
	{
		doSwitch();
	});	
}

function doSwitch()
{
	$("ul#sponsors li:first").appendTo("ul#sponsors");
	$("ul#sponsors").css("left", "0px");
	
	setTimeout("doSponsors()", 1000);
}

function replaceLogos()
{
	$("ul#sponsors li").each(
		function()
		{
			$(this).css("text-align", "center");
			
			$(this).find("img").load(
					function()
					{
						var img = $(this);
						var height = img.height();
						
						//console.log(height);
                        
						hoogte = Math.round(((130-height)/2)-10);
						
						img.css("margin-top", hoogte+"px");
					}
			);
						
		}
	);
}

/************************************************
 * Nieuws
 ************************************************/

var doRotateNieuws = true;
function doNieuws()
{
	$("#teaser-content li:gt(0)").hide();
	$("#teaser-content li:first").addClass('active');
	$("#teaser-titles li:first").addClass("active");
	
	setInterval(function(){rotateNieuws()}, 5000);
	
	$("#teaser-titles li a").click(
			function()
			{
				doRotateNieuws = false;
				
				var id = $(this).attr("href");
				
				var cur  = $("#teaser-content li.active");
				var next = $("#teaser-content li#"+id);
				
				cur.fadeOut("medium",
						function()
						{
							cur.removeClass('active');
							next.addClass('active').fadeIn("medium");
						
							$("#teaser-titles li.active").removeClass('active');
							$("#teaser-titles li:eq("+next.index()+")").addClass('active');
						}
				);
				
				setTimeout(function(){doRotateNieuws = true}, 10000);
			}
	);
}

function rotateNieuws()
{
	if (rotateNieuws)
	{
		$("#teaser-content li.active").fadeOut("medium",
			function()
			{
				var cur  = $("#teaser-content li.active");
				var next = cur.next('li');
				
				if (next.length == 0)
				{
					next = $("#teaser-content li:first");
				}
				
				cur.removeClass('active');
				next.addClass('active').fadeIn("medium");
						
				$("#teaser-titles li.active").removeClass('active');
				$("#teaser-titles li:eq("+next.index()+")").addClass('active');
			}
		
		);
	}
}

/************************************************
 * Header rotator
 ************************************************/
function rotatingHeader(iIndex)
{
    if (iIndex >= 0)
    {
        $("#home"+iIndex).fadeOut(1500)

        iIndex++;
        
        if (iIndex >= $(".homeImg").size())
        {
            iIndex = 0;
        }
        
        $("#home"+iIndex).fadeIn(1000);
		$("#home"+iIndex).css("display","block");
    }else{
        iIndex = 0;
        $("#home"+iIndex).fadeIn(1000);
		$("#home"+iIndex).css("display","block");
    }
    setTimeout("rotatingHeader("+iIndex+")", 5000);    
}

/************************************************
 * inschrijf formulier
 ************************************************/
function inschrijfformulier()
{
    $('.pakket').change(function(){
        
        if($(this).attr("id") == "pakket-1")
        {
            $("#tijdstip-wrapper").css("display","block");
        }else{
            $("#tijdstip-wrapper").css("display","none");
        } 
    });
    
    changeRekening();
    
    $('input[name="betaalwijze"]').click(function(){
        changeRekening();    
    });      
}

    function changeRekening()
    {
        if($('input[name="betaalwijze"]:checked').val() == "iDeal")
        {
            $('input[name="rekeningNr"]').removeClass("required");
            $('input[name="tenaamstelling"]').removeClass("required");
            
            $('input[name="rekeningNr"]').parent().css("display","none");
            $('input[name="tenaamstelling"]').parent().css("display","none");
        }else{
            
            $('input[name="rekeningNr"]').addClass("required");
            $('input[name="tenaamstelling"]').addClass("required");
            
            $('input[name="rekeningNr"]').parent().css("display","block");
            $('input[name="tenaamstelling"]').parent().css("display","block");
        }
    }



