//
//	Version 2.6
//	
//	History
//	1.0 	Initial version
//	1.1		Added Macintosh browser check
//  1.2 	Fixed Macintosh IE 5.x detection, added version detection for PC IE
//  2.0		Added IE and Netscape 4 Flash version detection
//  2.1		Functions added: generateBasicFlashObject, generateBasicNoFlashPage
//  2.2 	Fixed Opera browser compatibility problem
//  2.3		Streamlined browser detection
//  2.4		Added Nokia 770 detection
//	2.5		Fixed logical bug
//	2.6		New detection for Nokia devices
//
var flash2Installed = false; 
var flash3Installed = false;   
var flash4Installed = false;    
var flash5Installed = false;  
var flash6Installed = false;   
var flash7Installed = false;   
var flash8Installed = false;    
var flash9Installed = false; 
var maxver = 9;

function checkBrowser() {
	this.agent=navigator.userAgent;
	this.msie = this.agent.indexOf("MSIE")>-1&&this.agent.indexOf("Opera")==-1;
	this.macmsie = this.agent.indexOf("MSIE")>-1&&this.agent.indexOf("Mac")>-1;
	this.firefox = this.agent.indexOf("Mozilla/5.0")>-1&&this.agent.indexOf("Firefox")>-1&&this.agent.indexOf("Netscape")==-1;
	this.mozilla = this.agent.indexOf("Mozilla/5.0")>-1&&this.agent.indexOf("Firefox")==-1&&this.agent.indexOf("Netscape")==-1;
	this.safari = this.agent.indexOf("Safari")>-1&&this.agent.indexOf("Mac")>-1;
	this.netscape4 = document.layers;
	this.netscape = this.agent.indexOf("Mozilla/5.0")>-1&&this.agent.indexOf("Firefox")==-1&&this.agent.indexOf("Netscape")>-1;
	this.operaie = this.agent.indexOf("MSIE")>-1&&this.agent.indexOf("Opera")>-1;
	this.opera = this.agent.indexOf("MSIE")==-1&&this.agent.indexOf("Opera")>-1;
	this.operasym = this.agent.indexOf("Symbian")>-1&&this.agent.indexOf("Opera")>-1;
	this.n770 = this.agent.indexOf("N770/SU-18")>-1;
	//this.series40 = this.agent.indexOf("Series40")>-1;
	this.series60 = this.agent.indexOf("Series60")>-1;
	this.nokiaphone = this.agent.indexOf("Nokia")>-1;
	return this;
}

var br = checkBrowser();

function flashDetectHTML(flashHTML,noFlashHTML,required_version) {
	required_version = parseInt(required_version);
	//alert(br.agent);
		if (br.n770) {
			document.write(noFlashHTML);
		} else if (br.opera || br.operaie || br.mozilla || br.netscape || br.safari || br.firefox || br.macmsie) {	
		//
		//	Detection for Mac Internet Explorer, Safari, Opera (7.x, 8.x) and Gecko (Mozilla, FF, Netscape 6.x, 7.x) based browsers.
		//	Detects also version of Flash player and compares value to "required_version" variable.
		//
			if (navigator.plugins['Shockwave Flash']) {
				var description = navigator.plugins['Shockwave Flash'].description;
				var description_array = description.split(" ");
				var version_array = description_array[2].split(".");
				if (version_array[0]<required_version) {
					document.write(noFlashHTML);
				} else {
					document.write(flashHTML);
				}
			} else {
				document.write(noFlashHTML);
			}
		} else if (br.msie) {
		//
		//	Detection for Microsoft Internet Explorer 5.x and 6.x PC browsers.
		//	Does not detect flash version, just checks if plugin exists.
		//
		  var ie_true = false;
		  document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
		  document.write('on error resume next \n');
		  document.write('flash2Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))) \n');
		  document.write('flash3Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3"))) \n');
		  document.write('flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');
		  document.write('flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');  
		  document.write('flash6Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');  
		  document.write('flash7Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.7"))) \n');
		  document.write('flash8Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.8"))) \n');
		  document.write('flash9Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.9"))) \n');
		  document.write('<\/SCR' + 'IPT\> \n'); // break up end tag so it doesn't end our script

		  for (var i=2;i<=maxver;i++) {
		  		if (i==required_version) {
					if (eval("flash" + i + "Installed") == true) {
						ie_true = true;
					}
				}
		  }

		  if (!ie_true) {
			document.write(noFlashHTML);
		  } else {
			document.write(flashHTML);
		  }
				
		} else if (br.netscape4) {
		//
		//	Detection for old Netscape 4.x browsers. 
		//
			ns_flash = false;
			for (var i=0;i<=navigator.plugins.length;i++) {
				var plugin = navigator.plugins[i];
				if (plugin.name=="Shockwave Flash") {
					ns_flash = true;
					var description = plugin.description;
					var description_array = description.split(" ");
					var version_array = description_array[2].split(".");
					if (version_array[0]>=required_version) {
						document.write(flashHTML);
					} else {
						document.write(noFlashHTML);
					}
				}
			}
			if (!ns_flash) {
				document.write(noFlashHTML);
			}
		} else if (br.nokiaphone) {
			window.location = "http://www.nokia.com/global/mobile";
			//document.write(noFlashHTML);
		} else if (br.operasym || br.series60) {
			window.location = "http://www.nokia.com/global/mobile";
			
		} else {
			document.write(noFlashHTML);
		}
}

