$(document).ready(function() {
    // tabs toevoegen
    $('.cg_tabs').tabs();

    // fotoalbum fancybox
    $("#cg_fotos a").fancybox({
   		transitionIn : 'elastic',
   		transitionOut : 'elastic',
   		titleShow : true,
   		titlePosition : 'outside',
   		padding : 5,
   		scrolling : 'no',
   		autoDimensions : false,
   		width : 800,
   		height : 680,
   		autoScale : false,
   		speedIn : 600, 
   		speedOut : 200, 
   		overlayShow : true,
   		cyclic: true,
   		showNavArrows: true
   	});

    // ajax zoeken toevoegen aan almanak
    $('#cg_almanak_filter').keyup(function() {
    	CG_delayRequest($(this).val());
    }).focus(function() {
    	$(this).select();
    });

    // show more photo's in profile
	$('.cg_foto_more').toggle(function() {
		$('.cg_foto_item.cg_foto_hide').each(function(index, element) {
			$(this).show(600);
		});
		$('.cg_foto_item img.cg_foto_hide').each(function(index, element) {
			$(this).delay(600+index*150).fadeIn(300);
		});
		$('.cg_foto_more').addClass('cg_foto_less');
	}, function() {
		$($('.cg_foto_item img.cg_foto_hide').get().reverse()).each(function(index, element) {
			$(this).delay(index*50).fadeOut(100);
		});
		$('.cg_foto_item.cg_foto_hide').delay($('.cg_foto_item img.cg_foto_hide').length*50).hide(300);
		$('.cg_foto_more').removeClass('cg_foto_less');
	});

    // datepicker toevoegen
    $('.datepicker').datepicker({
		dateFormat: 'dd/mm/yy',
		changeMonth: true,
		changeYear: true,
		showWeek: true,
		numberOfMonths: 1,
		showAnim: 'fadeIn',
		showOtherMonths: true,
		selectOtherMonths: true
	});
});

var CG_timer, CG_zoek;

function CG_delayRequest(zoek) {
  CG_zoek = zoek;
  if (CG_timer) {
    clearTimeout(CG_timer);
  }
  if(zoek.length > 2) {
    CG_timer = setTimeout("CG_makeRequest()", 200);
  }
  else {
	$("#cg_almanak_results").html("<p></p>");
  }
}
function CG_makeRequest() {
	$.ajax({
	  url: "parse.php",
	  cache: false,
	  type: "GET",
      data: "item=13&action=view_almanak&filter="+CG_zoek,
      dataType: "html",
      beforeSend: function() {
        $("#cg_almanak_results").html('<div style="text-align: center;"><img src="_template/standard/graphics/congressus/loading.gif" alt="loading..." /></div>');
      },
      success: function(html){
    	$("#cg_almanak_results").fadeOut(100);
    	setTimeout(function() {$("#cg_almanak_results").html(html).fadeIn(500);}, 100);
      }
	});
}
