window.onload = register;
window.onresize = register;
var estate = 0;

var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

var isFlash = DetectFlashVer(8, 0, 0);

var fp_images = new Array();
var fp_hide;
var pos_hover = false;

function register(e)
{
	if (estate != 0) return false;
	estate = 1;
	if (!e) e = window.event;
	if (e.type == "resize" || e.type == "load") {
		var wh;
		if (window.innerHeight) {
			wh = window.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) {
			wh = document.documentElement.clientHeight;
		} else if (document.body && document.body.clientHeight) {
			wh = document.body.clientHeight;
		}

		var dw = document.getElementById("wrapper");
		var dm = document.getElementById("main");
		var df = document.getElementById("footer");

		var dwh = dw.clientHeight;
		var dmh = dm.clientHeight;
		var dfh = df.clientHeight + 3;
		
		if ((dwh + dfh) < wh) {
			var mt = Math.round((wh - dwh - dfh)/2);
			if (navigator.appName == "Microsoft Internet Explorer") mt -= 15;
			
			dm.style.marginTop = mt+"px";
			dm.style.marginBottom = mt+"px";
		} else {
			dm.style.maringTop = "0px";
			dm.style.marginBottom = "0px";
		}
	}
}
function RunFoo(f, w, h)
{
    document.write('<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="'+w+'" height="'+h+'">\n');
    document.write('<param name="allowScriptAccess" value="sameDomain" />\n');
	document.write('<param name="movie" value="images/'+f+'.swf" />\n');
	document.write('<param name="quality" value="best" />\n');
	document.write('<param name="wmode" value="transparent" />\n');
	document.write('<param name="bgcolor" value="#0E2152" />\n');
	document.write('<embed src="images/'+f+'.swf" quality="best" wmode="transparent" bgcolor="#0E2152" width="'+w+'" height="'+h+'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />\n');
    document.write('</object>\n');
}

function noFlash(f) {
	if (f == 'tagline') {
		document.write('<div><img src="images/tagline.gif" alt="Mylad Orthopedic Solutions&trade; &ndash; Stronger . Faster . Better" title="Mylad Orthopedic Solutions&trade; &ndash; Stronger . Faster . Better" /></div>');
	} else if (f == 'olecranail_intro') {
		document.write('<div><img src="images/olecranail_head.gif" alt="OlecraNail&trade; Intramedullary Fixation System" title="OlecraNail&trade; Intramedullary Fixation System" usemap="#techvideo" /></div>');
		document.write('<div id="nsintro">');
		document.write('<img src="images/olecranail_photo.jpg" alt="OlecraNail&trade; Intramedullary Fixation System" title="OlecraNail&trade; Intramedullary Fixation System" style="float:left" />');
		document.write('<div id="prod_spec">');
		document.write('<p><b>OlecraNail™</b> solves the problems with <b>proximal ulnar fractures:</b></p>');
		document.write('<ul class="specs">');
		document.write('<li>Minimally invasive, simple implantation</li>');
		document.write('<li>No soft tissue irritation</li>');
		document.write('<li>No removal necessary</li>');
		document.write('<li>Rigid fixation in all planes allowing early motion</li>');
		document.write('<li>Adjustable compression at the fracture site</li>');
		document.write('<li>Indicated for all fracture types and patterns</li>');
		document.write('</ul>');
		document.write('</div>');
		document.write('</div>');
		document.write('<map name="techvideo">');
		document.write('<area coords="615 0 761 30" href="olecranail-technique.html" title="Watch OlecraNail&trade; Technique Video" alt="Watch OlecraNail&trade; Technique Video" />');
		document.write('</map>');
	} else if (f == 'olecranail-indications') {
		document.write('<div>');
		document.write('<img src="images/olecranail-indications-header.gif" alt="Olecranail&trade; Indications" title="Olecranail&trade; Indications" />');
		document.write('</div>');
		document.write('<img src="images/olecranail-indications.gif" alt="Olecranail&trade; Indications" title="Olecranail&trade; Indications" />');
	} else if (f.indexOf('olecranail-features') == 0) {
		document.write('<img src="images/'+f+'.gif" alt="OlecraNail&trade; Features" title="OlecraNail&trade; Features" />');
	} else if (f == 'tech-video') {
		document.write('<div id="tech" style="border:2px solid #FFFFCC; padding:20px; text-align:center">');
		document.write('<p>Flash Player 8 or higher must be installed on your computer to view<br />OlecraNail™ Technique Video.</p>');
		document.write('Flash Player is available free to download from <a href="http://www.adobe.com/go/getflashplayer" target="blank">adobe website</a>.');
		document.write('</div>');
	}
}

// Flash Player Version Detection - Rev 1.6
// Detect Client Browser type
// Copyright(c) 2005-2006 Adobe Macromedia Software, LLC. All rights reserved.

