
var _skipAnimation = false;
var _menuShown = false;
var _animationActivated = false;
var _currentAddress = '';
var _currentLang = '';

function _welcomePageShowAnimation() {
   
   if (_skipAnimation || _animationActivated)
      return;
   _animationActivated  = true;
   //$('#footer p').html('anim');
   $(".welcomeDiv2").animate({
      opacity: 0.95
      }, 4000, function() {
      //na koniec animacji pokazujemy menu jezykow
      _welcomePageShowLangs();
  });
}

function _welcomePageSkipAnimation() {
   if (_menuShown)
      return;
      
   _skipAnimation = true;
   $(".welcomeDiv1").empty();
   $(".welcomeDiv2").css('opacity', 0.95);
   _welcomePageShowLangs();
}

function _welcomePageShowLangs() {
   if (_menuShown)
      return;
   _menuShown = true;
   $("#pominAnimacje").hide();
   $("#menuJezykow").fadeIn(800);
}

function _welcomePageShowMenu(id, skrot) {
   _currentLang = skrot;
   $("#menuJezykow").hide();
   $.ajax({
      type: "POST",
      url: "/zmienJezyk/"+skrot,
      success: function(msg){
         //alert(msg);
         $("#menu_"+id).fadeIn(800);
         $("#psm").fadeIn(800);
      }
    });
   
}

function _reloadSection(adres, link) {
   if (_currentAddress==adres)
      return;
   else
      _currentAddress = adres;
      
   var _hasContent = true;
   var _bodyClass;
    
   if (!_menuShown) {
      $("#pominAnimacje").hide();
      $("#menuJezykow").hide();
      $("#menu_"+_langId).show();
      _menuShown = true;
      _hasContent = false;
   }
   $('#bottom a').addClass('inactive');
   $(link).removeClass('inactive');
   
   switch ($(link).attr('id')) {
      case 'sectionLink_1':
         _bodyClass =  'blue';
         window.location.hash = 'store';
         break;
      case 'sectionLink_11':
         _bodyClass =  'white';
         window.location.hash = 'restaurant';
         break;
      case 'sectionLink_12':
         _bodyClass =  'blue';
         window.location.hash = 'kids';
         break;
      case 'sectionLink_13':
         _bodyClass =  'white';
         window.location.hash = 'eshop';
         break;
      case 'sectionLink_14':
         _bodyClass =  'white';
         window.location.hash = 'friends';
         break;
   }
   
   //fade tego co już jest w main
   if (_hasContent) {
      $('#main').fadeOut(800, function() {
         $('#main').empty();
         $('#main').show();
         _setBodyClass(_bodyClass);
         $('#main').addClass('loading');
         _reloadSectionAjax(adres);
      });
   }
   else {
      $('#main').empty();
      _setBodyClass(_bodyClass);
      $('#main').addClass('loading');
      _reloadSectionAjax(adres);
   }
}

function _setBodyClass(_bodyClass) {
   if (_bodyClass=='blue') {
      $('body').removeClass('white');
      $('body').addClass('blue');
   }
   else {
      $('body').removeClass('blue');
      $('body').addClass('white');
   }
}

function _reloadSectionAjax(adres) {
   
   $.ajax({
      type: "GET",
      url: adres,
      cache: true,
      success: function(msg){
         $('#main').removeClass('loading');
         
         $("#main").html(msg);
         //$('#main div').hide();
         
      }
   });
}

function _reloadSectionComplete() {
   $('#main div:not(.noDisplay)').fadeIn(1000);
   _aktPokazywane = 0;
   _afterSectionLoad();
   //jeśli e-shop to od razy wrzucamy podstronę
   if (window.location.hash=='#eshop')
      _showPage(24,null);
}

$(document).ready(function() {
   if (window.location.hash!="") {
      _currentLang = _lang;
      switch (window.location.hash) {
         case '#store':
            $('#main').empty();
            _reloadSection('/p-1/store',document.getElementById('sectionLink_1'));
            return;
         case '#restaurant':
            $('#main').empty();
            _reloadSection('/p-11/store',document.getElementById('sectionLink_11'));
            return;
         case '#kids':
            $('#main').empty();
            _reloadSection('/p-12/store',document.getElementById('sectionLink_12'));
            return;
         case '#eshop':
            $('#main').empty();
            _reloadSection('/p-13/store',document.getElementById('sectionLink_13'));
            return;
         case '#friends':
            $('#main').empty();
            _reloadSection('/p-14/store',document.getElementById('sectionLink_14'));
            return;
      }
   }

   $(".welcomeDiv2").css('opacity', 0);
   $(".welcomeDiv2").css('top', -600);
   
   //to się później wytnie
   //_welcomePageShowAnimation();
   //$('#footer p').html('start');
   //setTimeout("_welcomePageShowAnimation",10000);
});

