﻿var IDEASCALE_BASE_URL = 'https://oceanedge.ideascale.com';
var IS_DLG_WIDTH = 420;
var IS_DLG_HEIGHT = 480;

(function (window, document, undefined) {
    function QSObject(url) {
        //Create regular expression object to retrieve the qs part
        var qsReg = new RegExp("[?][^#]*", "i");
        var hRef = decodeURI(url);
        var qsMatch = hRef.match(qsReg);

        //removes the question mark from the url
        qsMatch = new String(qsMatch);
        qsMatch = qsMatch.substr(1, qsMatch.length - 1);

        //split it up
        var rootArr = qsMatch.split("&");
        for (var i = 0; i < rootArr.length; i++) {
            var tempArr = rootArr[i].split("=");
            if (tempArr.length == 2) {
                tempArr[0] = decodeURIComponent(tempArr[0]);
                tempArr[1] = decodeURIComponent(tempArr[1]);

                this[tempArr[0]] = tempArr[1];
            }
        }
    }

    var qs = new QSObject(document.getElementById("is-feedback-widget").src.toLowerCase());
    if (qs['width'] !== undefined) IS_DLG_WIDTH = qs['width'];
    if (qs['height'] !== undefined) IS_DLG_HEIGHT = qs['height'];

    var tab = document.createElement('img');
    tab.style.cursor = 'pointer';
    tab.style.position = 'fixed';
    tab.style.top = '350px';
    tab.style.left = '0';
    tab.style.zIndex = 10000;
    tab.style.cssText = tab.style.cssText + '; _position: absolute;';

    var tabSrc = IDEASCALE_BASE_URL + '/images/ideascale/themes/0/is_feedback.png';
    tab.src = tabSrc;

    function initialize() {
        document.body.appendChild(tab);

        var script = document.createElement('script');
        script.src = IDEASCALE_BASE_URL + '/javascript/lightbox-widget.js?1.3';
        document.body.appendChild(script);

        tab.onclick = function () {
            Lightbox.JS.show(IDEASCALE_BASE_URL + '/a/feedbackWidget.do', IS_DLG_HEIGHT, IS_DLG_WIDTH);
        };

        tab.onmouseover = function () {
            this.src = tabSrc.replace('.png', '_alt.png');
        }

        tab.onmouseout = function () {
            this.src = tabSrc;
        }
    }

    if (document.body) {//seems DOMReady.add doesn't work if the DOM is already fully loaded. so we need to initialize manually
        initialize();
    }
    else {
        /*!
        DOMReady

        Cross browser object to attach functions that will be called
        immediatly when the DOM is ready.

        @version   1.0
        @author    Victor Villaverde Laan
        @link      http://www.freelancephp.net/domready-javascript-object-cross-browser/
        @license   MIT license
        */
        var DOMReady = (function () { var fns = [], isReady = false, errorHandler = null, getFunc = function (fn) { if (typeof fn == 'string') return function () { eval(fn); }; return fn; }, ready = function () { isReady = true; for (var x = 0; x < fns.length; x++) { try { fns[x](); } catch (err) { if (errorHandler) errorHandler(err); } } }; this.setOnError = function (fn) { errorHandler = getFunc(fn); return this; }; this.add = function (fn) { fn = getFunc(fn); if (isReady) { fn(); } else { fns[fns.length] = fn; } return this; }; if (window.addEventListener) { document.addEventListener('DOMContentLoaded', function () { ready(); }, false); } else { (function () { if (!document.uniqueID && document.expando) return; var tempNode = document.createElement('document:ready'); try { tempNode.doScroll('left'); ready(); } catch (err) { setTimeout(arguments.callee, 0); } })(); } return this; })();

        DOMReady.add(initialize);
    }
})(this, this.document);
