$(".fbdisconnect").live("click", function(){
  FB.logout(function(response) {
     window.location.reload();
  });   
  return false;
});


$(".fblogin").live("click", function(){
   FB.login(function(response) {
     if (response.session) {
       // user successfully logged in
       window.location.reload();
     }else{
       console.log("Facebook login mislukt.");
     }
   }, {perms:'email,user_events,user_hometown,user_birthday'}); 
  return false;
});

$(document).ready(function(){
    init();
    
    //support form
    $("#supportform form").live("submit", function(){
      action = $(this).attr("action");
      data = $(this).serialize();
      $.post(action, data, function(response){ $("#supportform").replaceWith(response); });
      return false;
    });
});


//handle these links as ajax
$("#nav a, a.ajax").live("click", function(){
   url = $(this).attr("href");
   $("#loading").show();
   $.post(url, {ajax:1}, function(data){ $("#siteHolder").replaceWith(data); init(); $("#loading").hide(); });
   return false;
});  
    

function init(){   
  // simple accordion
  jQuery('#news').accordion({
    autoheight: false,
    header: 'h3'
  });
        
  $("a.agendaEvent").fancybox({ 'overlayOpacity': 0.8 });   
  

   $('.mb-slider').movingBoxes({
    startPanel   : 1,      // start with this panel
    width        : 500,    // overall width of movingBoxes (not including navigation arrows)
    wrap         : true,   // if true, the panel will "wrap" (it really rewinds/fast forwards) at the ends
    buildNav     : false,   // if true, navigation links will be added
    panelType    : '> li', // selector to find the immediate ">" children "li" of "#slider-one" in this case
    navFormatter : function(){ return "&#9679;"; } // function which returns the navigation text for each panel
   });
   
  $("#accordion").accordion({ autoHeight: false });


   /*
    *   Examples - images
    */

   $("a.fancy").fancybox({
        'autoScale'     : true,
        'transitionIn'    : 'elastic',
        'transitionOut'   : 'elastic',
      });

   $("a.fancyFrame").fancybox({
        'width'       : '98%',
        'height'      : '98%',
        'autoScale'     : false,
        'transitionIn'    : 'elastic',
        'transitionOut'   : 'elastic',
        'type'        : 'iframe'
      });
      
  var script = 'http://s7.addthis.com/js/250/addthis_widget.js#pubid=xa-4e2d83d401f3952e&domready=1';
  if (window.addthis){
     window.addthis = null;
  }
  $.getScript( script );      
}

//tracj analytics with jquery ajax
(function ($) {

  // Log all jQuery AJAX requests to Google Analytics
  $(document).ajaxSend(function(event, xhr, settings){ 
    if (typeof _gaq !== "undefined" && _gaq !== null) {
      _gaq.push(['_trackPageview', settings.url]);
    }
  });

})(jQuery);

