/**
 *  jQuery Plugin for use with Microsoft Silverlight
 *  Tested with Silverlight 1.0 beta
 *  @author:  M. Alsup (malsup at gmail dot com)
 *  @version: 1.0 (5/04/2007)
 *  Documentation and examples at: http://www.malsup.com/jquery/ag/
 *  Free beer and free speech. Enjoy!
 *
 *  VERSIONE MODIFICATA PER COMPATIBILITA' CON SILVERLIGHT 1.0
 * 
 */
(function($) {

if (!window.Silverlight) {
    alert('You must include the Silverlight.js script.');
    return;
}

$.fn.silverlight = function(opts) {
    return this.each(function() {
        var o = jQuery.extend({}, $.fn.silverlight.defaults, opts);
        
        // try to use metadata plugin
        if ($.meta) jQuery.extend(o, $(this).data());

        // make sure activex object gets a unique id
        var id = o.id || (this.id ? this.id + 'AG' : 'AG' + $.fn.silverlight.counter++);
        var props = {
            width: o.width,
            height: o.height,
            inplaceInstallPrompt: o.installPrompt,
            background: o.bg,
            isWindowless: o.windowless,
            framerate: o.framerate,
            version: o.version
        };
        var events = {
            onError: o.error,
            onLoad: o.load
        };

        Silverlight.createObjectEx({
            source: o.xaml,
            parentElement: this,
            id: id,
            properties: props,
            events: events,
            initParams: o.params,
            userContext: o.context
        });
    });
};

// @see http://msdn2.microsoft.com/en-us/library/bb190632.aspx
$.fn.silverlight.defaults = {
    width:         '300',       // width of component in px
    height:        '300',       // height of component in px
    bg:            '#00000000', // background color (default is transparent)
    installPrompt: 'true',      // display in-place install prompt?
    windowless:    'true',      // windowless mode (false for wrapping markup)
    framerate:     '24',        // maximum framerate
    version:       '1.0',       // Silverlight version
    error:         null,        // onError callback
    load:          null,        // onLoad callback
    params:        null,        // object init params
    context:       null         // callback arg passed to the load callback
};

$.fn.silverlight.counter = 0;

})(jQuery);

