Content = new (function() {
   var _hash, _currentMovie = undefined, _this = this, _flashObject = undefined, _docReady = false;
   
   _this.constructor = undefined;
   
   _this.setPageTitle = function(key, obj) {
      
      var p;
      
      if(typeof obj == 'string')
         p = obj;
      else if((typeof obj == 'object') && (typeof obj.innerHTML == 'string'))
         p = obj.innerHTML;
      else
         p = 'Live it';
      
      Utils.log('setPageTitle:'+ p);
      document.title = p.replace('&amp;', '&');
   }
   
   _this.show = function(id) {
      $('#lg').css('display', (id == 'bs') ? 'block' : 'none');
      $('#real-content').css('display', (id == 'default') ? 'block' : 'none');
      
      if (id == 'bs') {
         $('#menu a').css('background-image', '');
         this.redrawRight();
      }
   }
   
   _this.showBox = function(mode) {
      $('#startBox').css('display', (mode == 'start') ? 'block' : 'none');
      $('#cart').css('display', (mode == 'cart') ? 'block' : 'none');
   }

   _this.loadMovie = function(url) {
      if((url === undefined) && (_currentMovie === undefined))
         return;

      if((url !== undefined) && (_currentMovie === url))
         return;
      
      _currentMovie = url ? url : _currentMovie;
      
      if(_docReady == false)
         return;
      
      try {
         swfobject.embedSWF(_currentMovie, 'flashObject', '655', '225', '9.0.0', 'expressInstall.swf',
               {}, { wmode: 'transparent' }, {} );
      }
      finally {
      }
   }
   
   _this.showProduct = function(id) {
      _this.show('bs');
      bsShowProduct(id);
   }

   _this.showCategory = function(id, obj) {
      if(id == 29) {
         bsFilter('_RESET', 0, true, true);
         return;
      }
         
      bsFilter('_RESET', 0, true, false);
      bsFilter('CATEGORY_ID', id, false, true);
      $('#real-content').css('display', 'none');
      $('#lg').css('display', 'block');
      
      Content.setPageTitle(id, obj);
   }
   
   _this.load = function(options) {
      /* This is the old, deprecated, way. */
      if ((typeof options != 'object')) {
         Utils.log('Using deprecated variant of Content.load');
         options = { 
            url: arguments[0],
            image: (typeof arguments[1] == 'string') ? arguments[1] : undefined
         }
      }

      if ((matches = options.url.match(/^\/?([a-zA-Z0-9_-]+)((?:\/[a-zA-Z0-9_-]+)*)[\/]*$/)) === null)
         return;

      var page = matches[1], url = matches[1] + matches[2]; 
      
      if ((typeof Cart.getObject()) == 'undefined')
         _this.showBox('cart');
      else if ((page == 'start') && (Cart.getObject().products.length == 0))
         _this.showBox('start');
      else
         _this.showBox('cart');
      
      if (typeof options.data != 'object')
         options.data = {};

      options.data.sid  = SID;
      options.data.ajax = true;
      
      /* TODO: Do we really have to do this? */
      Cart.update();

      Page = { }
      
      location.hash = _hash = '#' + url;
      
      Utils.log('Content.load( { url: \'' + options.url + '\' } );');
      
      $('#lg').css('display', 'none');
      $('#real-content').css('display', 'block');

      $('#menu a').css('background-image', '');
      
      var menuButtons = {
         'start':           [ 0, '/images/topmenu/startsida_on.png'       ], 
         'hur_du_koper':    [ 1, '/images/topmenu/hur_du_koper_on.png'    ],
         'boka_upplevelse': [ 2, '/images/topmenu/boka_upplevelse_on.png' ],
         'om_oss':          [ 3, '/images/topmenu/om_oss_on.png'          ],
         'fragor_och_svar': [ 4, '/images/topmenu/fragor_on.png'          ],
         'kontakt':         [ 5, '/images/topmenu/kontakt_on.png'         ],
         'foretag':         [ 6, '/images/topmenu/foretag_on.png'         ],
         'i_butik':         [ 7, '/images/topmenu/i_butik_on.png'         ]
      }

      if (typeof menuButtons[page] != 'undefined') {
         var menuButton = menuButtons[page];
         $('#menu-button-' + menuButton[0]).css('background-image', 'url(' + menuButton[1] +')');
      }
     

      Utils.request({
         url: '/contents/' + url,
         data: options.data,
         success: function(result) {
            window.scroll(0, 0);
         
            if (typeof result.title == 'string')
               document.title = result.title;

            pageTracker._trackPageview('/' + page);
            
            _this.loadMovie((typeof options.image == 'string') ? options.image : result.image);

            $('#real-content').html(result.content);
            $('#real-content').append('<div class="cb"></div>');
            
            /* load left banners to the left column if   */
            /* supplied as part of content               */
            $('#l_banner').html($('#l_banner_load').html());
            
            Utils.autoLink('#real-content a');
            
            if (typeof Page.onLoad == 'function')
               Page.onLoad();
         }
      });
   }

   this.setHash = function(hash) {
      location.hash = _hash = hash;
   }
   
   this.redrawRight = function() {
      var html;
      
      html  = '';
   
      var img = Cart.hasGiftVoucher() ? '/images/kuvert.jpg' : '/images/liveitbox_frontpage.jpg';
      
// Not enough space for picture
/*      
      html += '<img style="display:block;margin-left:auto;margin-right:auto;margin-bottom:10px;" src="' + 
                  img + '" style="margin-left: 10px; margin-top: 10px;"/>';
*/      
      html +=
         '<div class="tS" style="width:170px;">' +
         '<a href="/fragor_och_svar/vad_ar_en_e-box"><img src="pics/banners/ebox.jpg" style="padding-bottom: 10px; padding-left: 5px; border: 0" border="0" /></a>' +
         '</div>';

      

      
      html +=
         '<div style="position:relative; width:160px; height:180px; margin:0 5px; border: 1px solid; border-color: #ddded9;' +
         'background: url(/pics/tipsaenkompis.jpg) no-repeat;">' +
         '<input type="text" style="position:absolute; top:64px; left:12px; ' +
         'width:133px; border:none; background: transparent; font-family: Arial, Sans; font-size:11px; ' +
         'margin:0px; padding:0px; color: #444444;" id="tip_from" onfocus="this.value=\'\'; this.style.color=\'black\'" value="Från: Ditt Namn " />' +
         
         '<input type="text" style="position:absolute; top:86px; left:12px; ' +
         'width:133px; border:none; background: transparent;  font-family: Arial, Sans; font-size:11px; ' +
         'margin:0px; padding:0px; color:#444444;" id="tip_to" onfocus="this.value=\'\'; this.style.color=\'black\'" value="Till: kompis@mail.se " />' +

         '<textarea style="position: absolute; top:108px; left:12px; ' +
         'width:138px; height:48px; border:none; background: transparent;   font-family:Arial, Sans; font-size:11px; ' +
         'margin:0px; padding:0px; color:#444444;" onfocus="this.value=\'\'; this.style.color=\'black\'" id="tip_msg">meddelande</textarea>' +
         
        '<div style="position:absolute; top:160px; left:96px; height: 17px; ' +
        'width:51px; border:none; background: transparent; cursor:pointer;" ' +
        'onclick="Utils.emailToAFriend($(\'#tip_from\').val(),$(\'#tip_to\').val(),$(\'textarea#tip_msg\').val());"></div></div>';
      
      $('#lg #productBanners').html(html);
   }
   
   $('document').ready(function() {
      _docReady = true;
      
      var matches;
      
      if((matches = location.hash.match(/^#(?!s=s)(.*)$/)) != null) {
         Content.load(matches[1]);
      }
   
      else {
         _this.loadMovie();
      }
   });
   
   
});



