
#= require jquery

#= require jquery_ujs

#= require vendor/jquery-ui

#= require bootstrap

#= require ./vendor/jquery.flexslider
#= require ./vendor/markerclusterer

#= require ./vendor/jquery.mask
#= require ./vendor/jquery.fitvids
#= require ./vendor/jquery.bxslider
#= require redactor
#= require redactor_plugins/fontsize
#= require redactor_plugins/fontfamily
#= require redactor_plugins/fontcolor

#= require vendor/flipclock.js
#= require vendor/jquery.cookiebar.js


#= require jquery.waypoints.min
#= require main.js

#=require ./popover
top = 20


$(document).ready -> 
  
  $(document).on 'click', 'input.datepicker', ->
    $(this).datetimepicker(
      language: 'fr'
      pickTime: false
    ).focus();
    
  $(document).on 'click', 'input.datetimepicker', ->
    $(this).datetimepicker(
      use24hours: true
      format: 'DD/MM/YYYY HH:mm'
      minuteStepping:15
      language: 'fr'
    ).focus();
    
    
  $(document).on 'click', 'input.timepicker', ->
    $(this).datetimepicker(
      use24hours: true
      format: 'DD/MM/YYYY hh:mm'
      minuteStepping:15
      pickDate: false
      language: 'fr'
    ).focus();


@scroll_ajust = () ->
  var_scroll = $(window).scrollTop()
  
  
  #right petition
  rp_top_start = 0
  rp_menu_top_container_height = $("#menu_top_container").outerHeight()
  rp_window_height = $(window).height()
  rp_right_petition_height = $(".new_petition .right_pad").outerHeight() + 60
  rp_left_petition_height = $(".new_petition .left_pad").outerHeight()
  rp_top_stop = rp_left_petition_height - rp_window_height + 150
  #alert rp_left_petition_height
    
  lambda = rp_window_height - rp_menu_top_container_height - rp_right_petition_height
  if lambda < 0
    rp_top_start = (lambda * -1)
  
  if var_scroll >= rp_top_start
    if var_scroll >= rp_top_stop
      rp_top_value = rp_top_stop - rp_top_start
    else
      rp_top_value = var_scroll - rp_top_start
    $(".new_petition .right_pad").css
      "top" : rp_top_value
  else
    $(".new_petition .right_pad").css
      "top" : 0
    
    
  #alert rp_top_start
  
  #menu
  if var_scroll > top
    $(".sub_menu_bar").addClass("move_top")
    $("#menu_top_container").addClass("move_top")
    
  else
    $(".sub_menu_bar").removeClass("move_top")
    $("#menu_top_container").removeClass("move_top")
    
    
  #top_link
  if var_scroll > 100
    $(".top_link").css
      "opacity" : 1
  else
    $(".top_link").css
      "opacity" : 0






@resize = () ->
  
    
    
  scroll_ajust()
  #$(".bxslider li").each ->
  #  width = $(this).parent().width()
  #  $(this).css("width",$(this).parent().width()+"px")
  $("#main").css
    "min-height" :$(window).height()+"px"
  #$(this).closes
  

  $(".vertical_center").css("margin-top", "0")

  height = 0

  height = ($(window).height() - $(".vertical_center").outerHeight()) / 2 - 70
    
  if height > 0
    $(".vertical_center").css("margin-top", height+"px")


  $(".with_ratio").each ->
    ratio = parseFloat($(this).data("ratio"))
    height = $(this).width()*ratio
    
    $(this).css("height",height+"px")
    
  
  
  
      
$ ->
  $(window).on "resize", ->
    resize()


  
  resize()
  
  $(".flashs .remove").click ->
    $(this).parent().remove()
  $(document).on "scroll", ->
    scroll_ajust()
  
  $(document).on "touchmove", ->
    scroll_ajust()

  
  











