function initPage(){
    
    loadbg();
    loadPageImage();
    //loadPage('')
}

function loadbg()
{
    var img = new Image();
    img.width  = $(window).width();
    img.height = $(document).height();
   
    $(img).load(function ()
    {  
        $(this).hide();
        $('#loader').removeClass('loading').append(this);
    
        $(this).fadeIn();
    }).error(function () {}).attr('src', 'photos/background.jpg');
}

function loadmenu(p)
{
    $('#nav').load('menu.php?p='+p);
}

function loadPage(name)
{
    $('#wrapper').load(name);
    loadmenu(name);
}

function loadPageImage()
{
    var img = new Image();
            
            $(img).load(function ()
            {  
                $(this).hide();
                $('#head-1').append(this); 
                $(this).fadeIn('slow');
                $(this).addClass('active');
                
                for(var imgind = 2 ; imgind < 4 ; imgind++)
                {
                    var img2 = new Image();
                    $(img2).attr('src','photos/main/first_class_spa_masaj_'+imgind+'.jpg');
                    $('#head-1').append(img2);
                }
                
                setInterval('swapImages()', 5000); 

            }).error(function () {}).attr('src', 'photos/main/first_class_spa_masaj_1.jpg');
}
function swapImages(){
      var $active = $('#head-1 .active');
      var $next = ($('#head-1 .active').next().length > 0) ? $('#head-1 .active').next() : $('#head-1 img:first');
      $active.fadeOut('slow',function(){
      $active.removeClass('active');
      $next.fadeIn('slow').addClass('active');
      });
}

