﻿
    var isLoaded = false;     

    function openCloseWindow(page, isOpen, isShowThankYou)
    {
        var targetControl = 'windowContent';
        var iframe = 'ifHideDropDowns';
        var zero = '0px';
        var windowHeight = '450px'; 
        var stopHeight = '150px'; 
        var opac = 0.5; 
        var _duration = 500;
        
        
        $(iframe).style.visibility = isOpen ? 'visible' : 'hidden';
    
        if ( isOpen && isLoaded != true && page != '' )
            isLoaded = GetWindowContent( page, 'content' ); 
        
        if ( isOpen )
        {
            if( window.onresize == 'undefined' )
                window.onresize = function () { resizeBackground(); };
            resizeBackground();
            changeOpac( 0, 'dimOut');
            $('dimOut').style.visibility = 'visible';
            
            trackingOmniture(page);
        }

        var animation2 = new Animator( 
        {
            duration: _duration, 
            onComplete: function()
                        {
                            if (!isOpen && !isShowThankYou)
                                $('dimOut').style.visibility = 'hidden';
                        }
        });                            
        
        if (isShowThankYou)
        {
            animation2.addSubject( new NumericalStyleSubject($(targetControl), 'height', isOpen ? stopHeight : windowHeight, isOpen ? windowHeight : stopHeight ) );
            animation2.addSubject( new NumericalStyleSubject($(iframe), 'height', isOpen ? stopHeight : windowHeight, isOpen ? windowHeight : stopHeight ) );
            setTimeout(function() 
                          { 
                        
                         var animation3 = new Animator( 
                                            {
                                                duration: 200, 
                                                onComplete: function()
                                                            {
                                                                if (!isOpen)
                                                                    $('dimOut').style.visibility = 'hidden';
                                                            }
                                            });             
                            animation3.addSubject( new NumericalStyleSubject($(iframe), 'height', isOpen ? 0 : stopHeight, isOpen ? stopHeight : 0 ) );
                            animation3.addSubject( new NumericalStyleSubject($(targetControl), 'height', isOpen ? 0 : stopHeight, isOpen ? stopHeight : 0 ) );
                            animation3.addSubject( new NumericalStyleSubject($('dimOut'), 'opacity', isOpen ? zero : opac, isOpen ? opac : zero ) );
                            
                            animation3.play();                  
                          
                          }, 3000);
            
        }
        else
        {
            animation2.addSubject( new NumericalStyleSubject($(targetControl), 'height', isOpen ? 0 : windowHeight, isOpen ? windowHeight : 0 ) );
            animation2.addSubject( new NumericalStyleSubject($(iframe), 'height', isOpen ? 0 : windowHeight, isOpen ? windowHeight : 0 ) );            
            animation2.addSubject( new NumericalStyleSubject($('dimOut'), 'opacity', isOpen ? 0 : opac, isOpen ? opac : 0 ) );
        }

        animation2.play();             

    }

    function resizeBackground()
    {
        var width = 0;
        var height = 0;
        
        if( self.innerHeight )
        {
            width = self.innerWidth;
            height = self.innerHeight;
        }
        else if( document.documentElement && document.documentElement.clientHeight )
        {
            width = document.documentElement.clientWidth;
            height = document.documentElement.clientHeight;
        }
        else if( document.body )
        {
            width = document.body.clientWidth;
            height = document.body.clientHeight;
        }    
        
        var scrolls = getScrollXY();
        
        $('dimOut').style.width = width + scrolls[0] + 'px';
        $('dimOut').style.height = height + scrolls[1] + 'px';
    }
     
     
    function getScrollXY() 
    {
        var scrOfX = 0, scrOfY = 0;
        if( typeof( window.pageYOffset ) == 'number' ) 
        {   //Netscape compliant
            scrOfY = window.pageYOffset;
            scrOfX = window.pageXOffset;
        } 
        else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) 
        {   //DOM compliant
            scrOfY = document.body.scrollTop;
            scrOfX = document.body.scrollLeft;
        } 
        else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) 
        {   //IE6 standards compliant mode
            scrOfY = document.documentElement.scrollTop;
            scrOfX = document.documentElement.scrollLeft;
        }
        return [ scrOfX, scrOfY ];
    } 
        
    function GetWindowContent( page, controlToUpdate )
    {
        var request = new Ajax.Request(page,   
        {     
            method:'get',

            onSuccess: function(transport)
            {  
                var contentToInsert = GetRawXml( transport );
                $(controlToUpdate).update( contentToInsert );
            },     
            onFailure: function()
            { 
                $(controlToUpdate).innerHTML = ""; 
            },
            evalScripts: true 
        });
                            
    }

    
    function changeOpac(opacity, id)    //change the opacity for different browsers
    {
        var object = document.getElementById(id);
        if (object)
        {
            object.style.opacity = (opacity / 100);
            object.style.MozOpacity = (opacity / 100);
            object.style.KhtmlOpacity = (opacity / 100);
            object.style.filter = "alpha(opacity=" + opacity + ")";
            
            errorFlag = false;
        }
        else
        {
            errorFlag = true;
            return false;
        }
    } 
   
    