/*
    js.js
        - JavaScript support for flash client         
*/

// name of the flash movie in the document
var objectName = "main";

// holds reference to the chat status script element
var chatStatusScript;

// holds reference to the chat monitor script element
var chatMonitorScript;

// __lc_loaded property - whether live chat API is loaded 
var __lc_loaded;

// holds the most current chat status
var LC_Status;

// init live chat definitions variable
var __lc = {};

// store live chat license id
__lc.license = 1032156;

// store live chat skill (1 means only WAD)
__lc.skill = 1;

// container to store reference to opened windows
var openedWindows = new Array();

// defines mapping of chat statuses to integers {{{
var chatStatuses = new Array();

chatStatuses['offline']         = 0;
chatStatuses['online']          = 1;
chatStatuses['voice']           = 2;
chatStatuses['expired']         = 3;
// }}}

// used to determine whether additional information container is visible or not
var additionalInformationActive = false;

function toggleAdditionalInformation(divId) {
    // get full document dimensions
    var dimensions = getDocumentSize(true);

    // compute height of the expanded container
    var containerHeight = Math.round((dimensions.height / 20) * 8);
 
    // get reference to the container
    var element = document.getElementById(divId);

    // show the container if it is hidden {{{
    if (!additionalInformationActive) {
        // make sure the browser scrollbars are always hidden
        document.body.style.overflow='auto';

        // remember that the container is active
        additionalInformationActive = true;

        // update height and position of the container {{{
        element.style.height = containerHeight + "px";
        element.style.top = (dimensions.height - containerHeight) + "px";
        // }}}
    } 
    // }}}
    // hide the container if its visible {{{
    else {
        // scroll to the top of the document
        scroll(0,0)

        // make sure the browser scrollbars are always hidden
        document.body.style.overflow='hidden';

        // remember that the container is inactive
        additionalInformationActive = false;

        // update height and position of the container {{{
        element.style.height = "20px";
        element.style.top = (dimensions.height - 20) + "px";
        // }}}
    }
    // }}}
}

function getBrowserType() {
    // default browser type value
    var browserType = 0;

    // determine browser type {{{
    if (navigator.userAgent.indexOf("Chrome") != -1) {
	browserType = 4;
    } 
    else if (navigator.appVersion.indexOf("MSIE") != -1) {
        browserType = 1;
    }
    else if (navigator.userAgent.indexOf("Opera") != -1) {
        browserType = 2;
    }
    else if (navigator.userAgent.indexOf("Safari") != -1) {
        browserType = 3;
    }
    // }}}

    // return the browser type
    return browserType;
}

function getOSType() {
    // return 0 for Windows OS {{{
    if (navigator.appVersion.toLowerCase().indexOf('win') != -1) {
        return 0;
    }
    // }}}
    // return 1 for the rest {{{
    else {
        return 1;
    }
    // }}}
}

function openWindow(windowId, uri, windowName, windowOptions) {
    // create the window
    var windowObject = window.open(uri, windowName, windowOptions);

    // notify the flash client if the window has failed to open {{{
    if ((windowObject == undefined) || ((window.opera) && (!windowObject.opera))) {
        // get the flash object
        var flashObject = getFlashMovieObject(objectName);

        // set the windowClosed property
        flashObject.SetVariable("windowDidNotOpen", windowId);
    }
    // }}}
    // otherwise store the reference to the created window {{{
    else {
        // store the ID of opened window
        openedWindows[windowId] = windowObject;
    }
    // }}}
}

function closeWindow(windowId) {
    // close the window specified by the ID
    openedWindows[windowId].close();
    // remove the window from registered windows
    delete openedWindows[windowId];
}

function checkIfWindowIsOpen(windowId) {
    // determine reference to the window object
    var windowObject = openedWindows[windowId];

    // assume the window is not opened
    var windowOpened = false;
    
    // if window is opened, set the windowOpened flag to true {{{
    if ((windowObject != undefined) && (!windowObject.closed)) {
        windowOpened = true;
    }
    // }}}

    // if window was closed, inform the flash client {{{
    if (!windowOpened) {
        // get the flash object
        var flashObject = getFlashMovieObject(objectName);

        // set the windowClosed property
        flashObject.SetVariable("windowClosed", windowId);
    }
    // }}}
}

