﻿(function(_){
    // Default attributes for a new Flash file
    _.flashDefaults = {
        url: '',
        id: 'homePageMovie',
        width: '1024',
        height: '561',
        version: '9.0.0',
        upgrade: 'expressInstall.swf',
        vars: {},
        params: { wmode: 'transparent' },
        attrs: {}
    }

    // Utility function to turn the values of an object's properties into children of an array
    _.arrayify = function () {
        var array = [];
        for (i in arguments[0])
            array.push(arguments[0][i]);
        return array;
    }

    // Function to create a new Flash file based on defaults defined above.
    // Takes one object where you can redefine any of the default values by name, eg:
    // var foo = newFlash({url:'here.swf',width:'500'});
    // Will output an array which can be passed to swfobject() eg:
    // swfobject.embedSWF(foo);
    // ...UNLESS a second parameter is passed, eg: newFlash({...}, true), which will then return the object in default format.
    _.newFlash = function () {
        var object = flashDefaults;
        for (i in arguments[0])
            if (object[i] || i == 'url')
                object[i] = arguments[0][i];
        return arguments[1] ? object : arrayify(object)
    }

    // swfobject.embedSWF with newFlash array
    swfobject.embedSWF._ = function (_) {
        if (!window.swfobject) return false;
        if (arguments.length == 10) _=arguments;
        swfobject.embedSWF(_[0],_[1],_[2],_[3],_[4],_[5],_[6],_[7],_[8],_[9]);
    }
}(window))
