
#= require jquery

#= require jquery_ujs

#= 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 ./popover
top = 20

@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 = () ->

      

      
  $('.small_thumb a').each -> 
    element = $(this)
    $(this).find('h4').each ->
      $(this).css('margin-top': ((element.height()-$(this).height())/ 2)+'px')
      
  
    
    
    
  scroll_ajust()
  
  
  $(".menu_itemlink_content").css("height", "auto");
  
  
  
  
  
  $(".menu_itemlink_content").each ->
    ratio = parseFloat($(this).data("ratio"))
    height = $(this).width()*ratio
    $(this).css("height",height+"px")
    
    title_height = $(this).find(".title").height()
    margin = (height-title_height-2)/ 2
    
    $(this).find(".title").css("margin-top",margin+"px")
    
    
  $(".article-2x-2, .article-small").each ->
    
    ratio = parseFloat($(this).data("ratio"))
    height = $(this).find(".inner").width()*ratio
    $(this).find(".inner").css("height",height+"px")
    
    title_height = $(this).find(".read_more").outerHeight()
    margin = (height-title_height-20-2)/ 2
    
    $(this).find(".read_more").css("margin-top",margin+"px")
    
    
    
  test = 10

  $("#home_slider").css("height", ($("#main").width()*(640 / 1200))+"px")
  
  $(".menu_item_top").css("min-height", ($(".widther").width()*(450 / 1200))+"px")
  
  $(".article_top").css("height", ($(".article_top").width()*(480 / 1200))+"px")
  
  

  left_size = ($(".right_follow .menu_itemlink_content:first").outerHeight()*2)+20
  
  $(".left_follow").css
    "min-height" :left_size+"px"
    
  
  image_actu_size = $(".home_articles:first").outerHeight()
  
  $(".home_image_actus .inner:first").css
    "min-height" :image_actu_size+"px"
  #//alert $("#main").width()*0.75
  if $(".widther").width() > 800
   
    dim = Math.round($(".widther").width()*0.70*(9 / 16))
  else
    dim = Math.round($(".widther").width()*1*(9 / 16))

  banner_padding = parseInt($("#slider_banner").data("padding"))
  $("#slider_banner").css("height", (dim+banner_padding)+"px")
  $("#slider_right .inner").css 
    "height" : dim+"px"
  $("#slider_left").css 
    "height" : dim+"px"
    
  $(".with_ratio").each ->
    ratio = parseFloat($(this).data("ratio"))
    height = $(this).width()*ratio
    
    $(this).css("height",height+"px")
    
  petition_height= 0
  $(".petition_line_inner").each ->
    if $(this).height() > petition_height
      petition_height = $(this).height()
    
  $(".petition_line .petition_line_inner").css("height", petition_height+"px")
      
      
  donate_pannel_height= 0
  $(".dons_top .donate_panel .inner").css "height", "auto"
  $(".dons_top .donate_panel .inner").each ->
    if $(this).height() > donate_pannel_height
      donate_pannel_height = $(this).height()
    
  $(".dons_top .donate_panel .inner").css("height", donate_pannel_height+"px")
  
  $(".payment_panel .submit_line").css("margin","auto")
  
  margin = ($(".payment_panel .inner").height() - $(".payment_panel .inner_content").height())/ 2 - 30
  if margin > 0.0
    $(".payment_panel .submit_line").css("margin-top",margin+"px")

  donate_pannel_height= 0
  $(".donate_content .donate_panel .inner").css "height", "auto"
  $(".donate_content .donate_panel .inner").each ->
    if $(this).height() > donate_pannel_height
      donate_pannel_height = $(this).height()
  $(".donate_content .donate_panel .inner").css("height", donate_pannel_height+"px")
  
  
  $(".home_articles .row").each ->
    articles_height = 0
    $(this).find(".description").css "height", "auto"

    if $(window).width() >= 800 
      $(this).find(".description").each ->
        if $(this).outerHeight() > articles_height
          articles_height = $(this).height()
      $(this).find(".description").css("height", (articles_height)+"px")
  
  
  
  $("#enquete_overlay .inner").css('margin-top': (($(window).height()-($("#enquete_overlay .inner").height()+30))/ 2)+'px')
  $("#enquete_overlay").click ->
    $("#enquete_overlay").fadeOut()
  
  $("#enquete_overlay .close").click ->
    $("#enquete_overlay").fadeOut()
  
  $("#enquete_overlay .site").click ->
    $("#enquete_overlay").fadeOut()
    
  $("#document_cart").css('margin-top': (($(window).height()-($("#document_cart").outerHeight()+0))/ 2)+'px')
  
  $(".adjust").each ->
    adjust_height= 0
    $(this).find(".element").css("height", "auto")
    if $(window).width() > 800
      $(this).find(".element").each ->
        
        if $(this).height() > adjust_height
          adjust_height = $(this).height()
    
      $(this).find(".element").css("height", adjust_height+"px")
  
  
  
  
      
$ ->
  $(window).on "resize", ->
    resize()


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

  
  $(".top_link").click ->
    $('html,body').animate({scrollTop: 0},'slow');
  
  $(document).on "click", ".specific_detail", ->
    $('html,body').animate({scrollTop: $(".detail_inner").offset().top},'slow');
  



  blog_category_animation = true


  $(".blog_category a").click ->
    blog_category_animation = false
    blog_category_go_to_link($(this))
    
    false
    
  blog_category_go_to_link = (link) ->
    $(".blog_category a").removeClass("active")
    link.addClass("active")
    $(".animate_index .index_category").fadeOut()
    $("#index_category_"+link.data('id')).fadeIn()
    resize()
    
    
  blog_category_next = () ->
    if blog_category_animation == true
    
      blog_category_active = $(".blog_category a.active:first")
    
      if blog_category_active.next("a").length > 0
        link = blog_category_active.closest("a").next("a")
      
      
      
      else
        link = blog_category_active.closest("div").children("a:first")
    

      blog_category_go_to_link(link)
    

  animate_blog_category = () ->
  
    setTimeout (->
      blog_category_next()
      animate_blog_category()
      return
    ), 5000
  
    
  
  animate_blog_category()
  
  
  investigations_animation = true 
  
  $("#investigation_next").click ->
    #investigations_animation = false
    investigations_next()
    
    false
  
  $("#investigation_prev").click ->
    #investigations_animation = false
    investigations_prev()
    
    false
    
  investigations_go_to_link = (link) ->
    $(".investigation_row").removeClass("active")
    link.addClass("active")
    
    resize()
  
  
    
  investigations_next = () ->
    if investigations_animation == true
    
      investigations_active = $(".investigation_row.active:first")
    
      if investigations_active.next(".investigation_row").length > 0
        link = investigations_active.next(".investigation_row")

      
      else
        link = $(".investigations .investigation_row:first")
    

      investigations_go_to_link(link)
  
  investigations_prev = () ->
    if investigations_animation == true
    
      investigations_active = $(".investigation_row.active:first")
    
      if investigations_active.prev(".investigation_row").length > 0
        link = investigations_active.prev(".investigation_row")

      
      else
        link = $(".investigations .investigation_row:last")
    

      investigations_go_to_link(link)
    

  animate_investigations = () ->
  
    setTimeout (->
      investigations_next()
      animate_investigations()
      return
    ), 5000
  
    
  
  animate_investigations()
  
  
  
  
  
  
  











