function getRootURL() {

    var baseURL = location.href;
    var rootURL = baseURL.substring(0, baseURL.indexOf('/', 7));
    // if the root url is localhost, don't add the directory as cassani doesn't use it
    if (baseURL.indexOf('localhost') == -1) {

        return rootURL + "/";

    } else {

        return rootURL + baseURL.substring(baseURL.indexOf('/', 8), baseURL.indexOf('/', baseURL.indexOf('/', 8) + 1)) + "/";

    }
}

function PopupCenter(pageURL, title, w, h) {
    var left = (screen.width / 2) - (w / 2);
    var top = (screen.height / 2) - (h / 2);
    var targetWin = window.open(pageURL, '', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
//    if (window.focus) {window.focus()}
      return false;
};

function openPublication(pub) {

    if (pub.lenght == 0) return;

    if (pub.indexOf(":") <= 0) {
        var ventana = window.open(pub, "Revista", "width=800, height=600, status=no, scrollbars=no, toolbars=no, menubar=no");
    }else {
      var _url = pub.substring(pub.indexOf(":") + 1, pub.lenght);
      window.location.href = _url;
    }
}    

if (typeof golfhoyoahoyo == 'undefined') var golfhoyoahoyo = {};
if (!golfhoyoahoyo.Sys) golfhoyoahoyo.Sys = {};
if (!golfhoyoahoyo.Application) golfhoyoahoyo.Application = {};

golfhoyoahoyo.Sys.registerNamespace = function (namespace) {
    namespace = namespace.split('.');
    if (!window[namespace[0]]) window[namespace[0]] = {};
    var strFullNamespace = namespace[0];
    for (var i = 1; i < namespace.length; i++) {
        strFullNamespace += "." + namespace[i];
        eval("if(!window." + strFullNamespace + ")window." + strFullNamespace + "={};");
    }
};

/// <summary>
/// Application
/// </summary>

golfhoyoahoyo.Sys.registerNamespace("golfhoyoahoyo.Application");
golfhoyoahoyo.Application = {

    Parent: null,
    // Inicializa la aplicación
    New: function () {
      
       
      
        var _Snowfall, staClaus, staClausMsg ;
      
        /*_snowTimeout = setTimeout(function () { 
          
          _Snowfall  = new golfhoyoahoyo.Plugins.Snowfall.New(window.document, { round: false, minSize: 12, maxSize: 12, flakeCount: 75, imageUrl: '"../css/ghh-images/snow-12.png"' });
        
          staClaus = $(document.createElement("div")).
                                    attr({ 'id': 'santa' }).
                                    css({ 'border': '0px solid blue',
                                        'width': '100px', 'height': '100px',
                                        'position': 'absolute',
                                        'display':'none',
                                        'left': '760px', 'top': '520px',
                                        'background': 'url("../css/ghh-images/santa-100.png") no-repeat bottom left'
                                    });

          staClausMsg = $(document.createElement("div")).
                                    attr({ 'id': 'santa_msg' }).
                                    css({ 'border': '0px solid blue',
                                        'width': '195px', 'height': '90px',
                                        'position': 'absolute',
                                        'left': '570px', 'top': '480px',
                                        'display':'none',
                                        'background': 'url("../css/ghh-images/boca-santa.png") no-repeat bottom left'
                                    });

          $('#body').append(staClaus);
          $('#body').append(staClausMsg);
          
          $('#santa').fadeIn(5000);$('#santa_msg').fadeIn(5000);
          
        }, 1500);
              
       
       

        _snowTimeout = setTimeout(function () { $('#santa').fadeOut(5000); $('#santa_msg').fadeOut(5000); $('.snowfall-flakes').fadeOut(5000); }, 10000);
        _snowTimeout = setTimeout(function () { $('#santa').remove(); $('#santa_msg').remove(); _Snowfall.clear(); }, 15000);

        clearTimeout(_snowTimeout);
      
		*/
		
		
    }, //New1

}

// Plugins
golfhoyoahoyo.Sys.registerNamespace("golfhoyoahoyo.Plugins");
golfhoyoahoyo.Plugins = {
  
  Snowfall: {

        New: function (element, options) {

            var defaults = {
                flakeCount: 35,
                flakeColor: '#ffffff',
                flakeIndex: 999999,
                minSize: 1,
                maxSize: 3,
                minSpeed: 2,
                maxSpeed: 3,
                round: false,
                shadow: false,
                imageUrl: ''
            },
      options = $.extend(defaults, options),
      random = function random(min, max) {
          return Math.round(min + Math.random() * (max - min));
      };

            $(element).data("snowfall", this);

            // (en) Snow flake object
            // (es) Objeto copo de nieve
            function Flake(_x, _y, _size, _speed, _id) {

                // (en) Properties
                // (es) Propiedades
                this.id = _id;
                this.x = _x;
                this.y = _y;
                this.size = _size;
                this.speed = _speed;
                this.step = 0,
        this.stepSize = random(1, 10) / 100;
                this.background = (options.imageUrl === '') ? options.flakeColor : 'url(' + options.imageUrl + ') no-repeat top left';
                this.flakeMarkup = $(document.createElement("div")).
                                  attr({ 'class': 'snowfall-flakes', 'id': 'flake-' + this.id }).
                                  css({ 'width': this.size, 'height': this.size,
                                      'background': this.background,
                                      'position': 'absolute',
                                      'top': this.y,
                                      'left': this.x,
                                      'fontSize': 0,
                                      'zIndex': options.flakeIndex
                                  });

                if ($(element).get(0).tagName === $(document).get(0).tagName) {
                    $('body').append(this.flakeMarkup);
                    element = $('body');
                } else {
                    $(element).append(this.flakeMarkup);
                }

                this.element = document.getElementById('flake-' + this.id);


                // (en) Update function, used to update the snow flakes, and checks current snowflake against bounds
                // (es) Función update, se utiliza para actualizar los copos de nieve y para controlar los límites.
                this.update = function () {

                    this.y += this.speed;

                    if (this.y > (elHeight) - (this.size + 6)) {
                        this.reset();
                    }

                    this.element.style.top = this.y + 'px';
                    this.element.style.left = this.x + 'px';

                    this.step += this.stepSize;
                    this.x += Math.cos(this.step);

                    if (this.x > (elWidth) - widthOffset || this.x < widthOffset) {
                        this.reset();
                    }
                }

                // (en) Resets the snowflake once it reaches one of the bounds set
                // (es) Restablece el copo de nieve cuando alcanza los límites establecidos
                this.reset = function () {
                    this.y = 0;
                    this.x = random(widthOffset, elWidth - widthOffset);
                    this.stepSize = random(1, 10) / 100;
                    this.size = random((options.minSize * 100), (options.maxSize * 100)) / 100;
                    this.speed = random(options.minSpeed, options.maxSpeed);
                }


            }

            // (en) Private vars
            // (es) Variables privadas
            var flakes = [],
        flakeId = 0,
        i = 0,
        elHeight = $(element).height(),
        elWidth = $(element).width(),
        widthOffset = 0,
        snowTimeout = 0;

            // (en) This will reduce the horizontal scroll bar from displaying, when the effect is applied to the whole page
            // (es) Impide que la barra de desplazamiento hotizontal se muestre cuando el efecto se aplica a toda la página
            if ($(element).get(0).tagName === $(document).get(0).tagName) {
                widthOffset = 25;
            }

            // (en) Bind the window resize event so we can get the innerHeight again
            // (es) Canpurar el evento de reajuste de la ventana para que podamos obtener el innerHeight (Tamaño interno)
            $(window).bind("resize", function () {
                elHeight = $(element).height();
                elWidth = $(element).width();
            });


            // (en) Initialize the snowflakes
            // (es) Inicializar los copos de nieve
            for (i = 0; i < options.flakeCount; i += 1) {
                flakeId = flakes.length;
                flakes.push(new Flake(random(widthOffset, elWidth - widthOffset), random(0, elHeight), random((options.minSize * 100), (options.maxSize * 100)) / 100, random(options.minSpeed, options.maxSpeed), flakeId));
            }

            // (en) This adds the style to make the snowflakes round via border radius property 
            // (es) Añade el estilo que permite redondear los bordes de los copos de nieve
            if (options.round) {
                $('.snowfall-flakes').css({ '-moz-border-radius': options.maxSize, '-webkit-border-radius': options.maxSize, 'border-radius': options.maxSize });
            }

            // (en) This adds shadows just below the snowflake
            // (es) Añadir sombra a los copos de nieve
            if (options.shadow) {
                $('.snowfall-flakes').css({ '-moz-box-shadow': '1px 1px 1px #555', '-webkit-box-shadow': '1px 1px 1px #555', 'box-shadow': '1px 1px 1px #555' });
            }

            // (en) This controls flow of the updating snow
            // (es) Controla el flujo de actualización de los copos nieve
            function snow() {
                for (i = 0; i < flakes.length; i += 1) {
                    flakes[i].update();
                }

                snowTimeout = setTimeout(function () { snow() }, 30);
            }

            snow();

            // (en) Public Methods
            // (es) Métodos públicos

            // (en) clears the snowflakes
            // (es) Elimina los copos de nieve
            this.clear = function () {
                $(element).children('.snowfall-flakes').remove();
                flakes = [];
                clearTimeout(snowTimeout);
            };
        }


    } // snowfall

}

