        var CONST_CYCLE_TIME_PARTNER = 10000 // default refresh images time interval for Partner
        var CONST_CYCLE_TIME_PLATINUM = 20000 // default refresh images time interval for Platinum

        var CONST_LEVEL_PREMIUM = 1
        var CONST_LEVEL_PARTNER = 2
        var CONST_LEVEL_PLATINUM = 3

        var __TimoutID = 0;
        
        // set the ads to hidden so that cached photos don't diplay too soon.
        document.write("<style type='text/css'>#thephoto1_2 {visibility:hidden;} </style>");        
        document.write("<style type='text/css'>#thephoto2_3 {visibility:hidden;} </style>");        
        document.write("<style type='text/css'>#thephoto3_3 {visibility:hidden;} </style>");        
    
        window.onload = function() {start()}

        function start()
        {
            var sPartnerCycle = document.getElementById("hidPartnerCycleTime").value;
            if(!isNaN(sPartnerCycle) && sPartnerCycle != "0")
            {
                CONST_CYCLE_TIME_PARTNER = parseInt(sPartnerCycle)*1000;
            }

            var sPlatinumCycle = document.getElementById("hidPlatinumCycleTime").value
            if(!isNaN(sPlatinumCycle) && sPlatinumCycle != "0")
            {
                CONST_CYCLE_TIME_PLATINUM = parseInt(sPlatinumCycle)*1000;
            }
            
            initImage('thephoto1_'+ CONST_LEVEL_PARTNER);
            initImage('thephoto2_'+ CONST_LEVEL_PLATINUM);
            initImage('thephoto3_'+ CONST_LEVEL_PLATINUM);

            setTimeout("fnCycleAds("+CONST_LEVEL_PARTNER+")", CONST_CYCLE_TIME_PARTNER);
            setTimeout("fnCycleAds("+CONST_LEVEL_PLATINUM+")", CONST_CYCLE_TIME_PLATINUM);
        }

        
        /////////////////////////////////////
        /// IMAGE FADING FUNCTIONS
        ////////////////////////////////////
        function initImage(imageId) {
          var image = document.getElementById(imageId);
          if(image)
          {
              setOpacity(image, 0);
              image.style.visibility = 'visible';
              
              fadeIn(imageId,0);
          }
        }    

        function setOpacity(obj, opacity) {
          opacity = (opacity == 100)?99.999:opacity;
          
          // IE/Win
          obj.style.filter = "alpha(opacity:"+opacity+")";
          
          // Safari<1.2, Konqueror
          obj.style.KHTMLOpacity = opacity/100;
          
          // Older Mozilla and Firefox
          obj.style.MozOpacity = opacity/100;
          
          // Safari 1.2, newer Firefox and Mozilla, CSS3
          obj.style.opacity = opacity/100;
        }
    
        function fadeIn(objId,opacity) {
          if (document.getElementById) {
            obj = document.getElementById(objId);
            if (opacity <= 100) {
              setOpacity(obj, opacity);
              opacity += 10;
              window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 100);
            }
          }
        }


        /////////////////////////////////////
        /// AD SWAPPING FUNCTIONS
        ////////////////////////////////////                
        function fnCycleAds(iLevel)
        {
            var xmlhttp = new XMLHttpRequest();
            xmlhttp.onreadystatechange = function()
            {
	            if(xmlhttp.readyState == 4)
	            {
                    var xmlDoc = xmlhttp.responseXML
                    var serializer = new XMLSerializer();

                    fnIterateXml(xmlDoc, iLevel);
                }
            };
            
            //var lLevel = document.getElementById("hidLevel").value; // we'll get rid of this and user the level passed in.
            
            xmlhttp.open("GET", "AdRotator.aspx?level="+(iLevel - 1)+"&action=rotate", true);
            xmlhttp.send(null);
        }
        
        function fnIterateXml(xmlDoc, iLevel)
        {
            if(xmlDoc.firstChild)
            {
                fnHideAll(iLevel);
                
                var adList = xmlDoc.firstChild.childNodes;
                var iImageCnt = (iLevel == CONST_LEVEL_PLATINUM)? 2 : 1;

                for(var i = 0; i < adList.length; i++)
                {
                    var AdNode = adList[i];
                    if(AdNode.nodeType == 1)
                    {
                        var sSrc = Sarissa.getText(fnSelectSingleNode(AdNode, "Logo"), false);
                        var sNavUrl = Sarissa.getText(fnSelectSingleNode(AdNode, "Website"), false);
                        var sAltText = Sarissa.getText(fnSelectSingleNode(AdNode, "Name"), false);
                        
                        fnReplaceAd(iImageCnt, sSrc, sNavUrl, sAltText, iLevel);
                        iImageCnt++;
                    }
                }
                
                __TimoutID = setTimeout("fnCycleAds("+iLevel+")", (iLevel == CONST_LEVEL_PLATINUM)? CONST_CYCLE_TIME_PLATINUM : CONST_CYCLE_TIME_PARTNER);
            }
        }
        
        function fnReplaceAd(iIndex, sSrc, sNavUrl, sAltText, iLevel)
        {
            var imageId = 'thephoto'+iIndex+"_"+iLevel;
            var image = document.getElementById(imageId);
            var link = document.getElementById('lnk'+iIndex+"_"+iLevel);
            
            image.src = "/Attachment/ViewSecureAttachment.aspx?fid=" + sSrc;
            image.alt = sAltText;
            image.title = sAltText;
            
            link.href = sNavUrl;
            
            document.getElementById(imageId).style.display = "block";
            initImage(imageId);
        }

        function fnHideAll(iLevel) {
            if (iLevel == CONST_LEVEL_PARTNER) {
                document.getElementById('thephoto1_' + CONST_LEVEL_PARTNER).style.display = "none";
            } else {
                document.getElementById('thephoto2_' + CONST_LEVEL_PLATINUM).style.display = "none";
                document.getElementById('thephoto3_' + CONST_LEVEL_PLATINUM).style.display = "none";
            }
        }
        
        function fnSelectSingleNode(node, nodeName)
        {
            var returnNode;
            for(var i = 0;i < node.childNodes.length;i++)
            {
                var childNode = node.childNodes[i];
                if(childNode.nodeName == nodeName)
                {
                    returnNode = childNode;
                    break;
                }
            }    
            
            return returnNode;    
        }
        
    function getElementTextNS(prefix, local, parentElem, index) {
        var result = "";
        if (prefix && isIE) {
            // IE/Windows way of handling namespaces
            result = parentElem.getElementsByTagName(prefix + ":" + local)[index];
        } else {
            // the namespace versions of this method 
            // (getElementsByTagNameNS()) operate
            // differently in Safari and Mozilla, but both
            // return value with just local name, provided 
            // there aren't conflicts with non-namespace element
            // names
            result = parentElem.getElementsByTagName(local)[index];
        }
        if (result) {
            // get text, accounting for possible
            // whitespace (carriage return) text nodes 
            if (result.childNodes.length > 1) {
                return result.childNodes[1].nodeValue;
            } else {
                return result.firstChild.nodeValue;    		
            }
        } else {
            return "n/a";
        }
    }        