// JavaScript Document



function filterResults(brand){
   $("#products_container").load('/index.php/filtercategory', {'brand' : brand});

}
function getCategory(category){
    $("#products_container").load('/index.php/content/category?title=' + category,'', function(){
        $('#'+ category +'_brands').slideDown();
    } );
    
}

function paginate(category, page){
    $("#products_container").load('/content/category?title=' + category + '&page=' + page); 
}




function sendForm(div, place){
    $('.afspraak_button').css('display', 'none');
    if(validator() == true){
      
  
    $.ajax({url:'/index.php/afspraak', method: 'post', data:{'naam': $('#aanhef').val() + $("#naam").val(), 'email': $("#email").val(), 'product': $("#product").val(), 'onderwerp': $('#onderwerp').val() + 'filiaal:' + $('#filiaal').val(), 'bericht': $('#bericht').val(), 'tel': $('#tel').val(), 'filiaal': $('#filiaal').val() }, complete: function(){if(place ==''){alert('Uw  bericht is succesvol verzonden');$('#afspraak_form').dialog('destroy')}
            
        }});
    return;
    }
    else{
        alert('U moet een naam en nummer opgeven om een afspraak te kunnen maken');
        return ;
    }
   
}
function getMap(id){
    $("#map").load('/index.php/contact/map?id=' + id);
}
function expandCategory(category){
    $(category).slideDown(500);
}
function Details(){
    
    $("img.products").hover(function(){
      
       var  id = '#' + 'details_' + $(this).attr('id');
     $(".pactive").hide();
      $(id ).slideDown().addClass('pactive');

    });
    

   
}
function startRotator(){

$("#home_images div:first").addClass("active").show();
rotateSwitch(); 
}
function rotate(){
    var triggerID = $active.attr("id") - 1; //Get number of times to slide
     //Determines the distance the image reel needs to slide

    $("#home_images div").removeClass('active').fadeOut(1000);
   //Remove all active class
    $active.addClass('active').fadeIn(1000); //Add active class (the $active is declared in the rotateSwitch function)

    //Slider Animation
  

}
var rotateSwitch = function(){
    var play = setInterval(function(){ //Set timer - this will repeat itself every 7 seconds
        $active = $('#home_images div.active').next(); //Move to the next paging
        
        if ( $active.length === 0) { //If paging reaches the end...
            $active = $('#home_images div:first'); //go back to first
        }
        rotate(); //Trigger the paging and slider function
    }, 7000); //Timer speed in milliseconds (7 seconds)
};

function nextImage(){
  $active =  $("#image_wrap div.active").next();

  if($active.length === 0){
      $active = $('#image_wrap div:first');
  }
  $("#image_wrap div.active").removeClass('active').fadeOut(1000);
  $active.addClass('active').fadeIn(1000)
  }
function previousImage(){
  $active =  $("#image_wrap div.active").prev();

  if($active.length === 0){
      $active = $('#image_wrap div:last');
  }
  $("#image_wrap div.active").removeClass('active').fadeOut(1000);
  $active.addClass('active').fadeIn(1000);
  }
function initializeImages(){
    $("#left").click(function (){
        previousImage();
    });
    $("#right").click(function (){
       
        nextImage();
    });
   
    $("#image_wrap div:first").addClass('active').fadeIn(1000);
}


function openDialog(){


 $('#afspraak_form').dialog('open');


}

function validator(){
    var valid = true;
    $('.afspraak_input ').each(function(){
        if($(this).val() == '' ){
            
            valid = false;
            $(this).addClass('invalid');
        }
        
    })

    return valid;
}