// JavaScript Document
//

/*****************************
 *correctPNG
 *****************************/
       function correctPNG() 
    	
       {
            for(var i=0; i<document.images.length; i++)
            {
                var img = document.images[i]
                var imgName = img.src.toUpperCase()
                
                if(imgName.indexOf("GOOGLE.COM") == -1) {
                    if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
                    {
                        var imgID = (img.id) ? "id='" + img.id + "' " : ""
                        var imgClass = (img.className) ? "class='" + img.className + "' " : ""
                        var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
                        var imgStyle = "display:inline-block;" + img.style.cssText 
                        if (img.align == "left") imgStyle = "float:left;" + imgStyle
                        if (img.align == "right") imgStyle = "float:right;" + imgStyle
                        if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle  
                        var strNewHTML = "<span " + imgID + imgClass + imgTitle
                        + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
                          + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                        + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
                        img.outerHTML = strNewHTML
                        i = i-1
                    }
                }    
            }
       }
       
       window.onload = init;
       window.onresize = init;
       
       
       
       //Scale background image:
/*****************************
 *init
 *****************************/
       function init() {
        
        var sBrowser = navigator.appName.toLowerCase();
        
        if(sBrowser.indexOf("microsoft") > -1) {
            correctPNG();
        }
        
        truc = setInterval(scrl, 10);
        
        SwitchImg();
        
       }
       
       
/*****************************
 *SwitchImg
 *****************************/
       function SwitchImg() {
         var iheight = GetHeight();
         var iwidth = GetWidth();
         var iratio = (iwidth/iheight);
         if(iheight < 550) {
            document.getElementById("divImg").style.display = "none";
         } else {
            document.getElementById("divImg").style.display = "block";
         }
         if(iratio > 1.8) {
            document.getElementById("background").setAttribute("src","/images/bg_top.jpg");
         } else {
            document.getElementById("background").setAttribute("src","/images/bg_top.jpg");
         }
         //alert(iratio);
       }
       
/*****************************
 *GetHeight
 *****************************/
       function GetHeight()
        {
        var y = 0;
        if (self.innerHeight)
        {
                y = self.innerHeight;
        }
        else if (document.documentElement && document.documentElement.clientHeight)
        {
                y = document.documentElement.clientHeight;
        }
        else if (document.body)
        {
                y = document.body.clientHeight;
        }
        return y;
        }
        
        
/*****************************
 *GetWidth
 *****************************/
        function GetWidth()
        {
        var x = 0;
        if (self.innerWidth)
        {
                x = self.innerWidth;
        }
        else if (document.documentElement && document.documentElement.clientWidth)
        {
                x = document.documentElement.clientWidth;
        }
        else if (document.body)
        {
                x = document.body.clientWidth;
        }
        return x;
        }
        
        
        window.onscroll = MoveLayout;

        var ScrollAmount = 0;
        var WasScrolling  = false;
        
/*****************************
 *MoveLayout
 *****************************/
        function MoveLayout() {
            ScrollAmount = GetScrollTop();
            WasScrolling = true;
        }
        
        function GetScrollTop(){
            var scrollTop = window.pageYOffset || document.documentElement.scrollTop || 0; 
            return scrollTop
        }
        
        var notScrolling = true;

/*****************************
 *scrl
 *****************************/
        function scrl() 
        {
            
            var newone = GetScrollTop();
            if(typeof(old)=='undefined') old = 0;
            
            notScrolling = (old == newone) ;
            old = notScrolling? old : newone ;
            
            if (WasScrolling && notScrolling)
            {
                var objDiv = document.getElementById("divImg");
                objDiv.style.top = ScrollAmount + "px";        
                
                WasScrolling = false;
                ScrollAmount = 0;
            }

        }
