// JScript source code

var Container;                          // object of Div whith main content
var Arrow                               // object of span with arrow
var Link                                // object of tag <A> (link)

var winScroll = 1;                      // If you don't need to scroll window Set variable with "0" either Set "1"

var Word_Maximize = "Maximize";         // You may use HTML tags
var Word_Minimize = "Minimize";         // You may use HTML tags
var Down_Arrow = "&darr;";              // You may use HTML tags
var Up_Arrow = "&uarr;";                // You may use HTML tags
var MarginTop = -35;                    // ... (-35) - this is distane from top of tab
var Height = 110;                       // Container's Height in Minimized condition 
var ContaienersFullHeight;              // Container's Height in Maximized condition 
var Step = 15;                          // develop steps ( in pixels )
var steps;                              // cantity of steps
var Wsteps = 40;                        // cantity of steps for Window scroll
var step_counter = 0;                   // counter for Container enlarge steps
var counter = 0;                        // counter for Window Scroll steps
var Delay = 20;                         // develop step delay
var currentY = 0;                       //
var Distance;                           //
var timer = null;                       //
var Wtimer = null;                      //

    function getContainersHeight()
    {
        Container = document.getElementById("ViewPagePhotosContent");
        
        if (winScroll)
        {
                // What is tab's margin from Top ?
                elem = document.getElementById("ViewPagePhotos");
                while (elem)
    	        {
        	        MarginTop += elem.offsetTop;
        	        elem = elem.offsetParent;
    	        }
    	}
    	
        //alert(MarginTop);
        if(Container){
	        ContaienersFullHeight = Container.offsetHeight-20;
	        Container.style.height = Height+'px';
	        
	        Arrow = document.getElementById("arrow");
	        Link = document.getElementById("linkArrow");
        	
        }

    }
    
    function develop()
    {
        steps = Math.ceil( (ContaienersFullHeight - Height) / Step );
        
        if (Container.style.height == Height+'px')
        {
            
            if (winScroll)
            {
                    // Let's calculate if we need to Scroll the window
                    Distance = (window.scrollY) ? MarginTop-window.scrollY : MarginTop-document.body.scrollTop;
                    //alert(Distance);
                    if ( Distance>60 )
                    {
                        Wsteps_ = Math.ceil( Distance/MarginTop*Wsteps );
                        px = Math.round( Distance/Wsteps_ )-1;  //alert("Distance = "+Distance+", px = "+px+" Wsteps_ = "+Wsteps_);
                        currentY = (window.scrollY) ? window.scrollY : document.body.scrollTop;
                        windowScroll(px,0);
                    }
                    else{
                            stopTimer();
                            maximize(Step, Delay);
                        }
             
             }
             else
                 {
                      stopTimer();
                      maximize(Step, Delay); 
                 }
                 
                 
        }
        else
            {
                stopTimer();
                minimize(Step, Delay);
            }
        
        return false;
    }
    
   
    function windowScroll(x,delay)
    {
        currentY += x;
        window.scroll(0,currentY);
        counter++;
        
        if (counter == Wsteps_)
        { 
            if(Wtimer) clearTimeout(Wtimer); Wtimer = null; counter = 0;

            stopTimer();
            maximize(Step, Delay);

        }
        else{
                Wtimer = setTimeout("windowScroll(px,"+delay+")", delay);
            }
        
    }
    
    function maximize(x, delay)
    {
        var y = Container.style.height;
        y = parseInt( y.replace(/px/, "") );
        Container.style.height = (y + x)+'px';
        step_counter++;
        
        if (step_counter == steps)
        {
            stopTimer();
            changeArrow();
        }
        else{
                timer = setTimeout("maximize("+x+", "+delay+")", delay);
            }
    }
    
    function minimize(x, delay)
    {
        var y = Container.style.height;
        y = parseInt( y.replace(/px/, "") );
        Container.style.height = (y - x)+'px';
        step_counter++;
        
        if (step_counter == steps)
        {
            stopTimer();
            changeArrow();
        }
        else{
                timer = setTimeout("minimize("+x+", "+delay+")", delay);
            }
    }
    
    function stopTimer() 
    { 
        if(timer) clearTimeout(timer); timer = null; step_counter = 0;
    }    
    
    function changeArrow() 
    { 
        if (Container.style.height != Height+'px')
        {
            Link.innerHTML =  Word_Minimize;
            Arrow.innerHTML =  Up_Arrow;
        }
        else{
                Link.innerHTML =  Word_Maximize;
                Arrow.innerHTML = Down_Arrow; 
            }
    }
    
