/** Helper Script File */
(function(){

    jQuery(function() {
        helper.init();
    });

    var helper = {

        init: function() {
            this.attachLoginIframe();
            this.attachInviteRequestForm();
        },

        attachLoginIframe: function() {
            if (jQuery(".login").length) {
                //Trick To Remove White Flicker When Loading Iframe
                var removeFlicker = "style='visibility:hidden;' onload='this.style.visibility = \"visible\";'";
                var login_iframe = jQuery("<iframe id='login_iframe' frameBorder='0' allowTransparency='true' "+removeFlicker+" width='600px' height='70px' src='http://social." + this.getEnvPath() + "/modules/iframes/html/login.html'></iframe>");
                //We May want to make this an ID but it will have to be done by design in the DWT template
                jQuery(".login").append(login_iframe);
            }
        },

        attachInviteRequestForm: function() {
            if(jQuery("#request_invite").length) {
                //Trick To Remove White Flicker When Loading Iframe
                var removeFlicker = "style='visibility:hidden;' onload='this.style.visibility = \"visible\";'";
                var invite_iframe = jQuery("<iframe id='invite_iframe' frameBorder='0' allowTransparency='true' "+removeFlicker+" width='600px' height='190px' src='http://social." + this.getEnvPath() + "/modules/iframes/html/request_invite.html?prov="+this.getProviderQs()+"'></iframe>");
                jQuery("#request_invite").append(invite_iframe);
            }
        },

        /**
         * Get Environment Path.. Eg. social.[master.dev]
         */
        getEnvPath: function() {
            var env_path_split = document.location.host.split(".");
            return env_path_split[1] +"."+  env_path_split[2];
        },

        /**
         * Include The Provider Query String
         */
        getProviderQs: function() {
            //Get The Host From The Document Location
            var env_path_split = document.location.host.split(".");
            return env_path_split[0];
        }
    }

})();

