System={
    Rout:function(url){
        if(System.RequestStart==1) return;
        System.RequestStart=1;
        this.ContentUrl=url;
        this.StartSlideOutContent();
    },
    Initialize:function(){
        $('body a').not('#lang a').not('#social a').click(function(){
            if($(this).attr('href') && $(this).attr('target')!='_blank'){
		System.Rout($(this).attr('href'));
	        return false;
	    }

        });        
        System.SlideLength=$('#content').outerWidth()+500;
        System.SlideTime=System.SlideLength/2;
        System.SlideTimeout=System.SlideLength/10;
        System.ShowPage();
    },
    InitializeContent:function(){
        $('#content a').click(function(){
            if($(this).attr('href') && $(this).attr('target')!='_blank')System.Rout($(this).attr('href'));
            return false;
        });
    },
    ContentUrl:'',
    SlideTime:0,
    SlideLength:0,
    SlideTimeout:0,
    RequestStart:0,
    StartSlideOutContent:function(){
        $('#content').height($('#content').outerHeight());
        $('#content>div:first-child').addClass('sliding');
        System.LoaderOff();
        System.SlideOutContent();
    },
    SlideOutContent:function(){
        d=$('#content>.sliding');
        d.removeClass('sliding');
        d.find(':animated').stop(true, true);
        d.css({'position':'relative'});
        d.animate({'left':System.SlideLength},System.SlideTime);
        f = d.next();
        f.addClass('sliding');
        if(f.length > 0) setTimeout("System.SlideOutContent();",System.SlideTimeout);
        else setTimeout("System.EndSlideOutContent();",System.SlideTime);
    },
    EndSlideOutContent:function(){
        $('#content').empty();
        System.LoaderOn();
        $.ajax({
            url: System.ContentUrl+'&ajax=on', 
            success: function(data, textStatus){
                System.RequestStart=0;
                $('#buffer').html(data);
                System.LoaderOff();
                System.StartSlideInContent();
            },
            error: function(){                
                alert('произошла ошибка при запросе.');
                System.RequestStart=0;
                System.LoaderOff();
            }
        });
        /*re = $('#buffer').load(System.ContentUrl+'&ajax=on',function(){            
            System.LoaderOff();
            System.StartSlideInContent();
        });*/
        //alert(re.get(0)); 
    },
    StartSlideInContent:function(){
        lightning = $('#content').outerHeight() - $('#buffer').outerHeight();
        if(lightning < 0)lightning = lightning * -1;
        $('#buffer>div').css({'position':'relative','left':-System.SlideLength+'px','display':'block'});
        $('#buffer>div:first-child').addClass('sliding');
        $('#content').append($('#buffer>div').clone(true));
        $('#content').animate({'height':$('#buffer').outerHeight()},lightning*3,System.SlideInContent);
    },
    SlideInContent:function(){
        d=$('#content>.sliding');
        d.removeClass('sliding');        
        d.animate({'left':0},System.SlideTime,function(){$(this).css({'position':'static'});});
        f = d.next('.body');
        f.addClass('sliding');
        if(f.length > 0) setTimeout("System.SlideInContent();",System.SlideTimeout);
        else setTimeout("System.EndSlideInContent();",System.SlideTime);
    },
    EndSlideInContent:function(){
        d=$('#buffer').empty();
        System.InitializeContent();
        System.OnReady();
    },
    ShowPage:function(){
        $('body .body').css({'left':-System.SlideLength+'px','display':'block'});
        $('body>.body:first-child').addClass('sliding');
        System.LoaderOff();
        System.SlideInBody();
    },
    SlideInBody:function(){
        d=$('body .sliding');
        d.removeClass('sliding');
        d.animate({'left':0},System.SlideTime,function(){$(this).css({'position':'static'});});        
        f = d.next('.body');
        if(f.length == 0){
            c = d.next('#content');            
            if(c.length == 1){
                f = c.children('.body');
            }
            else{
                c=d.closest('#content');
                if(c.length > 0) f = c.next();
            }
        }
        f.addClass('sliding');
        if(f.length > 0) setTimeout("System.SlideInBody();",System.SlideTimeout);
        else System.OnReady();
    },
    LoaderOn:function(){
        $('#content').append('<div class="loader"></div>');
        $('#content .loader').fadeIn(100);
    },
    LoaderOff:function(){
        $('#content .loader').fadeOut(100,function(){$(this).remove();});
    },
    Ready:function(func){
        System.ReadyStack.push(func);
    },
    OnReady:function(){
        for(var i in   System.ReadyStack) {
            if( System.ReadyStack[i]) System.ReadyStack[i]();
        }
        System.ReadyStack = [];
    },
    ReadyStack:[]
}
