﻿/*
###############################################################
SplashPage JS to load a div on the home page when users visit the website using below querystring:
http://www.pensionsboard.ie/en/?campaign=calc
###############################################################
*/

var queryVariableName;
var queryVariableValue;

var splashOverlayClass;
var splashOverlay;

var splashContainerClass;
var splashContainer;

var splashWrapperClass;
var splashWrapper;

var visibleClass = "IsVisible";
var hiddenClass = "IsHidden";

var splashButtonClass;
var splashButtons;

var splashCloseButtonId;
var splashCloseButton;

$(document).ready(function() {
    PBSplash_InitObjects();
    PBSplash_InitEvents();

    PBSplash_ShowSplash();
});

function PBSplash_InitObjects() {
    queryVariableName = "campaign";
    queryVariableValue = $.query.get(queryVariableName);

    splashOverlayClass = "PBSplashOverlay";
    splashOverlay = $("div." + splashOverlayClass);

    splashContainerClass = "PBSplashContainer";
    splashContainer = $("div." + splashContainerClass);

    splashWrapperClass = "PBSplashWrapper";
    splashWrapper = $("div." + splashWrapper);

    splashButtonClass = "PBSplashButton";
    splashButtons = $("div." + splashButtonClass);

    splashCloseButtonId = "PBSplashCloseButton";
    splashCloseButton = $("div[id='" + splashCloseButtonId + "']");
}

function PBSplash_InitEvents() {
    if ((splashCloseButton != null) && (splashCloseButton.length != 0)) {
        splashCloseButton.click(function(event) {
            if ((splashOverlay != null) && (splashOverlay.length >= 1)) {
                splashOverlay.removeClass(visibleClass);
                splashOverlay.addClass(hiddenClass);
            }

            if ((splashContainer != null) && (splashContainer.length >= 1)) {
                splashContainer.removeClass(visibleClass);
                splashContainer.addClass(hiddenClass);
            }
        });
    }
}

function PBSplash_ShowSplash() {
    if ((queryVariableValue != null) && (queryVariableValue.length != 0) && (queryVariableValue == "calc")) {
        PBSplash_ConfigureDimensions();
        
        if ((splashOverlay != null) && (splashOverlay.length >= 1)) {
            splashOverlay.removeClass(hiddenClass);
            splashOverlay.addClass(visibleClass);
        }

        if ((splashContainer != null) && (splashContainer.length >= 1)) {
            splashContainer.removeClass(hiddenClass);
            splashContainer.addClass(visibleClass);
        }
    }
}

function PBSplash_ConfigureDimensions() {
    var height = $("body").height();
    var width = $("body").width();
    
    if ((splashOverlay != null) && (splashOverlay.length >= 1)) {
        splashOverlay.height(height);
        splashOverlay.width(width);
    }

    if ((splashContainer != null) && (splashContainer.length >= 1)) {
        splashContainer.height(height);
        splashContainer.width(width);
    }
}
