// Really Simple History
window.dhtmlHistory.create();

var historyChange = function(newLocation, historyData) {
  if(newLocation == 'start')
  {
    loadApplication();
    document.title = 'podkast.pl';
  }
  if(newLocation == 'demo')
  {
    showContent('demo.php');
    document.title = 'podkast.pl';
  }
  else if(newLocation.indexOf('podkast/') != -1)
  {
    historyVariables = newLocation.split('/');
    showPodcast(historyVariables[1]);
    document.title = 'podkast.pl';
  }
  else if(newLocation.indexOf('tag/') != -1)
  {
    historyVariables = newLocation.split('/');
    showContent('tagView.php', 'tag='+historyVariables[1]);
    document.title = 'podkast.pl';
  }
  else if(newLocation == 'dodaj')
  {
    showContent('dodaj.php');
    document.title = 'podkast.pl';
  }
  else if(newLocation == 'roman')
  {
    showContent('generator/index.php');
    document.title = 'podkast.pl';
  }
  else if(newLocation == 'kategorie')
  {
    showContent('selectFolder.php');
    document.title = 'podkast.pl';
  }
  else if(newLocation == 'rejestracja')
  {
    showContent('register.php');
    document.title = 'podkast.pl';
  }
  else if(newLocation.indexOf('szukaj/') != -1)
  {
    historyVariables = newLocation.split('/');
    showContent('szukaj.php', 'zapytanie='+historyVariables[1]);
  }
  else if(newLocation == 'o-podkast.pl')
  {
    showContent('about.php');
    document.title = 'podkast.pl';
  }
  else if(newLocation == 'kontakt')
  {
    showContent('contact.php');
    document.title = 'podkast.pl';
  }
  else if(newLocation == 'warunki-uzywania')
  {
    showContent('terms.php');
    document.title = 'podkast.pl';
  }
  else if(newLocation == '')
  {
    loadApplication();
    document.title = 'podkast.pl';
  }
  window.scroll(0, 0);
}

if(dhtmlHistory.isIE)
{
    document.body.onload = function() {
      dhtmlHistory.initialize();
      if(dhtmlHistory.currentLocation) { historyChange(dhtmlHistory.currentLocation); }
      else loadApplication();
      dhtmlHistory.addListener(historyChange);
      if(!dhtmlHistory.currentLocation) dhtmlHistory.add('start', '0');
    };
}
else
{
    document.getElementById('rsh-script').onload = function() {
      dhtmlHistory.initialize();
      if(dhtmlHistory.currentLocation)
      {
          dhtmlHistory.currentLocation = dhtmlHistory.currentLocation.split('?');
          GoogleAnswer = dhtmlHistory.currentLocation[1];
          dhtmlHistory.currentLocation = dhtmlHistory.currentLocation[0];
          if(GoogleAnswer)
          {
              GoogleAnswerInterpret(GoogleAnswer);
          }
      }
      if(dhtmlHistory.currentLocation) { historyChange(dhtmlHistory.currentLocation); }
      else loadApplication();
      dhtmlHistory.addListener(historyChange);
      if(!dhtmlHistory.currentLocation) dhtmlHistory.add('start', '0');
    };
}

addHistory = function(name, description) {
  dhtmlHistory.add(name, description);
  historyChange(name, description);
}
// End RSH
