#= require jquery
#= require jquery_ujs
#= require ./vendor/jquery.flexslider
#=require ./popover
#= require jquery.waypoints.min
#= require main.js
$ ->



  $("#toggle-menu").click -> 
    
    $("#top_bar .menu").slideToggle()



  top = 120

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

    $(".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")

    test = 10

    $("#home_slider").css("height", ($("#main").width()*(9 / 26))+"px")

    $("#home_slider .inner").css("height", ($("#main").width()*(9 / 26))+"px")

    $("#popup_content").css
      "margin-top":"30px"
      "height" : ($(window).height()- 60 )+"px"
  $("body").on "click", ".close_popup", ->
    $(".popup_overlay").fadeOut();
    $(".popup_container").fadeOut 400, ->
      $(".popup_overlay").remove()
      $(".popup_container").remove()

  $(window).on "resize", ->
    resize()



  resize()


  $(document).on "scroll", ->
    scroll_ajust()

  $(document).on "touchmove", ->
    scroll_ajust()

  scroll_ajust = () ->
    var_scroll = $(window).scrollTop()
    if var_scroll > top
      $("#top_bar").addClass("move_top")
    else
      $("#top_bar").removeClass("move_top")

    if var_scroll > top
      $(".top_link").css
        "opacity" : 1
    else
      $(".top_link").css
        "opacity" : 0

  $(".top_link").click ->
    $('html,body').animate({scrollTop: 0},'slow');