function onWindowResize() {
    // determine flash overlay corners
    var overlayOffsets = getFlashOverlayOffsets();
    // get the document size
    var dimensions = getDocumentSize();

    // update the movie size
    updateMovieSize(dimensions);

    // update overlayOffsets in flash movie {{{
    var flashObject = getFlashMovieObject(objectName);
    flashObject.SetVariable("windowSize", dimensions.width + "x" + dimensions.height);
    flashObject.SetVariable("overlayOffsets", overlayOffsets);
    // }}}
}

function getFlashMovieObject(movieName) {
    // get the user agent of the browser
    var userAgent = navigator.userAgent;

    // Android {{{
    if ((userAgent.indexOf("Android") != -1)) {
        return window.document[movieName];
    }
    // }}}
    // Chrome {{{
    else if ((userAgent.indexOf("Chrome") != -1)) {
        return document.embeds[movieName];
    }
    // }}}
    // Konqueror, Internet Explorer {{{
    else if ((userAgent.indexOf("Konqueror") != -1) || (userAgent.indexOf("MSIE") != -1)) {
        return document.getElementById(movieName);
    }
    // }}}
    // Safari with support for different WebKit versions {{{
    else if (userAgent.indexOf("Safari") != -1) {
        // regexp to extract the version number
        var re = new RegExp('(?:Version/)([0-9]\.[0-9])');

        // get the version from Safari's appVersion property
        var safariWebKitVersion = (re.exec(navigator.appVersion))[1];

        // handle WebKit 5 (OSX 10.7 Lion +) {{{
        if (safariWebKitVersion > 5) {
            return window.document[movieName];
        }
        // }}}
        // handle older WebKit versions (< OSX 10.7.) {{{
        else {
            return document.getElementById(movieName);
        }
        // }}}
    }
    // }}}
    // Firefox / Mozilla {{{
    else if (window.document[movieName]) {
        return window.document[movieName];
    }
    // }}}
    // otherwise try to get the reference from a list of all embedded objects {{{
    else {
        return document.embeds[movieName];
    }
    // }}}
}

function getRatio() {
    // get the document size
    var dimensions = getDocumentSize();

    // compute ratios for both sides {{{
    var ratioHeight = dimensions.height / 650;          
    var ratioWidth = dimensions.width / 950;
    // }}}

    // use width ratio if its smaller {{{
    if (ratioHeight > ratioWidth) {
        var ratio = ratioWidth;
    } 
    // }}}
    // otherwise use height ratio {{{
    else {
        var ratio = ratioHeight;
    }
    // }}}
    
    // return the computed content ratio
    return ratio;
}

function getFlashOverlayOffsets() {
    // get the document size
    var dimensions = getDocumentSize();
    // get the flash content ratio
    var ratio = getRatio();

    // compute the real dimensions of the movie {{{
    var realMovieWidth = 950 * ratio;
    var realMovieHeight = 650 * ratio;
    // }}}

    // determine the offsets {{{
    var offsetX = Math.round(((realMovieWidth - dimensions.width) / 2) / ratio);
    var offsetY = Math.round(((realMovieHeight - dimensions.height) / 2) / ratio);
    // }}}

    // construct the offsets string for the flash client and return it
    return (offsetX + ":" + offsetY);
}

function updateMovieSize(dimensions) {
    // get the reference to flash object
    var flashObject = getFlashMovieObject(objectName);  

    // resize the flash movie for older IE versions {{{
    if ((document.all) && (!document.getElementById)) {
        flashObject.style.pixelWidth = dimensions.width + "px";
        flashObject.style.pixelHeight = dimensions.height + "px";
    }
    // }}}
    // resize the flash movie for modern browsers {{{
    else {
        flashObject.style.width = dimensions.width + "px";
        flashObject.style.height = dimensions.height + "px";
    }
    // }}}
}

function getDocumentSize(ignoreFooter) {
    // initialize the width and height variables {{{
    var documentWidth   = 0;
    var documentHeight  = 0;
    // }}}

    // Non-IE {{{
    if(typeof(window.innerWidth) == 'number') {
        documentWidth = window.innerWidth;
        documentHeight = window.innerHeight;
    }
    // }}}
    // IE 6+ in 'standards compliant mode' {{{
    else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        documentWidth = document.documentElement.clientWidth;
        documentHeight = document.documentElement.clientHeight;
    } 
    // }}}
    // IE 4 compatible {{{
    else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        documentWidth = document.body.clientWidth;
        documentHeight = document.body.clientHeight;
    }
    // }}}

    // if the Flash client footer is visible, subtract its height from the
    // overal Flash client height, so that it fits on screen aswell {{{
    // get the reference to the Flash client footer
    var flashClientFooter = document.getElementById("flashClientFooter");
        
    // subtract footer's height from the total height {{{
    if ((ignoreFooter != true) && (flashClientFooter != null) && (flashClientFooter.style.display != "none") && (documentHeight >= flashClientFooter.offsetHeight)) {
        documentHeight -= flashClientFooter.offsetHeight;
    }
    // }}}

    // return the computed document dimensions
    return { width: documentWidth, height: documentHeight };
}

