﻿    function setBackgrounds()
    {
    // Check if the connection is using Https or not

        var imageServer = "/images/image.aspx?format="

        elements = document.getElementsByClassName("customBackground");
        for(i = 0; i < elements.length; i++) {
        
            var element = elements[i];
        
            // Get the custom image classname
            var customBackground = "";
            classNames = element.className.split(" ");
            for(j = 0; j < classNames.length; j++) {
                if (classNames[j] == "customBackground" && (j + 1) < classNames.length)
                {
                   customBackground = classNames[j + 1];
                   break;
                }
            }
            
            // Check that a custom background was specified
            if (customBackground == "")
                continue;
                
            // Get the height and width of the element
            var width = elements[i].offsetWidth;
            var height = elements[i].offsetHeight;
                           
            // Set the custom background image of the element
           // var backgroundImage = "https://images.golfbreaks.com/customimage.aspx?format=" + customBackground + "&width=" + width + "&height=" + height;
            var backgroundImage = "/images/custom/" + width + "/" + height + "/Stretch/" + customBackground + ".aspx";
            element.style.backgroundImage = "url(" + backgroundImage + ")";
            
        }
    }

