// shared.js
// Misc support functions for the Madison Radiologists website

//=====================================================================================
// Start picture popup support

function openWindow(w, h, url) {
	// This member pops up a new window with the specified size and name
	var t = 0;
	var l = 0;
	// Adjust height and top position
	if (w > screen.width) {
		w = screen.width;
	} else {
		l = (screen.width - w) / 2;
	}
	// Adjust width and left position
	if (h > (screen.height - 80)) {
		h = screen.height - 80;
	} else {
		t = ((screen.height - 80) - h) / 2;
	}
	// Enable scroll bars and window resizing
	var scr = ((l == 0) || (t == 0))? 'yes': 'no';
	var rsz = ((l == 0) || (t == 0))? 'yes': 'no';
	// Show the window
	var win = window.open(url, null, 'toolbar=no,location=no,directories=no,status=no,scrollbars=' + scr + ',resizable=' + rsz + ',copyhistory=no,menubar=no,width=' + w + ',height=' + h + ',top=' + t + ',left=' + l);
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function openPicWindow(picw, pich, filename) {
	// Note that the width and height provided are the image size, not the desired window size
	openWindow(picw + 36, pich + 36, "Images/ContentPics/" + filename);
}

// End picture popup support
//=====================================================================================

//=====================================================================================
// Start background support

function useBackgroundImage(sBackFile)
{
	// Note that this code assumes that the browser can correctly render the background, and
	// we disable only the browsers known to have a problem. (Assume it works until we prove
	// otherwise).
	//
	// Also note that this must be called with the html head tags and not from other places in
	// the html page.
	
	var bBackEnabled = true;
	
	// Netscape 4.7 tables inherit the background graphic from the containing table cell instead
	// of applying a transparent effect. This is believed to work correctly with version 5 and newer.
	if (navigator.appName == 'Netscape' ) {
		bBackEnabled = (parseInt(navigator.appVersion) > 4)? true: false;
	}
	
	if (bBackEnabled && (sBackFile != '')) {
		// Insert a new style which replaces the plain white background one.
		document.write('<style type="text/css"> <!-- ');
		document.write('TD.background { background: url(Images/Backgrounds/' + sBackFile + ') no-repeat right top; background-color: white; } ');
		document.write("--></style>");
	}
}

// End background rendering
//=====================================================================================

//=====================================================================================
// Start flash support

// Detect compatible flash player
var minFlashVersion = 4;	// Macromedia v4 appears to play our v5 files
var canPlayFlash = false;	// Assume we can't play flash

if (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"] && navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin) {
	// Netscape and other modern browsers, find the installed plugin and
	// compare the version
	var words = navigator.plugins["Shockwave Flash"].description.split(" ");
	for (var i = 0; i < words.length; ++i)
	{
		if (isNaN(parseInt(words[i]))) continue;
		var playerVersion = words[i]; 
	}
	canPlayFlash = playerVersion >= minFlashVersion;
} else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE") >= 0) {
	var canDetectPlugin = false;
	if (navigator.appVersion.indexOf("Win") != -1) {
		// All IE Windows versions support plugin detection (before IE4, client-side scripting was
		// not supported, so it will fall through to the noscript tag)
		canDetectPlugin = true;
	} else if (navigator.appVersion.indexOf("Mac") != -1) {
		// MacIntosh version 4.5 is a special problem in that it does not support browser
		// detection, but version 5 and later does
		if (parseInt(navigator.appVersion) > 4) {
			canDetectPlugin = true;
		}
	}
	if (canDetectPlugin) {
		// We test version by instanciating ActiveX object
		// Hide this from IE4.5 Mac by splitting the tag
		document.write('<scr' + 'ipt language=vbscript\> \n');
		document.write('on error resume next \n');
		document.write('canPlayFlash = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & minFlashVersion)))\n');
		document.write('</scr' + 'ipt\> \n');
	}
}

function playFlash5(sFlashFile, sNoFlashFile, w, h)
{
	// Show flash presentation if we have a compatible flash player installed
	if (canPlayFlash) {
		document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab" width="' + w + '" height="' + h + '"><param name="movie" value="Media/' + sFlashFile + '"><param name="quality" value="high"><param name="Loop" value="true"><param name="play" value="true"><param name="menu" value="false">');
		document.write('<embed src="Media/' + sFlashFile + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + w + '" height="' + h + '"></embed>');
		document.write('<noembed><img border="0" width="' + w + 'px" height="' + h + 'px" src="Media/' + sNoFlashFile + '"></noembed>');
		document.write('</object>');
	} else{
		document.write('<img border="0" width="' + w + 'px" height="' + h + 'px" src="Media/' + sNoFlashFile + '">')
	}
}

// End flash support
//=====================================================================================

//=====================================================================================
// Start browser specific styles

function insertSpecialCSS()
{
	var mac = navigator.appVersion.indexOf("Mac") > -1;
	var opera = navigator.userAgent.indexOf("Opera") > -1;
	
	if (navigator.appName == "Netscape" && parseFloat(navigator.appVersion) < 5.00 && !mac) {
		document.write ('<link rel="stylesheet" href="SharedNS5.css" type="text/css">');
	} else {
	   	document.write ('<link rel="stylesheet" href="SharedIE5.css" type="text/css">');
    }
}

insertSpecialCSS(); // Run it now

// End browser specific styles
//=====================================================================================