function updateScreenResolution() {
    // determine reference to the flash movie
    var flashObject = getFlashMovieObject(objectName);

    // set screen resolution variable in flash movie
    flashObject.SetVariable("screenResolution", screen.width + "x" + screen.height);
}

function setInitialSettings() {
    // determine reference to the flash movie
    var flashObject = getFlashMovieObject(objectName);
    // get the document size
    var dimensions = getDocumentSize();

    // set client settings in the flash movie {{{
    flashObject.SetVariable("chatURI", "https://chat.livechatinc.net/licence/1032156/open_chat.cgi?lang=en&groups=1");
    flashObject.SetVariable("settingsURI", "**INSECURE**://**HOSTNAME**/**LANGUAGE**/shared/**THEME**/settings/**EXTENSION**?sid=3051f61fbcdb70f90a14b192a72784ab");
    flashObject.SetVariable("bootLoader", "http://media.winadaycasino.com/en/flash/winter/boot/bootLoader.swf?build=201201251845");
    flashObject.SetVariable("chatEnabled", "1");
    flashObject.SetVariable("browserType", getBrowserType());
    flashObject.SetVariable("build", "201201251845");
    flashObject.SetVariable("clientCopyright", "Copyright © 2007-2012 Slotland Entertainment S.A., All Rights Reserved.");
    flashObject.SetVariable("extension", "xml");
    flashObject.SetVariable("hostname", "www.winadaycasino.com");
    flashObject.SetVariable("swfHostname", "media.winadaycasino.com");
    flashObject.SetVariable("language", "en");
    flashObject.SetVariable("loadingText", "Loading");
    flashObject.SetVariable("preLoadingText", "Win A Day Casino is loading");
    flashObject.SetVariable("loadingFailedText", "We apologize for the inconvenience but there was a problem while communicating with the server. Please check your Internet connection and try again. ==P====LIA|IA_RETRY_LAST_REQUEST==Try again==EL== ==P====FSMALL====B==Error URI==EB====EF====N==");
    flashObject.SetVariable("overlayOffsets", getFlashOverlayOffsets());
    flashObject.SetVariable("theme", "winter");
    flashObject.SetVariable("windowSize", dimensions.width + "x" + dimensions.height);
    flashObject.SetVariable("jackpot", "21335722");
    // }}}

    // set flag to inform flash client that all initialization variables were set
    flashObject.SetVariable("initialSettings", 1);
}

function showFlashClientFooter() {
    // get reference to the Flash client footer
    var flashClientFooter = document.getElementById("flashClientFooter");

    // initial display type for all browsers
    var displayStyle = "table";

    // IE does not support 'table' display properly, so use block {{{
    if (getBrowserType() == 1) {
        displayStyle = "block";
    }
    // }}}

    // show the footer table {{{
    if (flashClientFooter.style.display != displayStyle) {
        // show the footer table
        flashClientFooter.style.display = displayStyle;

        // resize the Flash client size
        onWindowResize();
    }
    // }}}
}

function hideFlashClientFooter(emptyFooterOnly) {
    // get reference to the Flash client footer
    var flashClientFooter = document.getElementById("flashClientFooter");

    // if the footer table is visible, hide it and update client size {{{
    if (flashClientFooter.style.display != "none") {
        // scroll to the top of the document
        scroll(0,0)

        // empty the footer contents, but leave the block intact {{{
        if (emptyFooterOnly) {
            flashClientFooter.innerHTML = "";
        } 
        // }}}
        // hide the whole footer block {{{
        else {
            // hide the footer table
            flashClientFooter.style.display = "none";

            // update the Flash client size
            onWindowResize();
        }
        // }}}
    }
    // }}}
}

