var __h=585;
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;
var isGallery=0;
var isFirstTime=1;
var isSafariFirstTime=1;
var ie7=false;
var ie8=false;


function openWindow(URL) {
var day = new Date();
var id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "');");
}

function IsIE8Browser() {

    var rv = -1;

    var ua = navigator.userAgent;

    var re = new RegExp("Trident\/([0-9]{1,}[\.0-9]{0,})");

    if (re.exec(ua) != null) {

        rv = parseFloat(RegExp.$1);

    }

    return (rv == 4);

} 
function setScrollHeightValue(h)
{
    if(isScrolling==0)
    {
        __h=h;
       //alert("change Height 1");
        setScrollHeight();
    }
}

function getContainer()
{
	if(IsIE8Browser())
	{
		 ie7=false;
		 ie8=true;

	}
    container = document.getElementById("fullPage");
}

function setIEexpression(h)
{
	if (typeof document.body.style.maxHeight != "undefined") 
	{

	  ie7=true;
	}

	

    if(is_pc_ie && ie8==false)
    {
    	getContainer();
    
        container.style.removeExpression("height");
        if (document.documentElement.clientHeight==0)
        {
        	
            browserHeight=document.body.clientHeight;
            if(ie7){
	            container.style.minHeight = h+"px";
	        	container.style.height = "100%";
	        	container.firstChild.style.height = "100%";
	        	
	        	
        	}else{
        	
            	container.style.setExpression("height","document.body.clientHeight < "+(h+10)+" ? \""+h+"px\": \"100%\"");
            }
           if(isGallery==0) {
 
          	 container.style.height = "100%";
           }
        }
        else
        {

            browserHeight=document.documentElement.clientHeight;
           
            if(ie7){
            container.style.minHeight = h+"px";
        	container.style.height = "100%";
        	container.firstChild.style.height = "100%";
        	}else{
            container.style.setExpression("height","document.documentElement.clientHeight < "+(h+10)+" ? \""+h+"px\": \"100%\"");
            }
           if(isGallery==0){
           	
           container.style.height = "100%";
           }

        }
        
      
    }
}

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

function resizeSmooth(h,scValue)
{
    __h=h;
    getContainer();
    if(is_pc_ie && ie8==false)setIEexpression(__h);
    hSmooth(scValue);
}

function fixDiv()
{

    getContainer();
    if(is_pc_ie && ie8==false)
    {
        container.style.height=__h+"px";
        container.firstChild.style.height =__h+"px";
        if(isGallery==1) {
        	
        	isGallery=0;
        	container.firstChild.style.height="100%";
        }
        
    }
    else
    {
        nonIEFakeExpression(__h);
    }
    
  // if(!is_pc_ie) flashMovie.setScrollHeight();
}

function restoreHeight()
{
    __h=585;
    getContainer();
    if(is_pc_ie && ie8==false)
    {
        setIEexpression(__h);
        container.firstChild.style.height = "100%";
    }
    else
    {
        nonIEFakeExpression(__h);
    }
}

function setScrollHeight_bis(h)
{
	
    getContainer();
     __h=h;
     
    if(is_pc_ie && ie8==false)
    {
        setIEexpression(h);
    }
    else
    {
   		
        nonIEFakeExpression(h);
    }
   
 	 container.firstChild.style.height = "100%";
   	//flashMovie.setScrollHeight();

}

function hSmooth(scValue)
{
    var myH;
    var t;
    var t2;

    getContainer();
    
    if(is_pc_ie && ie8==false)
    {
        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
    {

        myH = container.offsetHeight;
        t = new Tween(container.firstChild.style,'height',Tween.regularEaseOut,myH,__h,0.4,'px');
        
        t.onMotionFinished = function(){
    
        	scrollit(scValue,__h,0);
        };
        t.start();
       // setScrollHeight();
   }
}

function setScrollHeight()
{
	
    getContainer();
    if(is_pc_ie && ie8==false)
    {
    	container.firstChild.style.height = "100%";
        setIEexpression(__h);
    }
    else
    {
    //	alert('here-->safari');
        nonIEFakeExpression(__h);
    }
    if(isFirstTime==1){
    	isFirstTime=0;
    	fixDiv();
    }
    if(is_pc_ie && ie7)
    {
		if(isGallery==1)  flashMovie.setScrollHeight(); 
    }else{
    	flashMovie.setScrollHeight();
    }
     
   	
}

function scrollit(numPos,newH,isg)
{

    changeHeightAfterScroll=0;
    isScrolling=1;
    if(isg==1){
    	isGallery=1;
    }else{
    	isGallery=0;
    }
    __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) / 8.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) / 8.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;
} 
