# -*- encoding : utf-8 -*-
module MenuItemsHelper
  
  def menu_item_link(menu_item, active = nil)
    @lang = @lang || LangSite.first
    menu_item_lang = menu_item.menu_item_langs.find_by_lang_site_id(@lang.id)
    if active == nil
      if @menu_item and (@menu_item == menu_item or @menu_item.ancestors.include?(menu_item))
        active = true 
      else
        active = false
      end
    end
    name = menu_item_lang.name
    if menu_item_lang.enabled == true and menu_item_lang.visible == true
      link_to name, menu_item_path(:url => menu_item_lang.url), :class => ("active" if active)
    end
  end
  
  
  def menu_item_url(menu_item, sym = false)
  
    menu_item_lang = menu_item.menu_item_langs.find_by_lang_site_id(@lang.id)
    
    @menu_item and (@menu_item == menu_item or @menu_item.ancestors.include?(menu_item)) ? active = true : active = false
    
    name = menu_item_lang.name+("" if sym and @menu_item and @menu_item == menu_item ).to_s
    if menu_item_lang.enabled == true and menu_item_lang.visible == true
      menu_item_path(:url => menu_item_lang.url)
    end
  end

end
