$(document).ready(function()
{
	
	var current = 0;
	
	//Ajax loader
	/*$(".thumb").each(function (i)
	{
		var button = this;
	
		$(this).click(function ()
		{ 
			$.ajax({
			  url: "http://development.gamescores.nl/ajax/"+i,
			  data: "",
			  beforeSend: function(html)
			  {
			  	$('#ajax').fadeOut(100);
			  	$(".thumb").removeClass("active");
			  },
			  success: function(html)
			  {
			  	$('#ajax').html(html);
			  	$('#ajax').fadeIn(100);
			  	$(button).addClass("active");
			  }
			});
	    });
    });*/
	
	$('#header_zoekterm').focus(function() {
							if($(this).attr('value') == 'Zoeken'){
								$(this).attr('value', '');
							}
						});
	$('#header_zoekterm').blur(function() {
							if($(this).attr('value') == '') {
								$(this).attr('value', 'Zoeken');
							}
						});
						
	$('#gebruikersnaam').focus(function() {
							if($(this).attr('value') == 'Gebruikersnaam'){
								$(this).attr('value', '');
							}
						});
	$('#gebruikersnaam').blur(function() {
							if($(this).attr('value') == '') {
								$(this).attr('value', 'Gebruikersnaam');
							}
						});
						
	$('#password').focus(function() {
							if($(this).attr('value') == 'Password'){
								$(this).attr('value', '');
							}
						});
	$('#password').blur(function() {
							if($(this).attr('value') == '') {
								$(this).attr('value', 'Password');
							}
						});
    
    //Controls
    $("#controls ul li").each(function (i)
	{
    	$(this).click(function()
    	{
            var newPos = -(i * 480);
            $("#breed").animate({ left:newPos+"px"}, 400);
            
            $("#controls ul li").removeClass("active");
            $(this).addClass("active");
            
            current = i;
        });
    });
    
    //volgende button
    $("#volgende").click(function()
	{
		if(current > 1) current = -1;

        var newPos = -((current + 1) * 480);
        $("#breed").animate({ left:newPos+"px"}, 400);
        
        $("#controls ul li").removeClass("active");
        $("#controls ul li:eq("+(current+1)+")").addClass("active");
        
        current = current + 1;     
    });
    
    //vorige button
    $("#vorige").click(function()
	{
		if(current < 1) current = 3;
	
        var newPos = -((current - 1) * 480);
        $("#breed").animate({ left:newPos+"px"}, 400);
        
        $("#controls ul li").removeClass("active");
        $("#controls ul li:eq("+(current-1)+")").addClass("active");
        
        current = current - 1;
 
    });
    
    //Keyboard navigation
    $().keydown(function(event)
    {
  		if (event.keyCode == '37') {
     		$("#vorige").click();
   		}
   		
   		if (event.keyCode == '39') {
     		$("#volgende").click();
   		}
   	});
	
	// target = _blank fix
	$('a').each(function() {
					if($(this).attr('rel') == 'external') {
						$(this).attr('target', '_blank');
					}
					
					if($(this).attr('rel') == 'lightbox'){
						$(this).fancybox({
							'transitionIn'	:	'elastic',
							'transitionOut'	:	'elastic',
							'speedIn'		:	600, 
							'speedOut'		:	200, 
							'overlayShow'	:	false
						});
					}
					
					
				});		
		/*$('a[rel=lightbox]').fancybox({
			'transitionIn'	:	'elastic',
			'transitionOut'	:	'elastic',
			'speedIn'		:	600, 
			'speedOut'		:	200, 
			'overlayShow'	:	false
		});*/
		if($('#car0').length > 0){
			startTimer();
		}
	
});

function switch_article(id, auto) {
	$('.ajax_article').each(function() {
								$(this).hide();
							});
							
	$('#ajax_' + id).fadeIn();
	
	if(!auto){
		timer_article = id +1;
	}
}