function insertFlashClient() {
    // get document dimensions
    var windowDimensions = getDocumentSize();
	
    // get the browser type
    var browserType = getBrowserType();

    // use 'transparent' wmode to enable z-indexing of the Flash object {{{
    // NOTE: enabled for all Windows browsers but Opera which freezes with wmode enabled
    if ((getOSType() == 0) || (browserType == 4)) {
        var wmode = "opaque";
    }
    // }}}
    // Firefox on Linux has weak support for wmode (not working, crashing the
    // browser or enormous slow downs of the Flash content) {{{
    else {
        var wmode = "window";
    }
    // }}}

    // create the content string to be written into the document {{{
    var content = '<object style="z-index: 1;" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"\n' + 
                  '  codebase="https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0"\n' +
                  '  width="' + windowDimensions.width + '" ' +
                  '  height="' + windowDimensions.height + '" ' +
                  '  id="main" align="top">\n' +
                  '  <param name="allowScriptAccess" value="always" />\n' +
                  '  <param name="swLiveConnect" value="true" />\n' +
                  '  <param name="movie" value="http://media.winadaycasino.com/en/flash/winter/boot/preLoader.swf?build=201201251845" />\n' +
                  '  <param name="quality" value="best" />\n' +
                  '  <param name="wmode" value="' + wmode + '" />\n' +
                  '  <param name="allowFullScreen" value="true" />\n' +
                  '  <param name="bgcolor" value="#000000" />\n' +
                  '  <embed src="http://media.winadaycasino.com/en/flash/winter/boot/preLoader.swf?build=201201251845" quality="best" bgcolor="#000000"' +
                  '     swLiveConnect="true" wmode="' + wmode + '" width="' + windowDimensions.width + '" '+
                  '     height="' + windowDimensions.height + '" ' + 
                  '     name="main" align="top"\n' +    
                  '     allowFullScreen="true"\n' + 
                  '     allowScriptAccess="always" type="application/x-shockwave-flash"\n' +
                  '     pluginspage="http://www.macromedia.com/go/getflashplayer"/>\n' +        
                  '</object>\n';
    // }}}

    // write the content for mozilla based browsers {{{
    if (browserType == 0 || browserType == 3 || browserType == 4) {
        document.write(content);
    } 
    // }}}
    // write the content for other browsers {{{
    else {
        window.document.write(content);
    }
    // }}}
}

function insertImagePageHeader() {
    // create the content string to be written into the document
    var content = '<img src="/en/file/winter/image/pageHeader.gif" border="0" width="573" height="141" alt="Win A Day Casino" />';
    // write the content
    document.getElementById("pageHeader").innerHTML = content;
}

function insertImagesInstallFlash() {
    // create the content string to be written into the document {{{
    var content = '<img id="offImage" src="/en/file/winter/image/flashOff.gif" width="391" height="176" alt="Click here to install Adobe Flash Player" />' +
                  '<img src="/en/file/winter/image/flashOn.gif" width="391" height="176" alt="Click here to install Adobe Flash Player" />';
    // }}}
    
    // write the content
    document.getElementById("installFlashLink").innerHTML = content;
}

function insertImagesUpgradeFlash() {
    // create the content string to be written into the document {{{
    var content = '<img id="offImage" src="/en/file/winter/image/flashUpgradeOff.gif" width="391" height="176" alt="Click here to upgrade Adobe Flash Player" />' +
                  '<img src="/en/file/winter/image/flashUpgradeOn.gif" width="391" height="176" alt="Click here to upgrade Adobe Flash Player" />';
    // }}}
    
    // write the content
    document.getElementById("upgradeFlashLink").innerHTML = content;
}

function insertImagesScreenshot() {
    // create the content string to be written into the document {{{
    var content = '<img src="/en/file/winter/image/wadEntrance.jpg" width="282" height="200" alt="Win A Day Casino Screenshot of Entrance" />' +
                  '<img src="/en/file/winter/image/wadGames.jpg" width="215" height="200" alt="Win A Day Casino Screenshot of Games" />';
    // }}}
    
    // write the content
    document.getElementById("screenshots").innerHTML = content;
}

