var rsh_branche = 0;

function loadStreet( street )
{
  frameNr = 2;

  switch( street )
  {
    // Niet op de kaart:
    case 'Kalverstraat'       : { frameNr = 2;  break; }
    case 'Magelhaenstraat'    : { frameNr = 2;  break; }

    // De 9 straatjes:
    case 'Gasthuismolensteeg' : { frameNr = 3;  break; }
    case 'Romeinsarmsteeg'    : { frameNr = 4;  break; }
    case 'Oude Spiegelstraat' : { frameNr = 5;  break; }
    case 'Wijde Heisteeg'     : { frameNr = 6;  break; }
    case 'Hartenstraat'       : { frameNr = 7;  break; }
    case 'Wolvenstraat'       : { frameNr = 8;  break; }
    case 'Huidenstraat'       : { frameNr = 9;  break; }
    case 'Reestraat'          : { frameNr = 10; break; }
    case 'Berenstraat'        : { frameNr = 11; break; }
    case 'Runstraat'          : { frameNr = 12; break; }

    // Grachten
    case 'Herengracht'        : { frameNr = 13; break; }
    case 'Singel'             : { frameNr = 13; break; }
    case 'Keizersgracht'      : { frameNr = 14; break; }
    case 'Prinsengracht'      : { frameNr = 15; break; }
  }

  new Ajax.Updater(
    'store_listing', 
    s_WEBROOT + '/shared/components/flash.cfc?method=getShopsByStreet', 
    { 
      parameters  : { 
                      street : street,
											lan		 : _currentLanguage
                    }
    } 
  );

  $( 'aanbiedingen_nieuwsflits' ).style.display = "none";
  $( 'store_bystreet' ).style.display = "";
  $( 'flash_content' ).style.width = flash_streetwidth+"px";
  $( 'flash_content' ).style.styleFloat = $( 'flash_content' ).style.cssFloat = "right";

  FlashReplace.replace(
    "flash_content", 
    flash_file,
    "kaartObj",
    flash_streetwidth,
    flash_height,
    8,
    {
      wmode : "transparent"
    }
  );

  setTimeout(
    function()
    {
      new Scroller( $( 'store_listing' ));

      $( 'kaartObj' ).style.width = flash_streetwidth+"px";
      $( 'kaartObj' ).loadStreetInFlash( frameNr );
    },
    1000
  );
}

function loadBranche( branche )
{
  rsh_branche = branche;
  trackMe();
  delay = 10;

  if( $( 'flash_content' ).style.width != flash_width+"px" )
  {
    delay = 1000;
    $( 'aanbiedingen_nieuwsflits' ).style.display = "";
    $( 'store_bystreet' ).style.display = "none";
    $( 'flash_content' ).style.width = flash_width+"px";
  
    FlashReplace.replace(
      "flash_content", 
      flash_file,
      "kaartObj",
      flash_width,
      flash_height,
      8,
      {
        wmode : "transparent"
      }
    );
  }

  setTimeout(
    function()
    {
      $( 'kaartObj' ).style.width = flash_width+"px";
      $( 'kaartObj' ).loadShopsInFlash( branche );
    },
    delay
  );
}

window.dhtmlHistory.create({
      toJSON: function(o) {
              return Object.toJSON(o);
      }
      , fromJSON: function(s) {
              return s.evalJSON();
      }
    });
      

function initialize(id) {
  // initialize RSH
  dhtmlHistory.initialize();
  
  // add ourselves as a listener for history
  // change events
  dhtmlHistory.addListener(collectionChangesHandle);
  
  // determine our current location so we can
  // initialize ourselves at startup
  var initialLocation = 
                dhtmlHistory.getCurrentLocation();
  
  // if no location specified, use the default
  if (initialLocation == null)
    alert("");
  
  // now initialize our starting UI
/* [] 6/25/2008   updateUI(initialLocation, null); */

}

/** A function that is called whenever the user
    presses the back or forward buttons. This
    function will be passed the newLocation,
    as well as any history data we associated
    with the location. */
function collectionChangesHandle(newLocation,
                             historyData) {
  // use the history data to update our UI
  updateUI(newLocation, historyData);                           
}

/** A simple method that updates our user
    interface using the new location. */
function updateUI(newLocation, historyData) {
  
  // simply display the location and the
  // data
  
  if( newLocation != "")
  {
    branche     = listGetAt(newLocation,1,'_');
    
    if( branche != 0)
      $( 'kaartObj' ).loadShopsInFlash( branche );
  }

}


function trackMe()
{        
  dhtmlHistory.add('location_' + rsh_branche,{}) 
}