// Implement method stubs for window.console to allow for transparent use of the Firebug API
if (window['console'] === undefined) {
    window['console'] = function() { };
    console.log = function() { };
}

// Declare the default namespace objects
var MillerCoors = {};
var MillerChill = {};

// Create a method that will allow us to extend the functionality of an 
// object with that of another object. Think of this as inheritence 
// through the process of copying properties / methods
MillerCoors.Extend = function(destination, source) {
    for (var property in source.prototype) {
        if (destination.prototype[property] === undefined) {
            destination.prototype[property] = source.prototype[property];
        }
    }
    return destination;
};

// Define the core object for use in the system. This defines a basic structure 
// of the javascript framework that we'll be using for the site.
MillerCoors.Core = function() {
    this.Initialize();
};

$(document).ready(function() {
    var __core__ = new MillerCoors.Core();
});

MillerCoors.Core.prototype = {
    InitializeServices: function() { },
    AttachEvents: function() { },
    Display: function() { },
    Initialize: function() {
        this.InitializeServices();
        this.AttachEvents();
        this.Display();

        function openPopupWindow(url, windowName, options) {
            if (url) {

                // Build a default set of options if none are given
                options = options || {
                    width: 640,
                    height: 500,
                    toolbar: "no",
                    scrollbars: "yes",
                    resizable: "no"
                };

                // If no placement was given, center the window
                options.left = options.left || (window.screen.width - options.width) / 2;
                options.top = options.top || (window.screen.height - options.height) / 2;

                // Build a standard features string
                var features = "";
                for (var i in options) {
                    features += i + "=" + options[i] + ",";
                }

                // Remove the trailing comma
                features = features.substr(0, features.length - 1);

                // Create the popup and focus it
                currentPopup = window.open(url, windowName, features);
                if (currentPopup)
                    currentPopup.focus();

                // Ensure that the popup window closes when the parent page does
                var delegate = window.onunload;
                window.onunload = function() {
                    if (currentPopup)
                        currentPopup.close();
                    if (delegate)
                        delegate.call();
                }
            }
        }

        $('ul.UtilityLinks a').click(function(event) {
            openPopupWindow($(this).attr('href'), 'popup');

            // If we are in a modern browser with decent DOM support let's use
            // it, otherwise we can just return false on the event to stop propogation
            if (event.preventDefault) {
                event.preventDefault();
            } else {
                event.returnValue = false;
            }
            
            // Track the click for seo purposes
            switch ($(this).attr('title').toLowerCase()) {
                case "site map":
                    dotPage("Chill Site Map: Main", "Chill Site Map");
                    break;
                case "privacy policy":
                    dotPage("Chill Privacy Policy", "Chill Legal Mandatories");
                    break;
                case "terms and conditions":
                    dotPage("Chill Terms and Conditions", "Chill Legal Mandatories");
                    break;
                case "contact us":
                    dotPage("Chill Contact Us: Registration", "Chill Contact Us");
                    break;
            }
        });

        $('.LogoResponsibility, .LogoResponsibilityComplete').click(function(event) {
            openPopupWindow($(this).attr('href'), 'popup', { width: 1000, scrollbars: "yes" });
            
            // If we are in a modern browser with decent DOM support let's use
            // it, otherwise we can just return false on the event to stop propogation
            if (event.preventDefault) {
                event.preventDefault();
            } else {
                event.returnValue = false;
            }
        });
    }
};