function showTransactionButton(buttonText, x, y) {
    // get the reference to the transacttion button
    var buttonDiv = document.getElementById("transactionButton");
 
    // tell the button to ignore document flow for positioning it
    // (must be done here otherwise IE will not display the DIV correctly)
    buttonDiv.style.position = "absolute";

    // determine the current ratio of the content
    var ratio = getRatio();

    // position the button applying the ratio on both axis to achieve correct
    // placement according to the flash movie {{{
    buttonDiv.style.left = x * ratio + "px";
    buttonDiv.style.top = y * ratio + "px";
    // }}}
    
    // set the fontSize also applying the ratio to match font size in the flash client
    buttonDiv.style.fontSize = Math.round(15 * ratio);

    // insert the button text into the div
    buttonDiv.innerHTML = buttonText;

    // show the transaction button
    document.getElementById("transactionButton").style.display = "block";

    // Firefox on Linux does not support proper wmode and z-indexing so use the
    // iframe hack to display the button {{{
    if (getOSType() == 1) {
        // get the reference to the iframe
        var iframe = document.getElementById("transactionIframe");

        // position and resize the iframe according to the button's dimensions {{{
        iframe.style.left = (x * ratio) + "px";
        iframe.style.top = (y * ratio) + "px";
        iframe.style.width = buttonDiv.offsetWidth + "px";
        iframe.style.height = buttonDiv.offsetHeight + "px";
        // }}}       

        // show the iframe
        iframe.style.display = "block";
    }
    // }}}
}

function hideTransactionButton() {
    // get the reference to the transacttion button
    var buttonDiv = document.getElementById("transactionButton");

    // reset the content of the div
    buttonDiv.innerHTML = "";
    // hide the transaction button
    buttonDiv.style.display = "none";

    // hide the iframe in Linux hack {{{
    if (getOSType() == 1) {
        // get the reference to the iframe
        var iframe = document.getElementById("transactionIframe");

        // hide the iframe
        iframe.style.display = "none";
    }
    // }}}
}

function hasFlash(requiredFlashVersion) {
    // get the version numbers {{{
    // get version numbers for the required flash version {{{
    var requiredVersion = new String(requiredFlashVersion).split(".");
    var requiredMajor = Number(requiredVersion[0]);
    var requiredMinor = Number(requiredVersion[1]);
    var requiredRevision = Number(requiredVersion[2]);
    // }}}

    // get version numbers for the client flash version {{{
    var clientVersion = new String(getFlashVersion()).split(".");
    var clientMajor = Number(clientVersion[0]);
    var clientMinor = Number(clientVersion[1]);
    var clientRevision = Number(clientVersion[2]);
    // }}}
    // }}}

    // if major version is higher any other checks are not necessary so skip them and return true {{{
    if (clientMajor > requiredMajor) {
        return true;
    }
    // }}}
    // if same major versions, check the minor and revision numbers {{{
    else if (clientMajor == requiredMajor) {
        // if minor version is higher any other checks are not necessary so return true {{{
        if (clientMinor > requiredMinor) {
            return true;
        }
        // }}}
        // otherwise check revision {{{
        else if (clientMinor == requiredMinor) {
            // if revision equals or is higher, return true {{{
            if (clientRevision >= requiredRevision) {
                return true;
            }
            // }}}
        }
        // }}}
    }
    // }}}

    // otherwise return false as the client version is too low 
    return false;
}

function getFlashVersionString(pluginVersionString) {
    // get flash version out of the version string
    var version = pluginVersionString.match(/[\d]+/g);

    // limit the version length to 3 digits 
    // (compatibility between IE and FF)
    version.length = 3;

    // return the version
    return version.join(".");
}

function getFlashVersion() {
    // initialize variable which will hold the flash version
    var flashVersion = '';

    // every browser except IE supports the plugins container {{{
    if ((navigator.plugins) && (navigator.plugins.length)) {
        // get the plugin object
        var plugin = navigator.plugins['Shockwave Flash'];

        // if the plugin is set, look for description and get the flash version {{{
        if (plugin) {
            if (plugin.description) {
                flashVersion = getFlashVersionString(plugin.description);
            }
        }
        // }}}
    }
    // }}}
    // if the first failed, next solution is to look up the mimeTypes container {{{
    else if ((navigator.mimeTypes) && (navigator.mimeTypes.length)) {
        // check if the flash MIME type can be found
        var mimeType = navigator.mimeTypes['application/x-shockwave-flash'];

        // if the MIME type was found and plugin is enabled, access the version
        // through MIME type plugin object {{{
        if (mimeType && mimeType.enabledPlugin) {
            flashVersion = getFlashVersionString(mimeType.enabledPlugin.description);
        }
        // }}}
    }
    // }}}
    // get version from Internet Explorer {{{
    else {
        // get the version from the ActiveX object for Flash plugin 7 and up {{{
        try {
            // try 7 first, since we know we can use GetVariable with it
            var ax = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.7');
            flashVersion = getFlashVersionString(ax.GetVariable('$version'));
        }
        // }}}
        // no valid version so try the default ActiveX object {{{
        catch (e) {
            // try the default activeX {{{
            try {
                var ax = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
                flashVersion = getFlashVersionString(ax.GetVariable('$version'));
            }
            // }}}
            // no flash {{{
            catch (e) {
                // No flash
            }
            // }}}
        }
        // }}}
    }
    // }}}

    // return the flash version
    return flashVersion;
}