// Generates object and embed tags needed
function generateBasicFlashObject(flash_file, flash_width, flash_height, flash_params_obj, flash_params_emb) {

	var flash_HTML;

	flash_HTML = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="'+flash_width+'" height="'+flash_height+'" id="index" align="middle">';
	flash_HTML += '<param name="allowScriptAccess" value="sameDomain" />';
	flash_HTML += '<param name="movie" value="'+flash_file+'" />';
	if(flash_params_obj) { flash_HTML += flash_params_obj; }
	flash_HTML += '<param name="quality" value="high" />';
	flash_HTML += '<param name="bgcolor" value="#ffffff" />';
	flash_HTML += '<embed src="'+flash_file+'" ';
	if(flash_params_emb) { flash_HTML += flash_params_emb; }
	flash_HTML += ' quality="high" bgcolor="#ffffff" width="'+flash_width+'" height="'+flash_height+'" name="index" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	flash_HTML += '</object>';   

	return flash_HTML;

}

// Generates download link to flash plug-in
function generateBasicNoFlashPage() {
	
	var noFlash_HTML;
	
	noFlash_HTML = '<table bgcolor="#ffffff" cellpadding="0" cellspacing="0" border="0"><tr>';
	noFlash_HTML += '<td valign="top" valign="top">';
	noFlash_HTML += '<img src="/pics/1x1trans.gif" width="1" height="50" /><br />';
	noFlash_HTML += '<a href="http://www.nokia.com/"><img src="http://www.nokia.com/pics/logo_nokia.gif" width="135" height="50" alt="" border="0"></a><br>';
	noFlash_HTML += '<img src="/pics/1x1trans.gif" width="1" height="15" /><br />';
	noFlash_HTML += '<table bgcolor="#ffffff" cellpadding="0" cellspacing="0" border="0"><tr><td><p>In order to view the Flash content, you need to have Macromedia Flash Player installed on your computer. You can  <a href="http://www.macromedia.com/go/getflashplayer/" target="_blank">download the latest Flash Player for free</a> from Macromedia\'s website.<br><br>';
	noFlash_HTML += '<a href="http://www.macromedia.com/go/getflashplayer/" target="_blank"><img src="http://www.nokia.com/NOKIA_COM_1/Common_Items/flashplayer_88x31.gif" width="88" height="31" border="0" hspace="7" vspace="7" title="Download Flash Player for free" alt="Download Flash Player for free" /></a>';
	noFlash_HTML += '</td></tr></table>';
	noFlash_HTML += '</td></tr></table>';

	return noFlash_HTML;

}

