﻿// silverlight.js 1.0.0

if (typeof YAHOO == "undefined" || !YAHOO) {
	var YAHOO = {};
}

YAHOO.namespace = function() {
	var a=arguments, o=null, i, j, d;
	for (i=0; i<a.length; i=i+1) {
		d=a[i].split(".");
		o=YAHOO;
		// YAHOO is implied, so it is ignored if it is included
		for (j=(d[0] == "YAHOO") ? 1 : 0; j<d.length; j=j+1) {
			o[d[j]]=o[d[j]] || {};
			o=o[d[j]];
		}
	}
	return o;
};

YAHOO.namespace("JP.env");

YAHOO.JP.env.silverlight = {
	isInstalled : function() {},
	getVersion : function() {},
	isInstallable : function(version) {},
	_lowerVersionCheck : function(version) {}
};

YAHOO.JP.env.silverlight.isInstalled = function() {
	var control = null;
	var pluginInstalled = false;
	if (window.navigator.userAgent.indexOf('MSIE') >= 0){
		try {
			control = new ActiveXObject('AgControl.AgControl');
		}
		catch(e) {
			pluginInstalled = false;
		}
		if(control) {
			pluginInstalled = true;
		}
	} else {
		if (navigator.plugins["Silverlight Plug-In"]){
			pluginInstalled = true;
		} else {
			pluginInstalled = false;
		}
	}
	if(pluginInstalled == true) {
		return true;
	} else {
		return false;
	}
};

YAHOO.JP.env.silverlight.getVersion = function() {
	var version = null;
	var oSL = null;
	var i = 0;
	var j = 0;
	var k = 0;
	if (!this.isInstalled()) {
		return version;
	}
	if (window.navigator.userAgent.indexOf('MSIE') >= 0){
		try {
			oSL = new ActiveXObject("AgControl.AgControl");
			version = 0;
		} catch(e) {
			return version;
		}
		while(++i) {
			j = i + ".0";
			if (oSL.IsVersionSupported(j)) {
				version = j;
			} else {
				break;
			}
		}
		i = 0;
		j = parseFloat(version);
		while(++i) {
			k = j + "." + i;
			if (i == 10) {
				k = j + 1 + ".0";
			}
			if (oSL.IsVersionSupported(k)) {
				version = k;
			} else {
				return parseFloat(version);
			}
		}
	} else {
		oSL = navigator.plugins["Silverlight Plug-In"];
		version = parseFloat(/\d+\.\d+/.exec(oSL.description)[0]);
		return version;
	}
};

YAHOO.JP.env.silverlight.isInstallable = function(version) {
	if (Silverlight.supportedUserAgent(version) && this._lowerVersionCheck(version)) {
		return true;
	} else {
		return false;
	}
};

YAHOO.JP.env.silverlight._lowerVersionCheck = function(version) {
	var ua = window.navigator.userAgent;
	if (ua.indexOf('Win') != -1) {
		if (ua.indexOf('NT 4.0') != -1) {
			return false;
		}
		if (ua.indexOf('NT 5.0') != -1 && ua.indexOf('MSIE 6') == -1) {
			return false;
		}
		if (
			ua.indexOf('NT 5.1') != -1 &&
			ua.indexOf('MSIE') != -1 &&
			ua.indexOf('SV1') == -1 && 
			ua.indexOf('IEMB3') == -1 &&
			ua.indexOf('MSIE 7') == -1 &&
			ua.indexOf('MSIE 8') == -1
		) {
			return false;
		}
	}
	if (ua.indexOf('Mac') != -1) {
		try {
			var aRegex = ua.match(/Mac OS X ([0-9_]+);/);
			if (aRegex) {
				var aVersions = aRegex[1].split("_");
				if (aVersions[1] < 4) {
					return false;
				}
				if (aVersions[1] == 4 && aVersions[2] < 8) {
					return false;
				}
			}
		} catch(e) {
		}
		try {
			if (ua.indexOf('KHTML') != -1) {
				var xLBtmp  = ua.split("/");
				var xLBtmpc = xLBtmp[2].split(" ");
				var safariVer = parseFloat(xLBtmpc[0]);
				if ((version < 3 && safariVer < 412)
					|| (version >= 3 && safariVer < 520)) {
					return false;
				}
			}
		} catch(e) {
		}
	}
	return true;
};

