var __h=0;
var browserHeight;
var container;
var timerID2=0;
var __hold=0;
var smoothLayer=0;
var yTarget=0;
var thisY=0;
var changeHeightAfterScroll=0;
var temp__h=0;
var __timeout=0;
var isScrolling=0;
var yposold=0;
var timerID = 0;
var framerate=25;
function scrollTopNoAnimation()
{
	scrollTo(0,0);
}
function setScrollHeightValue(h)
{
    if(isScrolling==0)
    {
    	scrollTo(0,0);
        __h=h;
        setScrollHeight();
    }
}

function getContainer()
{
    container = document.getElementById("flashPage");
}

function setIEexpression(h)
{
    if(is_pc_ie)
    {
        container.style.removeExpression("height");
        if (document.documentElement.clientHeight==0)
        {
            browserHeight=document.body.clientHeight;
            container.style.setExpression("height","document.body.clientHeight < "+(h+10)+" ? \""+h+"px\": \"100%\"");
        }
        else
        {
            browserHeight=document.documentElement.clientHeight;
            container.style.setExpression("height","document.documentElement.clientHeight < "+(h+10)+" ? \""+h+"px\": \"100%\"");
        }
    }
}

function nonIEFakeExpression(h)
{
    if(!is_safariShit)
    {
        container.style.minHeight = h+"px";
        container.style.height = "100%";
        container.firstChild.style.height = "100%";
    }
    else
    {
        container.style.minHeight = h+"px";
        container.firstChild.style.minHeight = h+"px";
        container.firstChild.style.height = "100%";
    }
}

function resizeSmooth(h)
{
    __h=h;
    getContainer();
    if(is_pc_ie)setIEexpression(__h);
    hSmooth();
}

function fixDiv()
{
    getContainer();
    if(is_pc_ie)
    {
    	
        container.style.height=__h+"px";
        container.firstChild.style.height =__h+"px";
        if (container.firstChild!=null) container.firstChild.style.height = "100%";
    }
    else
    {
        nonIEFakeExpression(__h);
    }
}

function restoreHeight()
{
    __h=550;
    getContainer();
    if(is_pc_ie)
    {
        setIEexpression(__h);
        if (container.firstChild!=null) container.firstChild.style.height = "100%";
    }
    else
    {
        nonIEFakeExpression(__h);
    }
}

function setScrollHeight2(h)
{
    getContainer();
    if(is_pc_ie)
    {
        setIEexpression(h);
    }
    else
    {
        nonIEFakeExpression(h);
    }
    __h=h;
}

function hSmooth()
{
    var myH;
    var t;
    getContainer();
    if(is_pc_ie)
    {
        if((o = document.defaultView) && o.getComputedStyle)
        {
            myH = o.getComputedStyle(container, null).height;
        }
        else if('number' == typeof container.offsetHeight)
        {
            myH = container.offsetHeight;
        }
        t = new Tween(container.firstChild.style,'height',Tween.regularEaseOut,myH,__h,0.6,'px');
        t.onMotionFinished = function(){flashMovie.setScrollHeight();};
        t.start();
    }
    else
    {
        setScrollHeight();
    }
}

function setScrollHeight()
{
    getContainer();
    if(is_pc_ie)
    {
        setIEexpression(__h);
        if (container.firstChild!=null) container.firstChild.style.height = "100%";
    }
    else
    {
        nonIEFakeExpression(__h);
    }
    //flashMovie.setScrollHeight();
}

function scrollit(numPos,newH)
{
    changeHeightAfterScroll=0;
    isScrolling=1;
    __timeout=0;
    //alert('scroll it');
    yTarget=numPos;
    if(newH!=null)
    {
        changeHeightAfterScroll=1;
        temp__h=newH;
    }
    var maxHS=(__h-f_clientHeight());
    if (f_scrollTop()<yTarget)
    {
        if(yTarget>maxHS)
        {
            yTarget=maxHS;
        }
        __timeout=1;
        downTo();
    }
    else
    {
        __timeout=1;
        upTo();
    }
}

function upTo()
{
    var ypos=f_scrollTop();
    ypos = Math.round(ypos + (yTarget-ypos) / 5.0);
    if (yposold!=ypos)
    {
        yposold = ypos;
        scrollTo(0,ypos);
        timerID = setTimeout ('upTo()',framerate)
    }
    else
    {
        timerID =0;
        __timeout=0;
        isScrolling=0;
        if(changeHeightAfterScroll==1)
        {
            if(__h>temp__h)
            {
                setScrollHeightValue(temp__h);
            }
        }
    }
}

function downTo()
{
    var ypos=f_scrollTop();
    ypos = Math.round(ypos + (yTarget-ypos) / 5.0);
    if (yposold!=ypos)
    {
        yposold = ypos;
        scrollTo(0,ypos);
        timerID = setTimeout ('downTo()',framerate)
    }
    else
    {
        timerID =0;
        __timeout=0;
        isScrolling=0;
        if(changeHeightAfterScroll==1)
        {
            setScrollHeightValue(temp__h);
        }
    }
}

function f_scrollTop()
{
    return f_filterResults (
    window.pageYOffset ? window.pageYOffset : 0,
    document.documentElement ? document.documentElement.scrollTop : 0,
    document.body ? document.body.scrollTop : 0
    );
}

function f_clientHeight()
{
    return f_filterResults (
    window.innerHeight ? window.innerHeight : 0,
    document.documentElement ? document.documentElement.clientHeight : 0,
    document.body ? document.body.clientHeight : 0
    );
}

function f_filterResults(n_win, n_docel, n_body)
{
    var n_result = n_win ? n_win : 0;
    if (n_docel && (!n_result || (n_result > n_docel)))
    n_result = n_docel;
    return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
} 
