﻿/* globals
    jQuery, CsLogger
 */
/* exported
 */
"use strict";
(function ($, window, document, undefined) {

    // default settings.
    var _pluginName = "embeddedWebPage";
    var _defaultsOptions = {
        debug: false,
        rotateInterval: 5000,
        rotateFxDuration: 2000,
        enableParallax: false
    };
    var _logger = new CsLogger(_pluginName);

    // constructor.
    function EmbeddedWebPage(element, options) {
        this._element = element;

        // $.extend to store user provided options.
        this._options = $.extend({}, _defaultsOptions, options);
        this._defaultOptions = _defaultsOptions;
        this._name = _pluginName;
        this.init();
    }

    // (void) ensure the selected element is valid.
    function validateElement(element) {
        _logger.log("validateElement()");
        if (element == undefined || $(element).length == 0) {
            _logger.error("selected element is not valid.");
            return;
        }
    }

    // (void) validate the options passed into the plugin.
    function validateOptions(options) {
        if (typeof (options.debug) == "boolean" && options.debug == true) {
            _logger.enable();
        }
        if (typeof (options.enableParallax) == "boolean") {
            _defaultsOptions.enableParallax = options.enableParallax;
        }
        _logger.obj("validateOptions() | opts:", options);
    }

    // prototype extensions.
    EmbeddedWebPage.prototype = {

        // (void) initialise.
        init: function () {
            validateOptions(this._options);
            validateElement(this._element);
            _logger.log("init()");
        }
    };

    // A really lightweight plugin wrapper around the constructor,
    // preventing against multiple instantiations
    $.fn[_pluginName] = function (options) {
        return this.each(function () {
            if (!$.data(this, "plugin_" + _pluginName)) {
                $.data(this, "plugin_" + _pluginName,
                    new EmbeddedWebPage(this, options));
            }
        });
    };

})(jQuery, window, document);