class HomeController < ApplicationController

  def index
    @user_session = UserSession.new

    query = "Mach mit beim Stadtplan der Globalisierung!"

    if Page.exists?(['title LIKE ?', "%#{query}%"])
      @page = Page.find(:first, :conditions => ['title LIKE ?', "%#{query}%"])
    else
      @page = Page.new()
      @page.title = query
      @page.content = "..."
      @page.save
    end

    # query = "Mitmachen"
    # if Page.exists?(['title LIKE ?', "%#{query}%"])
    #  @button = Page.find(:first, :conditions => ['title LIKE ?', "%#{query}%"])
    # end
    if Page.exists?(['id = ?', 4])
      @button = Page.find(4)
    end


    @maps = Map.find_all_by_public(true)


    @placemarks = Placemark.find(:all, :order => "updated_at DESC", :conditions => ["public = ?", true])
    # @placemarks = Placemark.all

    respond_to do |format|
        format.json { render json: @placemarks.to_json(:methods => [:internal_link, :map_icon_url]) }
        format.html { render }

    end
  end

end

