Topic: determining layouts based on javascript

Not sure if this is the right forum, but i think this is more of a design issue, if not, i apologize in advance.

Heres my problem, I have 2 different layouts (significantly different...) and i have to choose which one to display based on screen size. Originally the site i am working on was built with php, and here is what the index.html file looks like:

<script type="text/javascript">
<!-- Begin
        if(screen.width > xxx)
        {
                 window.location = "file1.php";

        }
        else {
                window.location='file2.php";
        }
// End -->
</script>


basically, based on the screen size, a specific php file would be loaded...not the original design is not very desired, as the content within these files and the links from each one would be the same, it was just the display (i.e. the layout) which greatly differed.

so basically, i am trying to do this in rails with layouts, and save us development time in the future....i.e. if we add a link to our footer, i would have to go through all the pages (for both template1 and template2) and add it...

so then i started thinking that maybe i could store the current template view as a session variable, and have it set by calling an action...basically something like this:

my index.html file:

<script type="text/javascript">
<!-- Begin
        if(screen.width > xxx)
        {
                 window.location = "http://www.mysite.com/mode/1";

        }
        else {
                window.location="http://www.mysite.com/mode/2; technically, this isn't needed, since there are only 2 templates (so if one isn't chosen, then obviously, use the other one.
        }
// End -->
</script>

and in my controller:

  layout :layout_mode_func

  def mode
    if params[:id] == 1
      self.layout_mode = true
    else
      self.layout_mode = false
    end
  end

 
private
  def layout_mode_func
    self.layout_mode ? "template1" : "template_2"
  end


i tried this, and i ran into a couple of problems....first off, the controller couldn't find the variable self.layout_mode within the layout_mode_func action (not sure what i did wrong), secondly, i dont want to use a layout for the index action, but i havent been able to figure that out either.

so basically, my questions sum up to:

   1) is this possible
   2) if so, am i going about it in the right way?
   3) if so, how can i get around the problems i have run into?

thanks!