﻿(function ($) {
    $.fn.active = function () {
        return this.each(function () { $(this).addClass('active'); });
    };
    $.fn.expand = function (options) { //plugin start
        var settings = $.extend({
            oHeight: 150, //collapsed height
            eHeight: 386, //expanded height
            showText: 'SHOW', //the text to show to show
            hideText: 'HIDE', //the text to show to hide
            showClass: '', //the show class
            hideClass: '', //the hide class
            timeout: 200, //animation time		
            defaultOpen: false, //if set to true, the expanded view will be the default state
            parent: 'div:eq(0)', //parent element to hide/show, in relation to the trigger
            doOpen: function () { },
            doClose: function () { }
        }, options || {});

        return this.each(function () {
            $(this).toggle(function (e) {
                e.preventDefault();
                $(this).html(settings.hideText).removeClass(settings.showClass).addClass(settings.hideClass)
				.parents(settings.parent).animate({ height: settings.eHeight + 'px' }, settings.timeout);
                settings.doOpen();
            }, function (e) {
                e.preventDefault();
                $(this).html(settings.showText).removeClass(settings.hideClass).addClass(settings.showClass)
				.parents(settings.parent).animate({ height: settings.oHeight + 'px' }, settings.timeout);
                settings.doClose();
            });
            if (settings.defaultOpen) {
                $(this).click();
            }
        });
    };
    $.fn.pseudohover = function (options) {
        var s = $.extend({
            hover: '#overridethis',
            pseudo: '#overridethis',
            className: ''
        }, options || {});
        return this.each(function () {
            var index = $(s.hover).index(this);
            $(this).hover(function (e) {
                e.preventDefault();
                $(s.pseudo).removeClass(s.className);
                $(s.pseudo).eq(index).addClass(s.className)
            }, function (e) {
                e.preventDefault();
                $(s.pseudo).removeClass(s.className);
            });
        });
    };
    $.fn.hoverdropdown = function (options) {
        var settings = $.extend({
            oHeight: 0, //collapsed height
            eHeight: 400, //expanded height
            timeout: 200, //animation time
            child: 'div:eq(0)'//child element to hide/show, in relation to the trigger
        }, options || {});
        return this.each(function () {
            $(this).find(settings.child).hide().css({ height: settings.oHeight + 'px' });
            $(this).hover(function (e) {
                e.preventDefault();
                $(this).find(settings.child).show().stop().animate({ height: settings.eHeight + 'px' }, settings.timeout);
            }, function (e) {
                e.preventDefault();
                $(this).find(settings.child).stop().animate({ height: settings.oHeight + 'px' }, settings.timeout, 'linear', function () { $(this).hide(); });
            });
        });
    };
    $.fn.navBuilder = function (json, options) {
        if (json == null) // if json is null 
            return this; //return selector unmolested
        var settings = $.extend({
            navList: $('#header-nav .nav .wrap'), //the element ul that has the drop down list
            buildMenu: true // if you want only to build a list, pass false to this property
        }, options || {});
        function buildList(o) {
            var ul = $('<ul>');
            for (var a = 0; a < o.sub_categories.length; a++) {
                ul.append($('<li>').append($('<a>').text(o.sub_categories[a]).attr('href', o.urls[a]).attr('onclick', o.tracks[a])));
            }
            return ul;
        }
        function buildMenu(ob) {
            var el = settings.navList;
            for (var a = 0; a < ob.length; a++) {
                $(this).append($('<li>').text(ob[a].main_category).click(function (e) {
                    var i = $(this).parent().children().index($(this));
                    e.preventDefault();
                    eval(ob[i].track);
                    location.href = ob[i].urls[0];
                }));
                if (a == 0)
                    el.html('');
                el.append($('<li>').append(buildList(ob[a])));
            }
            el.append($('<li>').addClass('cf'));
        }
        return this.each(function () {
            if (settings.buildMenu) {
                $(this).html('');
                buildMenu.call(this, json);
            } else {
                $(this).append(buildList(json));
            }
        });
    };
    $.fn.rotban = function (options) {
        var s = $.extend({
            slides: '#m-items-carousel li', //the jquery object of items
            slider: '#m-rotban-ban', //the jquery object of the container of the banners
            buttons: '#m-items-carousel li', //the jquery object of items
            fadetimeout: 2000, //use this to control length of animation
            pausetimeout: 5600, //use this to control how long between timed animations
            activeclass: 'active', //use this to control how long between timed animations
            height: 164 //height of slide
        }, options || {});
        return this.each(function () {
            var t = setTimeout(nextslide, s.pausetimeout);
            var slide = 0;
            var prevslide = 0;
            var count = $(s.slides).length;
            for (i = 0; i < count; i++) {
                $(s.buttons).append($('<a>').addClass('btn' + (i + 1)).attr('href', '#'));
            }
            displayslide(0);
            $(s.buttons + ' a').click(function (e) {
                e.preventDefault();
                displayslide($(s.buttons + ' a').index(this));
            });
            function nextslide() {
                slide = (slide + 1) % count;
                displayslide(slide);
            }
            function displayslide(number) {
                slide = number;
                var prevSelected = $(s.slides).eq(prevslide);
                var selected = $(s.slides).eq(number);
                var button = $(s.buttons + ' a').eq(number);

                $(s.buttons + ' a').removeClass(s.activeclass);
                button.addClass(s.activeclass);

                $(s.slides).not(prevSelected).css({ opacity: 0 });
                prevSelected.removeClass(s.activeclass);
                selected.addClass(s.activeclass);

                prevslide = number;
                clearTimeout(t);
                selected.stop().fadeTo('slow', 1, function () {
                    t = setTimeout(nextslide, s.pausetimeout);
                });
            }
        });
    };
    $.fn.carousel = function (options) {
        var settings = $.extend({
            slides: 1, //number of slides
            animtimeout: 1000, //use this to control length of animation
            pausetimeout: 6000, //use this to control how long between timed animations
            controls: '#carousel_controls', //the control wrapper with the appropriate control naming convention
            slider: '#slide_holder .thumbs', //the thing that is slid
            controlsbtns: '#carousel_controls #slide_buttons', //indexed buttons
            width: 567//width of slide
        }, options || {});
        return this.each(function () {
            var pos = 0;
            var t = setTimeout(nextslide, settings.pausetimeout);
            function nextslide() {
                pos = (pos + 1) % settings.slides;
                gotoslide(pos);
            }
            function gotoslide(number) {
                clearTimeout(t);
                t = setTimeout(nextslide, settings.pausetimeout + settings.animtimeout);
                $(settings.slider).stop().animate({ left: (-number * settings.width) + 'px' }, settings.animtimeout);
                $(settings.controlsbtns + ' li').eq(number).addClass('selected').siblings().removeClass('selected');
            }
            $(settings.controls + ' #next_button').click(function (e) {
                e.preventDefault();
                if (pos < settings.slides - 1) {
                    pos++;
                    gotoslide(pos);
                }
            });
            $(settings.controls + ' #prev_button').click(function (e) {
                e.preventDefault();
                if (pos > 0) {
                    pos--;
                    gotoslide(pos);
                }
            });
            $(settings.controlsbtns + ' li').click(function (e) {
                e.preventDefault();
                pos = $(settings.controlsbtns + ' li').index(this);
                gotoslide(pos);
            });
        });
    };
    $.fn.freetoplay = function (options) {
        var s = $.extend({
            url: '/popup.txt'
        }, options || {});
        function closePopup() {
            $('#screen, #freetoplay-popup').fadeOut(200, function () {
                $('#freetoplay-popup-content').html('');
            });
        }
        return this.each(function () {
            if ($('#freetoplay-popup').length == 0) {
                $('body').append('<div id="freetoplay-popup"><a href="#" id="freetoplay-popup-close"></a><div id="freetoplay-popup-content"></div></div>');
                $('#freetoplay-popup').hide();
                $('#freetoplay-popup-close').click(function (e) {
                    e.preventDefault();
                    closePopup();
                });
            }
            if ($('#screen').length == 0) {
                $('body').append('<div id="screen"></div>');
            }
            $('#screen').hide();
            $('#screen').click(function (e) {
                e.preventDefault();
                closePopup();
            });
            $(this).click(function (e) {
                e.preventDefault();
                var maxHeight = $(document).height();
                $("#freetoplay-popup-content").load(s.url, function () {
                    var popuptop = $(document).scrollTop() + 100;
                    if ($('#freetoplay-popup').height() + popuptop > maxHeight - 200) {
                        popuptop = maxHeight - 200 - $('#freetoplay-popup').height();
                    }
                    $('#freetoplay-popup').css({ top: popuptop });
                    $('#screen, #freetoplay-popup').fadeIn(200);
                    /* start ie7 only fix */
                    if ($.browser.msie && parseInt($.browser.version) < 8) {
                        $('#screen').height(maxHeight).css('position', 'absolute');
                    }
                    /* end ie7 only fix */
                });
            });
        });
    };
    $.fn.emergency = function (options) {
        var s = $.extend({
            url: '/emergency.txt'
        }, options || {});
        function closePopup() {
            $('#screen, #emergency-popup').fadeOut(200, function () {
                $('#emergency-popup-content').html('');
            });
        }
        return this.each(function () {
            if ($('#emergency-popup').length == 0) {
                $('body').append('<div id="emergency-popup"><a href="#" id="emergency-popup-close"></a><div id="emergency-popup-content"></div></div>');
                $('#emergency-popup').hide();
                $('#emergency-popup-close').click(function (e) {
                    e.preventDefault();
                    closePopup();
                });
            }
            if ($('#screen').length == 0) {
                $('body').append('<div id="screen"></div>');
            }
            $('#screen').hide();
            $('#screen').click(function (e) {
                e.preventDefault();
                closePopup();
            });
            $(this).click(function (e) {
                e.preventDefault();
                var maxHeight = $(document).height();
                $("#emergency-popup-content").load(s.url, function () {
                    var popuptop = $(document).scrollTop() + 100;
                    if ($('#emergency-popup').height() + popuptop > maxHeight - 200) {
                        popuptop = maxHeight - 200 - $('#emergency-popup').height();
                    }
                    $('#emergency-popup').css({ top: popuptop });
                    $('#screen, #emergency-popup').fadeIn(200);
                    /* start ie7 only fix */
                    if ($.browser.msie && parseInt($.browser.version) < 8) {
                        $('#screen').height(maxHeight).css('position', 'absolute');
                    }
                    /* end ie7 only fix */
                });
            });
        });
    };
    $.fn.carouselDisplay = function (options) {
        var settings = $.extend({
            slides: 4, //number of items
            animtimeout: 1000, //use this to control length of animation
            pausetimeout: 5600, //use this to control how long between timed animations
            nextbtn: '.next', //next button
            prevbtn: '.prev', //previous button
            parent: '#m-hotitems',
            slider: '.images', //the thing that is slid
            desc: true, //set to false to disable text details
            width: 76//width of slide
        }, options || {});
        return this.each(function () {
            var pos = 0;
            var ite = 0;
            var c = setTimeout(nextitem, settings.pausetimeout);
            displayitem(ite);
            function nextslide() {
                if (pos == settings.slides - 3) {
                    pos = 0;
                } else {
                    pos = Math.min(settings.slides - 3, pos + 3) % settings.slides;
                }
                gotoslide(pos);
            }
            function nextitem() {
                if (ite == settings.slides - 1) {
                    ite = 0;
                } else {
                    ite = Math.min(settings.slides - 1, ite + 1);
                }
                if (ite > pos + 2 || ite < pos) {
                    nextslide();
                }
                displayitem(ite);
            }
            function displayitem(number) {
                ite = number;
                var selected = $(settings.parent + ' ' + settings.slider + ' li').eq(number);
                var imglink = selected.find('img').attr('alt');
                var imgpath = selected.find('img').attr('src');
                var patt = new RegExp('[^/]+$', '');
                patt.compile(patt);
                imgpath = imgpath.replace(patt, imglink);
                $(settings.parent + ' .display img').attr('src', imgpath);
                $(settings.parent + ' .display a').attr('href', selected.find('a').attr('href'));
                if (settings.desc) {
                    $(settings.parent + ' .display .desc').html(selected.children('.desc').html());
                }
                selected.addClass('selected').siblings('.selected').removeClass('selected');
                clearTimeout(c);
                c = setTimeout(nextitem, settings.pausetimeout + settings.animtimeout);

            }
            function gotoslide(number) {
                clearTimeout(c);
                c = setTimeout(nextitem, settings.pausetimeout + settings.animtimeout);
                $(settings.parent + ' ' + settings.slider).stop().animate({ left: (-number * settings.width) + 'px' }, settings.animtimeout);
            }
            $(settings.parent + ' ' + settings.nextbtn).click(function (e) {
                e.preventDefault();
                pos = Math.min(settings.slides - 3, pos + 3);
                gotoslide(pos);
            });
            $(settings.parent + ' ' + settings.prevbtn).click(function (e) {
                e.preventDefault();
                pos = Math.max(0, pos - 3);
                gotoslide(pos);
            });
            $(settings.parent + ' ' + settings.slider + ' li').click(function (e) {
                e.preventDefault();
                displayitem($(settings.parent + ' ' + settings.slider + ' li').index(this));
            });
        });
    };
    $.cookie = function (name, value, options) {
        if (typeof value != 'undefined') { // name and value given, set cookie
            options = options || {};
            if (value === null) {
                value = '';
                options.expires = -1;
            }
            var expires = '';
            if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
                var date;
                if (typeof options.expires == 'number') {
                    date = new Date();
                    date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
                } else {
                    date = options.expires;
                }
                expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
            }
            // CAUTION: Needed to parenthesize options.path and options.domain
            // in the following expressions, otherwise they evaluate to undefined
            // in the packed version for some reason...
            var path = options.path ? '; path=' + (options.path) : '';
            var domain = options.domain ? '; domain=' + (options.domain) : '';
            var secure = options.secure ? '; secure' : '';
            document.cookie = [name, '=', (options.unescape == "true" ? value : encodeURIComponent(value)), expires, path, domain, secure].join('');
        } else { // only name given, get cookie
            var cookieValue = null;
            if (document.cookie && document.cookie != '') {
                var cookies = document.cookie.split(';');
                for (var i = 0; i < cookies.length; i++) {
                    var cookie = jQuery.trim(cookies[i]);
                    // Does this cookie string begin with the name we want?
                    if (cookie.substring(0, name.length + 1) == (name + '=')) {
                        cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                        break;
                    }
                }
            }
            return cookieValue;
        }
    };
    $.fn.login = function (options) { // authored by Neil
        var o = $.extend({
            loginCookieName: 'CAPassport',
            logoutSelector: '.to-logout',
            idSelector: '#tbID',
            passSelector: '#tbPass',
            rememberMeSelector: '.chx',
            submitSelector: 'input.login',
            checkbox:
            { //default is CSS controlled checkbox. if checkbox is an input, these properties should be overwritten in plugin initializer 
                isChecked: function () { return this.hasClass('checked'); },
                toggle: function () { $(this).toggleClass('checked'); }
            },
            moduleURL: '/Modules/Passport.aspx',
            moduleSelector: '.login-module',
            successCallback: function () { } //if you need to call any function after login is successful, override this
        }, options || {});
        var parent = $(this);
        var loadPath = o.moduleURL + ' ' + o.moduleSelector;
        function attachLogout() { //makes sure logout returns user to correct page from passport by setting cookie manually
            $(o.logoutSelector).click(function (e) {
                e.preventDefault();
                $.cookie("returnURL", location.href, { expires: 1, path: "/", domain: "nexon.net", unescape: "true" });
                location.href = "javascript:nexon.sso.logout();";
            });
        }
        function startUpdateSession() {
        }
        function loginLoad() {
            var id = $(o.idSelector);
            var pass = $(o.passSelector);
            var idAndPass = id.add(pass);
            var remember = $(o.rememberMeSelector);
            var otherInputs = $('input').not($(this).find('input').not('[disabled=true]'));
            var cookieName = o.loginCookieName;
            var loginCookie = $.cookie(cookieName);
            otherInputs.disabled = true;
            //these functions control the css display of id/pass inputs.
            idAndPass.attr('value', '').focus(function () {
                $(this).css('background-position', '100% 0');
            }).blur(function () {
                if ($(this).val().split(' ').join('') == '') {
                    $(this).val('').css('background-position', '0 0');
                }
            }).keydown(function (e) {
                if (e.keyCode == 13) {
                    e.preventDefault();
                    $(o.submitSelector).click();
                    return false;
                }
            });
            //check for cookie
            if (loginCookie !== null) {
                id.css('background-position', '100% 0').val(loginCookie);
                remember.click();
            }
            //attach event handler for checkbox
            remember.click(function (e) { o.checkbox.toggle.apply(this); }); //e.preventDefault(); removed for weird input handling
            //handle login submit
            $(o.submitSelector).click(function (e) {
                e.preventDefault();
                var alertStr = (pass.val().split(' ').join('') == '' ? 'Please enter your Password' :
                            (id.val().split(' ').join('') == '' ? 'Please input your ID' : ''));
                if (alertStr != '') {//make sure user has entered an ID and Password
                    alert(alertStr);
                    return false;
                }
                else {//submit info
                    $.ajax({
                        url: o.moduleURL,
                        type: 'POST',
                        data: { "tbID": id.val(), "tbPass": pass.val() }, // Passport.aspx should look for tbID and tbPass
                        datatype: 'html',
                        success: function (data) {
                            var alertData = data.split('<script type=\'text/javascript\'>');
                            if (alertData[1] !== undefined) {
                                alertData = alertData[1].split('</script>');
                                eval(alertData[0]);
                            }
                            else {
                                if (o.checkbox.isChecked.apply(remember)) {
                                    $.cookie(cookieName, id.val(), { expires: 365, path: '/', domain: 'nexon.net' });
                                }
                                else {
                                    $.cookie(cookieName, null, { path: '/', domain: 'nexon.net' });
                                }
                                parent.load(loadPath, function () {
                                    otherInputs.removeAttr('disabled');
                                    startUpdateSession();
                                    attachLogout();
                                    if ($("#forums").length > 0) {
                                        var src = $("#forum-frame").attr("src");
                                        $("#forum-frame").attr("src", src.substring(0, src.indexOf("#")));
                                    }
                                });
                                o.successCallback();
                            }
                        },
                        error: function (xhr) {
                            alert('I\'m sorry. There was an error. Please Try again later. ' + xhr.status + ' ' + xhr.statusText);
                        }
                    });
                    return false;
                }
            });
        }
        return this.each(function () {
            $.ajaxSetup({ cache: false });
            $(this).load(loadPath, function () {
                if (nexon.sso.isLoggedIn) {// loggedIn needs to be defined before plugins library is loaded
                    startUpdateSession();
                    attachLogout();
                    if ($("#forums").length > 0) {
                        var src = $("#forum-frame").attr("src");
                        $("#forum-frame").attr("src", src.substring(0, src.indexOf("#")));
                    }
                }
                else {
                    loginLoad();
                }
            });
        });
    };
    /// modified jquery.dataset v0.1.0 -- HTML5 dataset jQuery plugin
    $.fn.dataset = function (name, value) {
        var PREFIX = 'data-', PATTERN = /^data\-(.*)$/;
        if (value !== undefined) {
            // dataset(name, value): set the NAME attribute to VALUE.
            return this.attr(PREFIX + name, value);
        }
        switch (typeof name) {
            case 'string':
                // dataset(name): get the value of the NAME attribute.
                return this.attr(PREFIX + name);
            case 'object':
                // dataset(items): set the values of all (name, value) items.
                return this.each(function () {
                    for (var key in name)
                        $(this).attr(PREFIX + key, name[key]);
                });
                //                set_items.call(this, name);
            case 'undefined':
                // dataset(): return a mapping of (name, value) items for the
                // first element.
                var proc = function (index, attr, result) {
                    var match = PATTERN.exec(this.name);
                    if (match) result[match[1]] = this.value;
                };
                return this.fold((this.length > 0) && this[0].attributes, proc);
                //                return get_items.call(this);
            default:
                throw 'dataset: invalid argument ' + name;
        }
    };
    $.fn.removeDataset = function (obj) {
        var idx, length = obj && obj.length, PREFIX = 'data-';
        // For any object, remove attributes named by the keys.
        if (length === undefined) {
            for (idx in obj) {
                this.removeAttr(PREFIX + idx);
            }
        }
        // For an array, remove attributes named by the values.
        else {
            for (idx = 0; idx < length; idx++) {
                this.removeAttr(PREFIX + obj[idx]);
            }
        }
        return this;
    };
    /*
    * A left-fold operator. The behavior is the same as $.each(),
    * but the callback is called with the accumulator as the third
    * argument.  The default accumulator is an empty object.
    */
    $.fn.fold = function (object, proc, acc) {
        var length = object && object.length;
        // The default accumulator is an empty object.
        if (acc === undefined) acc = {};
        // Returning an empty accumulator when OBJECT is "false"
        // makes FOLD more composable.
        if (!object) return acc;
        // Check to see if OBJECT is an array.
        if (length !== undefined) {
            for (var i = 0, value = object[i];
	                (i < length) && (proc.call(value, i, value, acc) !== false);
	                value = object[++i])
            { }
        }
        // Object is a map of (name, value) items.
        else {
            for (var name in object) {
                if (proc.call(object[name], name, object[name], acc) === false) break;
            }
        }
        return acc;
    }
})(jQuery);
// jQuery SWFObject v1.1.1 MIT/GPL @jon_neal
// http://jquery.thewikies.com/swfobject
(function ($, flash, Plugin) {
    var OBJECT = 'object',
		ENCODE = true;
    function _compareArrayIntegers(a, b) {
        var x = (a[0] || 0) - (b[0] || 0);
        return x > 0 || (
			!x &&
			a.length > 0 &&
			_compareArrayIntegers(a.slice(1), b.slice(1))
		);
    }
    function _objectToArguments(obj) {
        if (typeof obj != OBJECT) {
            return obj;
        }
        var arr = [],
			str = '';
        for (var i in obj) {
            if (typeof obj[i] == OBJECT) {
                str = _objectToArguments(obj[i]);
            }
            else {
                str = [i, (ENCODE) ? encodeURI(obj[i]) : obj[i]].join('=');
            }
            arr.push(str);
        }
        return arr.join('&');
    }
    function _objectFromObject(obj) {
        var arr = [];
        for (var i in obj) {
            if (obj[i]) {
                arr.push([i, '="', obj[i], '"'].join(''));
            }
        }
        return arr.join(' ');
    }
    function _paramsFromObject(obj) {
        var arr = [];
        for (var i in obj) {
            arr.push([
				'<param name="', i,
				'" value="', _objectToArguments(obj[i]), '" />'
			].join(''));
        }
        return arr.join('');
    }
    try {
        var flashVersion = Plugin.description || (function () {
            return (
				new Plugin('ShockwaveFlash.ShockwaveFlash')
			).GetVariable('$version');
        } ())
    }
    catch (e) {
        flashVersion = 'Unavailable';
    }
    var flashVersionMatchVersionNumbers = flashVersion.match(/\d+/g) || [0];
    $[flash] = {
        available: flashVersionMatchVersionNumbers[0] > 0,
        activeX: Plugin && !Plugin.name,
        version: {
            original: flashVersion,
            array: flashVersionMatchVersionNumbers,
            string: flashVersionMatchVersionNumbers.join('.'),
            major: parseInt(flashVersionMatchVersionNumbers[0], 10) || 0,
            minor: parseInt(flashVersionMatchVersionNumbers[1], 10) || 0,
            release: parseInt(flashVersionMatchVersionNumbers[2], 10) || 0
        },
        hasVersion: function (version) {
            var versionArray = (/string|number/.test(typeof version))
				? version.toString().split('.')
				: (/object/.test(typeof version))
					? [version.major, version.minor]
					: version || [0, 0];
            return _compareArrayIntegers(
				flashVersionMatchVersionNumbers,
				versionArray
			);
        },
        encodeParams: true,
        expressInstall: 'expressInstall.swf',
        expressInstallIsActive: false,
        create: function (obj) {
            var instance = this;

            if (
				!obj.swf ||
				instance.expressInstallIsActive ||
				(!instance.available && !obj.hasVersionFail)
			) {
                return false;
            }
            if (!instance.hasVersion(obj.hasVersion || 1)) {
                instance.expressInstallIsActive = true;
                if (typeof obj.hasVersionFail == 'function') {
                    if (!obj.hasVersionFail.apply(obj)) {
                        return false;
                    }
                }
                obj = {
                    swf: obj.expressInstall || instance.expressInstall,
                    height: 137,
                    width: 214,
                    flashvars: {
                        MMredirectURL: location.href,
                        MMplayerType: (instance.activeX)
							? 'ActiveX' : 'PlugIn',
                        MMdoctitle: document.title.slice(0, 47) +
							' - Flash Player Installation'
                    }
                };
            }
            attrs = {
                data: obj.swf,
                type: 'application/x-shockwave-flash',
                id: obj.id || 'flash_' + Math.floor(Math.random() * 999999999),
                width: obj.width || 320,
                height: obj.height || 180,
                style: obj.style || ''
            };
            ENCODE = typeof obj.useEncode !== 'undefined' ? obj.useEncode : instance.encodeParams;
            obj.movie = obj.swf;
            obj.wmode = obj.wmode || 'opaque';
            delete obj.fallback;
            delete obj.hasVersion;
            delete obj.hasVersionFail;
            delete obj.height;
            delete obj.id;
            delete obj.swf;
            delete obj.useEncode;
            delete obj.width;
            var flashContainer = document.createElement('div');
            flashContainer.innerHTML = [
				'<object ', _objectFromObject(attrs), '>',
				_paramsFromObject(obj),
				'</object>'
			].join('');
            return flashContainer.firstChild;
        }
    };
    $.fn[flash] = function (options) {
        var $this = this.find(OBJECT).andSelf().filter(OBJECT);

        if (/string|object/.test(typeof options)) {
            this.each(
				function () {
				    var $this = $(this),
						flashObject;
				    options = (typeof options == OBJECT) ? options : {
				        swf: options
				    };
				    options.fallback = this;
				    flashObject = $[flash].create(options);
				    if (flashObject) {
				        $this.children().remove();
				        $this.html(flashObject);
				    }
				}
			);
        }
        if (typeof options == 'function') {
            $this.each(
				function () {
				    var instance = this,
					jsInteractionTimeoutMs = 'jsInteractionTimeoutMs';
				    instance[jsInteractionTimeoutMs] =
						instance[jsInteractionTimeoutMs] || 0;
				    if (instance[jsInteractionTimeoutMs] < 660) {
				        if (instance.clientWidth || instance.clientHeight) {
				            options.call(instance);
				        }
				        else {
				            setTimeout(
								function () {
								    $(instance)[flash](options);
								},
								instance[jsInteractionTimeoutMs] + 66
							);
				        }
				    }
				}
			);
        }
        return $this;
    };
} (
	jQuery,
	'flash',
	navigator.plugins['Shockwave Flash'] || window.ActiveXObject
));

