﻿$(function() {
  //Hide layers to start
  $('#create_fundraising_event_layover').hide()
  $('#create_fundraising_celebration_layover').hide()

  //Set up the triggers
  $('.cp_create_event_button').click(function() {

    //Show the event
    $('#create_fundraising_event_layover').fadeIn(150).css({
      zIndex: 99
    })
    $('#create_fundraising_celebration_layover').hide()

    return false;

  })
  $('.cp_create_celebration_button').click(function() {

    //Show the celebration
    $('#create_fundraising_celebration_layover').fadeIn(150).css({
      zIndex: 99
    })
    $('#create_fundraising_event_layover').hide()

    return false;

  })

  //Set up the auto fadeouts
  create_event_out = "";
  create_celebration_out = "";

  // Event
  $('#create_fundraising_event_layover').mouseleave(function() {

    create_event_out = setTimeout(function() {
      $('#create_fundraising_event_layover').fadeOut(150, function() {
        clearTimeout(create_event_out)
      })

    }, 800)

  })
  $('#create_fundraising_event_layover').mouseenter(function() {

    clearTimeout(create_event_out)

  })

  // Celebration
  $('#create_fundraising_celebration_layover').mouseleave(function() {

    create_event_out = setTimeout(function() {
      $('#create_fundraising_celebration_layover').fadeOut(150, function() {
        clearTimeout(create_event_out)
      })

    }, 800)

  })
  $('#create_fundraising_celebration_layover').mouseenter(function() {
    clearTimeout(create_event_out)
  })

})
