var interval;

$(function()
{
	/* Homepage slider */
	
	if( $( '.slider-image' ) != 'undefind' ) interval = setInterval( "slideSwitch()", 4000 );
	
	$( '#sliderBullets > li' ).click( function()
	{
		clearInterval(interval);
		
		$( '.slider-image div.last-active' ).removeClass( 'last-active' );
		$( '.slider-image div.active' ).removeClass( 'active' );
		
		$( '#sliderBullets > li.current' ).removeClass( 'current' );
		$( this ).addClass('current');
		
		var image = $( this ).attr('id').split('-');
		
		$( '#' + image[1] ).parent().addClass('active');
		
		interval = setInterval( "slideSwitch()", 4000 );
	});
	
	/* Kleuren */
	
	if( $( '#parasol' ) != 'undefined' ) var orgineel = $( '#parasol' ).attr( 'src' );
	
	$( 'ul.kleuren > li > a' ).hover( function()
	{
		$( '#parasol' ).attr('src', $( this ).attr( 'href') );
		
		return false;
		
	}, function()
	{
		$( 'ul.kleuren' ).hover( function(){}, function()
		{
			$( '#parasol' ).attr('src', orgineel );
		});
		
	});
	
	$( 'ul.kleuren > li > a' ).click( function(){ return false; } );
	
	/* Fotos */
	$( 'ul.thumbs > li > a' ).click( function()
	{
		
		$( this ).parent().parent().next('img.foto')
			.attr( 'src', $( this ).attr( 'href' ) )
			.attr( 'alt', $( this ).attr( 'title' ) )
			.attr( 'title', $( this ).attr( 'title' ) );
		
		return false;
	});
	
	/* Alleen nummers invoeren */
	$( '.nummers' ).keypress( function(e)
	{ 
		if (e.keyCode == 0)
		{
			keyCode = e.which;

			if( keyCode < 48 || keyCode > 57 )
			{
				 e.preventDefault();
				 e.returnValue = false;
			} 
			else 
			{
				keyCode = e.keyCode;
			}
		}
	});
	

	if( $( '#offerte-formulier' ) != 'undefined' )
	{
		checkAnders();
		checkBedrukking();
		
		$( ":radio[name='Kleur']").change( function(){ checkAnders(); });
		$( ":radio[name='Bedrukking']").change( function(){ checkBedrukking(); });
		$( ":radio[name='Logo']").change( function(){ checkLogo(); });
	}
});

function slideSwitch()
{
    var $active = $('.slider-image div.active');

    if ( $active.length == 0 ) $active = $('.slider-image div:last');

    var $next =  $active.next().length ? $active.next() : $('.slider-image div:first');
    
    $active.addClass('last-active');
    
    $( '#sliderBullets > li.current' ).stop().animate({opacity: 1.0}, 500, function()
    {
    	 $( '#sliderBullets > li.current' ).removeClass( 'current' );
    	    
    	 var bullet = $( '#li-' + $next.children('img').attr('id') ).addClass('current');
    });

    $next.css({opacity: 0.0}).addClass('active').stop().animate({opacity: 1.0}, 2000, function()
	{
 		$active.removeClass('active last-active');
 	});
}

function checkAnders()
{
	
	if( $( '#anders-radio').attr( 'checked' ) == false )
	{
		$( '#KleurAnders' ).attr( 'disabled', true );
	}
	else
	{
		$( '#KleurAnders' ).attr( 'disabled', false );
	}
}

function checkBedrukking()
{
	
	if( $( '#bedrukkingJa').attr( 'checked' ) == false )
	{
		$( '#eigen-logo' ).attr( 'disabled', true );
		$( '#logo-anders' ).attr( 'disabled', true );
		$( '#LogoAnders' ).attr( 'disabled', true );
		$( '#AantalKleuren' ).attr( 'disabled', true );
		$( '#Prints' ).attr( 'disabled', true )
	}
	else
	{
		$( '#eigen-logo' ).attr( 'disabled', false );
		$( '#logo-anders' ).attr( 'disabled', false );
		
		checkLogo();
	}
}
function checkLogo()
{
	if( $( '#logo-anders').attr( 'checked' ) == false )
	{
		$( '#LogoAnders' ).attr( 'disabled', true );
		$( '#AantalKleuren' ).attr( 'disabled', false );
		$( '#Prints' ).attr( 'disabled', false );
	}
	else
	{
		$( '#LogoAnders' ).attr( 'disabled', false );
		$( '#AantalKleuren' ).attr( 'disabled', true );
		$( '#Prints' ).attr( 'disabled', true );
	}
}

function toggleContactwijze() {
	$('#Contactwijze_anders').hide();
	$('input:radio[name=Contactwijze]:checked').each(function(){
		if($(this).val() == "via_anders") {
			$('#Contactwijze_anders').show();
		} 
	});	
}

$(document).ready(function() {
  toggleContactwijze();
});