///////////////////////////////////////////////////////////////////////////////
//
//  Silverlight.supportedUserAgent.js   	version 2.0.40211.0
//
//  This file is provided by Microsoft as a helper file for websites that
//  incorporate Silverlight Objects. This file is provided under the Microsoft
//  Public License available at 
//  http://code.msdn.microsoft.com/SLsupportedUA/Project/License.aspx.  
//  You may not use or distribute this file or the code in this file except as 
//  expressly permitted under that license.
// 
//  Copyright (c) Microsoft Corporation. All rights reserved.
//
///////////////////////////////////////////////////////////////////////////////

if (!window.Silverlight)
{
	window.Silverlight = { };
}

Silverlight.supportedUserAgent = function(version, userAgent) {
	try {
		var ua = null;

		if (userAgent) {
			ua = userAgent;
		}
		else {
			ua = window.navigator.userAgent;
		}

		var slua = { OS: 'Unsupported', Browser: 'Unsupported' };

		//Silverlight does not support pre-Windows NT platforms
		if (ua.indexOf('Windows NT') >= 0 || ua.indexOf('Mozilla/4.0 (compatible; MSIE 6.0)') >= 0) {
			slua.OS = 'Windows';
		}
		else if (ua.indexOf('PPC Mac OS X') >= 0) {
			slua.OS = 'MacPPC';
		}
		else if (ua.indexOf('Intel Mac OS X') >= 0) {
			slua.OS = 'MacIntel';
		}
		else if (ua.indexOf('Linux') >= 0) {
			slua.OS = 'Linux';
		}

		if (slua.OS != 'Unsupported') {
			if (ua.indexOf('MSIE') >= 0) {
				if (navigator.userAgent.indexOf('Win64') == -1) {
					if (parseInt(ua.split('MSIE')[1]) >= 6) {
						slua.Browser = 'MSIE';
					}
				}
			}
			else if (ua.indexOf('Firefox') >= 0) {
				var versionArr = ua.split('Firefox/')[1].split('.');
				var major = parseInt(versionArr[0]);
				if (major >= 2) {
					slua.Browser = 'Firefox';
				}
				else {
					var minor = parseInt(versionArr[1]);
					if ((major == 1) && (minor >= 5) && version < 3) {		// modified for ver3.0
						slua.Browser = 'Firefox';
					}
				}
			}

			else if (ua.indexOf('Safari') >= 0) {
				slua.Browser = 'Safari';
			}
		}

		//detect all unsupported platform combinations (IE on Mac, Safari on Win)
		var supUA = (!(slua.OS == 'Unsupported' ||							 //Unsupported OS
							slua.Browser == 'Unsupported' ||						//Unsupported Browser
							(slua.OS == 'Windows' && slua.Browser == 'Safari') ||   //Safari is not supported on Windows
							(slua.OS.indexOf('Mac') >= 0 && slua.Browser == 'MSIE')   //IE is not supported on Mac
								));

		if (version >= 2) {		// modified for ver3.0
			//add PPC and Linux to unsupported list
			return ((supUA && (slua.OS != 'MacPPC' && slua.OS != 'Linux')));
		}
		else if (version == '1.0') {
			//add win2k to unsupported list
			return (supUA && (ua.indexOf('Windows NT 5.0') < 0));
		}
		else {
			return (supUA);
		}
	}
	catch (e) {
		return false;
	}
};

var ver = 2.0; //最新バージョン

