      function scrollInitialize() {
          $('#scroll').jScrollPane({showArrows: true, scrollbarWidth: 16, dragMaxHeight: 16 });
          if ($('#scroll').hasClass('short')) {
            if ($.browser.name == "msie" && $.browser.version == "6.0") {
              $('.jScrollPaneContainer').width('423px');
              $('#scroll').width('423px');
              $('#article').css('padding-right','26px');
            }else{
              $('.jScrollPaneContainer').width('426px');
              $('#scroll').width('426px');
              $('#article').css('padding-right','26px');
            }
          }else{
            $('.jScrollPaneContainer').width('525px');
            $('#scroll').width('504px');
          }
          
          if ($('#scroll').hasClass('main')) {
            $('#scroll').width('525px');
          }
      }
  
  var previous_hash = "";
      
      function pageload(_hash) {
        previous_hash = hash;
        hash = _hash;
        if(hash) {
          $("#ajax-content").fadeOut(500);
          setTimeout("loadContent();", 500);
        } else {

        }
      }
      
      var hash, content;
      function loadContent() {
          if(hash) {
            $.ajax({url: hash+'.part', complete: function(xhr, status) {
              pageTracker._trackPageview(hash);
              $('#ajax-content').html(xhr.responseText).fadeIn(500);
              set_lightbox(); 
              
              var address = hash.split('/').slice(0, 4).join('/');
              var link = $('#main-menu li a[href^='+address+']');
              $('#main-menu li.selected').removeClass('selected').removeClass('here');
              if(link.length > 1) {
                $('#main-menu li:first').addClass('selected').addClass('here');
              } else {
                link.parent().addClass('selected');    
              }
              
              if($('#content-wrapper').hasClass('home')){
                mainFlash();
              }
              
              var number = getPageNumber(hash);
              $('#main-menu ul li').removeClass('selected');
              $($('#main-menu ul li')[number]).addClass('selected');
              scrollInitialize();
            }});
          }
      }
      
      
function loadFlash() {
        var so2 = new SWFObject("/uploads/flashe/biuro_norco_TOP.swf", "biuro_norco_TOP", "800", "149", "8");
        so2.addParam("wmode","transparent");
        so2.write("flash_top");
      }
      
      function mainFlash() {
        var so = new SWFObject("/uploads/flashe/biuro_norco_main.swf", "biuro_norco_main", "637", "340", "8");
        so.addParam("wmode","transparent");
        so.write("flash_main");
      }
      
      function getPageNumber(path) {
        var address = path.split('/').slice(0, 4).join('/');
        var link = $('#main-menu li a[href^='+address+']');
        $('#main-menu li.selected').removeClass('selected');
        var li = link.parent().addClass('selected');
        var number = $("#main-menu ul li").index(li[0]);
        
        return number;
      }
      

  var slideShow = {
    image: '',
    current_photo: 0,
    photos_count: 0,
    initialize: function() {
      var self = this;
      this.images = [];
      var photos = $('#slideshow ul li');
      photos.each(function(){
        self.images.push($(this).html());
      });
      this.photos_count = photos.length;
      this.loadPhotos(0);
      this.changePhoto();
    },
    next: '',
    previous: '',
    preloaded_images: [],
    loadPhotos: function(current_photo) {
      if(current_photo + 1 > this.photos_count) {
        return;
      }
      var image = new Image;
      var self = this;
      image.onload = function() {
        self.preloaded_images.push(this);
        self.loadPhotos(current_photo + 1);
      };
      image.src = this.images[current_photo];
      $('#slideshow').append(image);
      $(image).addClass('hidden');
    },
    changePhoto: function() {
      var self = this;
      
      if (this.preloaded_images.length > this.current_photo) {
                
         if (this.current_photo == 0) {
          var previous_photo = this.photos_count - 1;
        }else{
          var previous_photo = this.current_photo - 1; 
        }
        
        var current_photo = this.current_photo;
        
        if (this.current_photo + 1 == this.photos_count) {
          var next_photo = 0;
        }else{
          var next_photo = this.current_photo + 1; 
        }
        this.current_photo = next_photo;


        $(this.preloaded_images[previous_photo]).fadeOut('slow');
        $(this.preloaded_images[current_photo]).fadeIn('slow', function() {
          setTimeout(function() {
            self.changePhoto();
          }, 5000);
        });

      }else{
        setTimeout(function() {
          self.changePhoto();
        }, 200);
      }
    }
  };

  function slideSwitch() {
    
    slideShow.initialize();
  
  }
  
  
$(document).ready(function() {

    $('#slideshow ul li:first').addClass('active');

    slideSwitch();
  
      $("a.history, span.breadcrumbs a, #previous_article a, #next_article a").livequery('click', function() {
              var hash = this.href;
              if($(this).attr('target') == "_blank") {
                return true;
              }
              hash = hash.replace(/^.*#/, '');
              hash = hash.replace(/http:\/\/[^\/]*/, '');
              // moves to a new page. 
              // pageload is called at once. 
              $.historyLoad(hash);
              return false;
      });
      
      /*$('a.photo-number:first').addClass("selected");
      
      $('#photo img').load(function() {
        $('#loader').hide();
        var photo = $('#photo img');
        $('#photo').css("width", photo.width());
        $('#photo').css("height", photo.height()+5);
        $('#photo img').fadeIn('slow');
      });

    
      $('a.photo-number').click(function(){
        var clicked = $(this);
        var photo = $('#photo img');
        var height = photo.height();
        var width = photo.width();
        
        $('#photo').css("width", width);
        $('#photo').css("height", height + 5);
        
        photo.fadeOut('slow');
        photo.queue(function() {
          photo.attr('src', clicked.attr("href"));
           $('#loader').show().css("left", width/2 - 78).css("top", height/2 - 16);
          $(this).dequeue();
        });
        
        $('a.photo-number').removeClass("selected");
        clicked.addClass("selected");
        return false;
      });      */  
                

      $.historyInit(pageload);
      
      scrollInitialize();
      
});