function ControlVersion()
{
	var version;
	var axo;
	var e;

	// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry

	try {
		// version will be set for 7.X or greater players
		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version = axo.GetVariable("$version");
	} catch (e) {
	}

	if (!version)
	{
		try {
			// version will be set for 6.X players only
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
			
			// installed player is some revision of 6.0
			// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
			// so we have to be careful. 
			
			// default to the first public version
			version = "WIN 6,0,21,0";

			// throws if AllowScripAccess does not exist (introduced in 6.0r47)		
			axo.AllowScriptAccess = "always";

			// safe to call for 6.0r47 or greater
			version = axo.GetVariable("$version");

		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 4.X or 5.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = axo.GetVariable("$version");
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 3.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = "WIN 3,0,18,0";
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 2.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = "WIN 2,0,0,11";
		} catch (e) {
			version = -1;
		}
	}
	
	return version;
}

// JavaScript helper required to detect Flash Player PlugIn version information
function GetSwfVer(){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	var flashVer = -1;
	
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			var descArray = flashDescription.split(" ");
			var tempArrayMajor = descArray[2].split(".");			
			var versionMajor = tempArrayMajor[0];
			var versionMinor = tempArrayMajor[1];
			var versionRevision = descArray[3];
			if (versionRevision == "") {
				versionRevision = descArray[4];
			}
			if (versionRevision[0] == "d") {
				versionRevision = versionRevision.substring(1);
			} else if (versionRevision[0] == "r") {
				versionRevision = versionRevision.substring(1);
				if (versionRevision.indexOf("d") > 0) {
					versionRevision = versionRevision.substring(0, versionRevision.indexOf("d"));
				}
			}
			var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	else if ( isIE && isWin && !isOpera ) {
		flashVer = ControlVersion();
	}	
	return flashVer;
}

// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
{
	versionStr = GetSwfVer();
	if (versionStr == -1 ) {
		return false;
	} else if (versionStr != 0) {
		if(isIE && isWin && !isOpera) {
			// Given "WIN 2,0,0,11"
			tempArray         = versionStr.split(" "); 	// ["WIN", "2,0,0,11"]
			tempString        = tempArray[1];			// "2,0,0,11"
			versionArray      = tempString.split(",");	// ['2', '0', '0', '11']
		} else {
			versionArray      = versionStr.split(".");
		}
		var versionMajor      = versionArray[0];
		var versionMinor      = versionArray[1];
		var versionRevision   = versionArray[2];

        	// is the major.revision >= requested major.revision AND the minor version >= requested minor
		if (versionMajor > parseFloat(reqMajorVer)) {
			return true;
		} else if (versionMajor == parseFloat(reqMajorVer)) {
			if (versionMinor > parseFloat(reqMinorVer))
				return true;
			else if (versionMinor == parseFloat(reqMinorVer)) {
				if (versionRevision >= parseFloat(reqRevision))
					return true;
			}
		}
		return false;
	}
}

function loadFracturesImages()
{
	var img1 = new Image();
	var img2 = new Image();
	var img3 = new Image();
	var img4 = new Image();
	
	img1.src = "images/pattern1.jpg";
	img2.src = "images/pattern2.jpg";
	img3.src = "images/pattern3.jpg";
	img4.src = "images/pattern4.jpg";
	
	fp_images[0] = img1;
	fp_images[1] = img2;
	fp_images[2] = img3;
	fp_images[3] = img4;
}

function showPattern(n)
{
	var id = parseInt(n);
	
	if (isNaN(id)) return false;
	pos_hover = true;
	
	var thediv = document.getElementById("indications");
	var theimg = fp_images[(id-1)];
	
	thediv.innerHTML = '<img src="'+theimg.src+'" alt="Fracture Pattern" />';
}

function hidePattern()
{
	pos_hover = false;
	fp_hide = setInterval(remove_pattern_img, 1000);
}

function remove_pattern_img()
{
	window.clearInterval(fp_hide);
	var thediv = document.getElementById("indications");
	var html = "";

	if (pos_hover == false) {
		if (isFlash) {
			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="400" height="230">\n';
			html += '<param name="allowScriptAccess" value="sameDomain" />\n';
			html += '<param name="movie" value="images/olecranail-indications.swf" />\n';
			html += '<param name="quality" value="best" />\n';
			html += '<param name="wmode" value="transparent" />\n';
			html += '<param name="bgcolor" value="#0E2152" />\n';
			html += '<embed src="images/olecranail-indications.swf" quality="best" wmode="transparent" bgcolor="#0E2152" width="400" height="230" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />\n';
			html += '</object>\n';
		} else {
			html += '<div>';
			html += '<img src="images/olecranail-indications-header.gif" alt="Olecranail&trade; Indications" title="Olecranail&trade; Indications" />';
			html += '</div>';
			html += '<img src="images/olecranail-indications.gif" alt="Olecranail&trade; Indications" title="Olecranail&trade; Indications" />';
		}
		thediv.innerHTML = html;
		pos_hover = true;
	}
}
