﻿// Copyright © 2008 Vertigo Software, Inc. All rights reserved.
var t = _gat._getTracker("UA-3764344-1");
t._initData();
t._trackPageview();

var MSG_SUPPORT = "Your browser or operating system may not be officially supported by Microsoft Silverlight 3. Give it a shot. It might work. If not, please visit microsoft.com/silverlight for system requirements.";
var HTM_INSTALL = "<a id=\"install\" href=\"http://go.microsoft.com/fwlink/?linkid=149156&v=3.0.40624.0\">To explore the world’s greatest music memorabilia collection in mind-boggling detail, please install Microsoft Silverlight. It only takes a second.</a>";
var HTM_UPGRADE = "<a id=\"upgrade\" href=\"http://go.microsoft.com/fwlink/?linkid=149156&v=3.0.40624.0\">The world’s greatest music memorabilia collection has been updated to run on the very latest version of the Microsoft Silverlight plug-in. Please re-install. It only takes a second.</a>";

if (!window.SLChecker) { window.SLChecker = {} };

function onBrowseCheck(e)
{
    if (!e.isVersionInstalled) {
        if (!e.isUpgradeRequired) {
            SLChecker.Cookie.Set('nosl3', '1', '7');
        }
    }
    else {
        //check for the no sl3 cookie
        if (SLChecker.Cookie.Get('nosl3')) {
            SLChecker.Cookie.Clear('nosl3');
            ReportInteractionEvent('Silverlight 3', 'Install', null, null)
        }
    }
	
	Silverlight.createObject
	(
		e.data.source,
		document.getElementById("browseParent"),
		"browse",
		{
			windowless: "true",
			width: "960",
			height: "475",
			background: "#000",
			splashScreenSource: "/Chrome/Splash.xaml",
			version: e.version,
			alt: (e.isUpgradeRequired) ? HTM_UPGRADE : HTM_INSTALL
		},
		{
			onLoad: function(sender)
			{
				if (Silverlight.IsVersionAvailableOnLoad(sender))
				{
					//if (!e.isVersionSupported)
					//	alert(MSG_SUPPORT);
					
					sender.getHost().focus();
				}
			},
			onError: function(sender, args)
			{
				if (Silverlight.IsVersionAvailableOnError(sender, args))
					Silverlight.default_error_handler(sender, args);
			}
		},
		e.data.initParams
	);
}

SLChecker.Cookie =
{
    Set: function(key, value, expDays, path, domain) {
        if (!path)
            path = '/';

        var expires = '';
        if (expDays) {
            var d = new Date();
            d.setTime(d.getTime() + (expDays * 86400000));
            expires = '; expires=' + d.toGMTString();
        }

        if (domain)
            document.cookie = key + '=' + value + expires + '; path=' + path + '; domain=' + domain;
        else
            document.cookie = key + '=' + value + expires + '; path=' + path;
    },

    Get: function(key) {   // returns the given cookie or null if not present
        var nameEQ = key + "=";
        var ca = document.cookie.split(';');
        for (var i = 0; i < ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0) == ' ') c = c.substring(1, c.length);
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
        }
        return null;
    },

    Clear: function(key) {   // clears a cookie if it exists
        // (a cookie with a date in the past is automatically deleted)
        SLChecker.Cookie.Set(key, '', -1);
    }
};

function onSplashScreenReady(sender)
{
	splashScreen = sender;
	document.getElementById("splash").className = "enabled";
	document.getElementById("about").href = "javascript:about();";
	document.getElementById("tips").href = "javascript:tips();";
	document.body.offsetLeft;
}

function about()
{
	splashScreen.ShowAbout();
}

function tips()
{
	splashScreen.ShowTips();
}

function ReportInteractionEvent(eventCategory, eventName, eventArg1, eventArg2) {
    if (t) {
        t._trackEvent(eventCategory, eventName, eventArg1, eventArg2);
    }
}