// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

$(document).ready(function(){
  initializeEventScrolling();
  
  $("#content .ajaxForm").jaxy();
  $('.scroll-pane').jScrollPane({
    scrollbarWidth: 4,
    scrollbarMargin: 12,
    showArrows: true
  });
  
  // $("#pageMonthUp").click(function(){
  //   $.getScript("events/next_month");
  // });
  // 
  // $("#pageMonthDown").click(function(){
  //   $.getScript("events/last_month");
  // });
  
});

// window.onload = initializeEventScrolling();

function initializeEventScrolling(){
  $("#calendar").smoothDivScroll({
    scrollingSpeed: 12,
    // mouseDownSpeedBooster: 3,
    // autoScroll: "",
    // autoScrollDirection: "endlessloop",
    // autoScrollSpeed: 1,
    // visibleHotSpots: "",
    // hotSpotsVisibleTime: 1,
    // startAtElementId: "",
    visibleHotSpots: "always",
    // hotSpotsVisibleTime: 6
  });
  
}

// function initializeEventScrollingAjax(contentUrl){
//   $("#calendar").smoothDivScroll({
//     scrollingSpeed: 12,
//     mouseDownSpeedBooster: 3,
//     autoScroll: "",
//     autoScrollDirection: "endlessloop",
//     autoScrollSpeed: 1,
//     visibleHotSpots: "allways",
//     // hotSpotsVisibleTime: 1,
//     startAtElementId: "",
//     ajaxContentURL: contentUrl
//   });
// }

function newEvent(){
  Shadowbox.open({
    content:  url='/admin/events/new',
    player:   'iframe',
    width:  800,
    height: 600
  });
  return false;
}

function editEvent(event_id){
  Shadowbox.open({
    content:  url='/admin/events/'+event_id.toString()+'/edit',
    player:   'iframe',
    width:  800,
    height: 600
  });
  // $("#eventManager").load("/admin/events/"+event_id.toString()+"/edit");
} 

function deleteEvent(event_id){
  $("#event_"+event_id+" .deletionMask").fadeIn();
}

function cancelEventDeletion(event_id){
  $("#event_"+event_id+" .deletionMask").fadeOut();
}

/**********
*
* fade different content section in and out.
*
**********/

jQuery.fn.fadeToggle = function(speed, easing, callback) {
  return this.animate({opacity: 'toggle'}, speed, easing, callback);  
};

$(document).ready(function(){
  $('#navigation a.events').click(function(){
    if(!$(this).hasClass('selected')){
      $("#content div.selected:not(.events)").fadeOut(
        1200
      );
      $('#navigation a.selected:not(.events)').removeClass('selected');
    
      $(this).toggleClass('selected');
      $('#content .calendar').addClass('selected');
    
      $("#content .calendar").fadeToggle(
        1200
      );
    }
  }
  );
  
  $('#navigation a.map').click(function(){
    if(!$(this).hasClass('selected')){
      $("#content div.selected:not(.map)").fadeOut(
        1200
      );
      $('#navigation a.selected:not(.map)').removeClass('selected');
    
      $(this).toggleClass('selected');
      $('#content .map').addClass('selected');
    
      $("#content .map").fadeToggle(
        1200
      );
    }
  }
  );
  
  $('#navigation a.newsletter').click(function(){
    if(!$(this).hasClass('selected')){
      $("#content div.selected:not(.newsletter)").fadeOut(
        1200
      );
      $('#navigation a.selected:not(.newsletter)').removeClass('selected');
    
      $(this).toggleClass('selected');
      $('#content .newsletter').addClass('selected');
    
      $("#content .newsletter").fadeToggle(
        1200
      );
    }
  }
  );
  
  $('#navigation a.contact').click(function(){
    if(!$(this).hasClass('selected')){
      $("#content div.selected:not(.contact)").fadeOut(
        1200
      );    
      $('#navigation a.selected:not(.contact)').removeClass('selected');
    
    
      $(this).toggleClass('selected');
      $('#content .contact').addClass('selected');
    
      $("#content .contact").fadeToggle(
        1200
      );
    }
  }
  );
  
  $('#eventContainer a.flyerZoom').click(function(){
    $('img.zoomed', $(this).parent().parent()).show();
    }
  );
  
  $('#eventContainer img.zoomed').click(function(){
    $(this).hide();
    }
  );
  
  $('#eventContainer img.zoomed').mouseleave(function(){
    $(this).hide();
    }
  );
  
  $('#editEventForm a.closeShadowbox').click(function (){
    alert("yeha");
    parent.Shadowbox.close();
    return false;
    }
  );
  
  // $('#topicsContents p').mouseleave(function(){
  //     $("#topicsContents p").fadeOut(
  //       1200
  //     );
  //     $('#navigation a.selected').removeClass('selected');
  //     
  //   }
  // );
  
  // $('#navigation a.events').click(function(){
  //   $("#topicsContents li.events").fadeToggle();
  // }
  // );
  // 
  // $('#navigation a.events').click(function(){
  //   $("#topicsContents li.events").fadeToggle();
  // }
  // );
  // 
  // $('#navigation a.events').click(function(){
  //   $("#topicsContents li.events").fadeToggle();
  // }
  // );  
  
});