﻿
// declare sl util var
if (!window.SilverlightUtil) {
    window.SilverlightUtil = {};
}

// Silverlight util
SilverlightUtil.m_SLVersionString = null; //SilverlightUtil.getVersion();

//////////////////////////////////////////////////////////////////
// get silverlight version
//////////////////////////////////////////////////////////////////
SilverlightUtil.getVersion = function() {
    var SLVersion;
    try {
        try {
            var control = new ActiveXObject('AgControl.AgControl');
            if (control.IsVersionSupported("3.0"))
                SLVersion = 3;
            else
                if (control.IsVersionSupported("2.0"))
                SLVersion = 2;
            else
                SLVersion = 1;
            control = null;
        }
        catch (e) {
            var plugin = navigator.plugins["Silverlight Plug-In"];
            if (plugin) {
                if (plugin.description === "1.0.30226.2")
                    SLVersion = 2;
                else
                    SLVersion = parseInt(plugin.description[0]);
            }
            else
                SLVersion = 0;
        }
    }
    catch (e) {
        alert(e);
        SLVersion = 0;
    }

    // save for future ref
    SilverlightUtil.m_SLVersionString = SLVersion;

    return SLVersion;
}

// report silverlight version for tracking
// *** uses google analytics !!!
SilverlightUtil.reportVersion = function() {
    //alert('dbg');
    // if we didn't allready detect the version
    if (SilverlightUtil.m_SLVersionString == null) {
        // detect SL version
        SilverlightUtil.getVersion();
    }
    // report to ga
    var pageTracker = _gat._getTracker("UA-2964847-4");
    pageTracker._setVar('SLVersion ' + SilverlightUtil.m_SLVersionString);
}

// get html to display when silverlight/sl version not detected
SilverlightUtil.getDefaultAltHtml = function(reqVersion) {
    //<a href=\'javascript:Silverlight.getSilverlight(2.0);\'><img src=\'Images/Graphics/GetSL1.png\' alt=\'Get Microsoft Silverlight\' style=\'border-style: none\' /></a>
    // !!! Silverlight 3 hack -> because Silverlight.getSilverlight msft script supplied url goes to 2.0 instead of 3.0
    // !!! Remove when version 3 is released !!!
    if (reqVersion == 3) {
      var html = '<a href=\'http://silverlight.net/getstarted/silverlight3/default.aspx\'><img src=\'Images/Graphics/GetSL' + reqVersion + '.png\' alt=\'Get Microsoft Silverlight\' style=\'border-style: none\' />';
      return html;
    }
    // EOF hack ////////
    var html = '<a href=\'javascript:Silverlight.getSilverlight(' + reqVersion + '.0);\'><img src=\'Images/Graphics/GetSL' + reqVersion + '.png\' alt=\'Get Microsoft Silverlight\' style=\'border-style: none\' />';
    return html;
}

// global funcs
// report silverlight version for tracking
SilverlightUtil.reportVersion();