function onChatStatusLoaded() {
    // clean up the the chat script element
    document.getElementsByTagName("head")[0].removeChild(chatStatusScript)
 
    // get the flash object
    var flashObject = getFlashMovieObject(objectName);

    // set the windowClosed property
    flashObject.SetVariable("chatStatus", chatStatuses[LC_Status]);   
}

function checkForChatStatus() {
    // invoke on chat status loaded callback if LC_Status is defined {{{
    if (LC_Status != undefined) {
        onChatStatusLoaded();
    }
    // }}}
    // otherwise setup next check {{{
    else {
        // setup timeout which periodically checks for presence of LC_Status
        setTimeout("checkForChatStatus()", 1000);
    }
    // }}}
}

function getChatStatus() {
    // dynamically create the script element for loading chat status on demand
    chatStatusScript = document.createElement("script");
    
    // set the script element type
    chatStatusScript.type = "text/javascript";

    // allow processing of the rest of the page while the script is being sourced
    chatStatusScript.async = true;

    // reset LC_Status
    LC_Status = undefined;

    // setup timeout which periodically checks for presence of LC_Status
    setTimeout("checkForChatStatus()", 1000);

    // set next update to 5 minutes
    setTimeout("getChatStatus()", 300000);

    // set the URL from with the current chat status
    chatStatusScript.src = location.protocol + "//chat1a.livechatinc.com/licence/1032156/buttontype.cgi?time=" + (new Date().getTime());

    // add the element to header and essentially start loading the chat status
    document.getElementsByTagName("head")[0].appendChild(chatStatusScript);
}

function chatMonitor(auxiliaryData, auxiliaryDataParsed) {
    // remove previous instance of chat monitor script {{{
    if (chatMonitorScript != undefined) {
        // clean up the the chat script element
        document.getElementsByTagName("head")[0].removeChild(chatMonitorScript)
    }
    // }}}

    // if live chat API allready loaded, store the container using it's set
    // custom variables method {{{
    if(__lc_loaded) {
        LC_API.set_custom_variables(auxiliaryData);
    } 
    // }}}
    // otherwise store the parameters in live chat property {{{
    else {
        // store auxiliary parameters in live chat definition
        __lc.params = auxiliaryDataParsed;
    }
    // }}}

    // dynamically create the script element for loading chat status on demand
    chatMonitorScript = document.createElement("script");
    
    // set the script element type
    chatMonitorScript.type= "text/javascript";

    // allow processing of the rest of the page while the script is being sourced
    chatMonitorScript.async = true;

    // set the script URL to load the chat status
    chatMonitorScript.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'cdn.livechatinc.com/tracking.js';

    // add the element to header and essentially start loading the chat status
    document.getElementsByTagName("head")[0].appendChild(chatMonitorScript);
}

// if the client's Flash Plugin version meets the requirements, initialize the main flash movie {{{
if (hasFlash("10.0.0")) {
    // make sure the browser scrollbars are always hidden
    document.body.style.overflow='hidden';
    // draw the Flash client
    insertFlashClient();
}
// }}}
// otherwise display HTML message with instructions how to get the required version of the Flash Plugin {{{
else {
    // draw the page header image
    insertImagePageHeader();

    // for users with old version of Flash plugin display a message that they need to update it {{{
    if (hasFlash("0.0.0")) {
        // draw the upgrade flash images
        insertImagesUpgradeFlash();
        // show the div container which will display the message
        document.getElementById("upgradeFlash").style.display = "block";
    }
    // }}}
    // for users without Flash plugin display a message that they need to install it {{{
    else {
        // draw the install flash images
        insertImagesInstallFlash();
        // show the div container which will display the message
        document.getElementById("installFlash").style.display = "block";
    }
    // }}}

    // draw the screenshot images
    insertImagesScreenshot();
    // display the div with instructions to install the Flash plugin
    document.getElementById("noFlash").style.display = "block";
    // make the div container with the SEO links position relative
    document.getElementById("flashClientFooter").style.position = "static";
}
// }}}


