function gallery()
{

    system.addEventListener("onreadline", run);
    system.addEventListener("onresize", resize);
    system.addEventListener("onbeforeHelp", help);
    
    var place;
    var images = ["http://cs.usu.edu.ru/home/v/data/gallery/images/1.jpg","http://cs.usu.edu.ru/home/v/data/gallery/images/2.jpg","http://cs.usu.edu.ru/home/v/data/gallery/images/3.jpg","http://cs.usu.edu.ru/home/v/data/gallery/images/4.jpg","http://cs.usu.edu.ru/home/v/data/gallery/images/5.jpg","http://cs.usu.edu.ru/home/v/data/gallery/images/6.jpg","http://cs.usu.edu.ru/home/v/data/gallery/images/7.jpg","http://cs.usu.edu.ru/home/v/data/gallery/images/8.jpg","http://cs.usu.edu.ru/home/v/data/gallery/images/9.jpg","http://cs.usu.edu.ru/home/v/data/gallery/images/10.jpg","http://cs.usu.edu.ru/home/v/data/gallery/images/11.jpg","http://cs.usu.edu.ru/home/v/data/gallery/images/12.jpg",
"http://cs.usu.edu.ru/home/v/data/gallery/images/13.jpg","http://cs.usu.edu.ru/home/v/data/gallery/images/14.jpg","http://cs.usu.edu.ru/home/v/data/gallery/images/15.jpg","http://cs.usu.edu.ru/home/v/data/gallery/images/16.jpg","http://cs.usu.edu.ru/home/v/data/gallery/images/17.jpg"];
    var next, previos;
    var center, left, right, current;
    var canva, creeping, curtainLeft, curtainRight;
    var loaded = {};
    
    next = {};
    previous = {};
    next[ 0 ] = 1; next[ 1 ] = 2; next[ 2 ] = 3; next[ 3 ] = 4; next[ 4 ] = 5; 
    next[ 5 ] = 6; next[ 6 ] = 7; next[ 7 ] = 8; next[ 8 ] = 9; next[ 9 ] = 10;    
    next[ 10 ] = 11; next[ 11 ] = 12; next[ 12 ] = 13; next[ 13 ] = 14; next[ 14 ] = 15;
    next[ 15 ] = 16; next[ 16 ] = 0;
    previous[ 0 ] = 16; previous[ 1 ] = 0; previous[ 2 ] = 1; previous[ 3 ] = 2; previous[ 4 ] = 3; 
    previous[ 5 ] = 4;  previous[ 6 ] = 5; previous[ 7 ] = 6; previous[ 8 ] = 7; previous[ 9 ] = 8; 
    previous[ 10 ] = 9; previous[ 11 ] = 10; previous[ 12 ] = 11; previous[ 13 ] = 12; previous[ 14 ] = 13; 
    previous[ 15 ] = 14; previous[ 16 ] = 15;
    
    system.dispatchEvent("ontitle", "gallery");
    place = document.createElement("DIV");
    system.dispatchEvent("onshow", place);
    place.style.left = "10px";
    canva = document.createElement("DIV");
    creeping = document.createElement("DIV");
    curtainLeft = document.createElement("DIV");
    curtainRight = document.createElement("DIV");
    place.appendChild( canva );
    place.appendChild( creeping );
    place.appendChild( curtainLeft );
    place.appendChild( curtainRight );    
    try
    {
        place.style.height = parseInt( place.parentNode.currentStyle.height );
        place.style.width = parseInt( place.parentNode.currentStyle.width ) - 10; 
        canva.style.height = parseInt( place.currentStyle.height )/100 * 80;
        canva.style.width = parseInt( place.currentStyle.width ); 
        creeping.style.height = parseInt( place.currentStyle.height )/100 * 20;
        creeping.style.width = parseInt( place.currentStyle.width );  
        creeping.style.top = parseInt( place.currentStyle.height )/100 * 80;
        curtainLeft.style.height = parseInt( place.currentStyle.height )/100 * 20;
        curtainLeft.style.width = parseInt( place.currentStyle.width ) / 10;  
        curtainLeft.style.top = parseInt( place.currentStyle.height )/100 * 80;  
        curtainRight.style.height = parseInt( place.currentStyle.height )/100 * 20;
        curtainRight.style.width = parseInt( place.currentStyle.width ) / 10;  
        curtainRight.style.top = parseInt( place.currentStyle.height )/100 * 80;     
        curtainRight.style.left = parseInt( place.currentStyle.width )/100 * 90;             
    }
    catch( e )
    {
        place.style.height = parseInt(  window.getComputedStyle(place.parentNode, "").height ) - 10; 
        place.style.width = parseInt(  window.getComputedStyle(place.parentNode, "").width );
        canva.style.height = parseInt(  window.getComputedStyle(place, "").height ) / 100 * 80; 
        canva.style.width = parseInt(  window.getComputedStyle(place, "").width );        
        creeping.style.height = parseInt(  window.getComputedStyle(place, "").height ) / 100 * 20; 
        creeping.style.width = parseInt(  window.getComputedStyle(place, "").width );            
        creeping.style.top = parseInt(  window.getComputedStyle(place, "").height ) / 100 * 80;
        curtainLeft.style.height = parseInt(  window.getComputedStyle(place, "").height ) / 100 * 20; 
        curtainLeft.style.width = parseInt(  window.getComputedStyle(place, "").width ) / 10;            
        curtainLeft.style.top = parseInt(  window.getComputedStyle(place, "").height ) / 100 * 80;  
        curtainRight.style.height = parseInt( window.getComputedStyle(place, "").height )/100 * 20;
        curtainRight.style.width = parseInt( window.getComputedStyle(place, "").width ) / 10;  
        curtainRight.style.top = parseInt( window.getComputedStyle(place, "").height )/100 * 80;     
        curtainRight.style.left = parseInt( window.getComputedStyle(place, "").width )/100 * 90;          
    }
    paintCurrent( 0 );
    
    function resize()
    {
        var node;
    try
    {
        place.style.height = parseInt( place.parentNode.currentStyle.height );
        place.style.width = parseInt( place.parentNode.currentStyle.width ) - 10; 
        canva.style.height = parseInt( place.currentStyle.height )/100 * 80;
        canva.style.width = parseInt( place.currentStyle.width ); 
        creeping.style.height = parseInt( place.currentStyle.height )/100 * 20;
        creeping.style.width = parseInt( place.currentStyle.width );  
        creeping.style.top = parseInt( place.currentStyle.height )/100 * 80;
        curtainLeft.style.height = parseInt( place.currentStyle.height )/100 * 20;
        curtainLeft.style.width = parseInt( place.currentStyle.width ) / 10;  
        curtainLeft.style.top = parseInt( place.currentStyle.height )/100 * 80;  
        curtainRight.style.height = parseInt( place.currentStyle.height )/100 * 20;
        curtainRight.style.width = parseInt( place.currentStyle.width ) / 10;  
        curtainRight.style.top = parseInt( place.currentStyle.height )/100 * 80;     
        curtainRight.style.left = parseInt( place.currentStyle.width )/100 * 90;             
    }
    catch( e )
    {
        place.style.height = parseInt(  window.getComputedStyle(place.parentNode, "").height ) - 10; 
        place.style.width = parseInt(  window.getComputedStyle(place.parentNode, "").width );
        canva.style.height = parseInt(  window.getComputedStyle(place, "").height ) / 100 * 80; 
        canva.style.width = parseInt(  window.getComputedStyle(place, "").width );        
        creeping.style.height = parseInt(  window.getComputedStyle(place, "").height ) / 100 * 20; 
        creeping.style.width = parseInt(  window.getComputedStyle(place, "").width );            
        creeping.style.top = parseInt(  window.getComputedStyle(place, "").height ) / 100 * 80;
        curtainLeft.style.height = parseInt(  window.getComputedStyle(place, "").height ) / 100 * 20; 
        curtainLeft.style.width = parseInt(  window.getComputedStyle(place, "").width ) / 10;            
        curtainLeft.style.top = parseInt(  window.getComputedStyle(place, "").height ) / 100 * 80;  
        curtainRight.style.height = parseInt( window.getComputedStyle(place, "").height )/100 * 20;
        curtainRight.style.width = parseInt( window.getComputedStyle(place, "").width ) / 10;  
        curtainRight.style.top = parseInt( window.getComputedStyle(place, "").height )/100 * 80;     
        curtainRight.style.left = parseInt( window.getComputedStyle(place, "").width )/100 * 90;          
    }
        if ( (canva.firstChild)&&(canva.firstChild.tagName == "IMG") )
        {
            try
            {
                node = canva.firstChild;
                node.style.height = parseInt( canva.currentStyle.height ) / 80 * 74;
                node.style.width = parseInt( canva.currentStyle.width ) / 100 * 80; 
                node.style.top = parseInt( canva.currentStyle.height ) / 80 * 3;
                node.style.left = parseInt( canva.currentStyle.width ) / 100 * 10;
            }
            catch( e )
            {
                node.style.height = parseInt(  window.getComputedStyle(canva, "").height ) / 80 * 74; 
                node.style.width = parseInt(  window.getComputedStyle(canva, "").width ) / 80 * 60;
                node.style.top = parseInt( window.getComputedStyle(canva, "").height ) / 80 * 3;
                node.style.left = parseInt( window.getComputedStyle(canva, "").width ) / 100 * 10;   
            }                  
        }
    }
    
    function paintCurrent( index )
    {
        var img;
        if ( (canva.firstChild)&&(canva.firstChild.tagName == "IMG")&&( loaded[ index ] ) )
        {
            canva.firstChild.src = images[ index ];
        }
        else
        {
            img = new window.Image();
            img.onload = handler;
  //          img.addEventListener("onload", function () { alert("debag"); }, true );
            img.onerror =   function ()
                            {
                                var message = document.createTextNode("К несчастью, не удалось загрузить изображение. Возможно, это связанно с тм, чтов настройках браузера оключенне отображение рисунков.");
                                if ( canva.firstChild ) canva.removeChild( canva.firstChild );
                                canva.appendChild( message );
                            }
            img.src = images[ index ];
            if ( img.readyState == undefined )
            {
                handler();
            }
        }
        var left, right;
        if ( !loaded[ previous[index] ] )
        {
            left = new Image();
            left.src = images[ previous[index] ];
            left.onload = function(){ loaded[ previous[index] ] = true };
        }
        if ( !loaded[ next[index] ] )
        {
            right = new Image();
            right.src = images[ next[index] ];
            right.onload = function(){ loaded[ next[index] ] = true };
        }
        current = index;    
                
            function handler()
            {
                var node = document.createElement("IMG");
                node.src = img.src;
                if ( canva.firstChild ) canva.removeChild( canva.firstChild );
                canva.appendChild( node );
                loaded[ index ] = true;
                try
                {
                    node.style.height = parseInt( canva.currentStyle.height ) / 80 * 74;
                    node.style.width = parseInt( canva.currentStyle.width ) / 100 * 80; 
                    node.style.top = parseInt( canva.currentStyle.height ) / 80 * 3;
                    node.style.left = parseInt( canva.currentStyle.width ) / 100 * 10;
                }
                catch( e )
                {
                    node.style.height = parseInt(  window.getComputedStyle(canva, "").height ) / 80 * 74; 
                    node.style.width = parseInt(  window.getComputedStyle(canva, "").width ) / 80 * 60;
                    node.style.top = parseInt( window.getComputedStyle(canva, "").height ) / 80 * 3;
                    node.style.left = parseInt( window.getComputedStyle(canva, "").width ) / 100 * 10;   
                }                                
            }        
    }
    
   
    function help()
    {
        system.dispatchEvent("onwrite", "\nкоманды доступные в этом разделе:\n  next - следующие изображение.\n  previous   - преведещие изображение.\n");
    }   

    
    function run( input )
    {
        if ( input == "next" )
        {
            paintCurrent( next[ current ] );
        }
        if ( input == "previous" )
        {
            paintCurrent( previous[ current ] );
        }        
        if ( input != "exit" )
        {
            system.dispatchEvent("ontitle", "gallery");
        }
    }
}
