//version 3-26-2008 1:27 pm
var FOOTER_HEIGHT = 46;
var HEADER_HEIGHT = 31;

function openWin(isbn, buyURL, serviceURL)
{
	var bookText = BookViewerText("single", isbn, null, null, null, null, buyURL, serviceURL);
	var varString = "height=700,width=610,resizable=1,status=0";
	var OpenWindow=window.open("", "_blank", varString);
	OpenWindow.document.write("<HTML>");
	OpenWindow.document.write("<TITLE>Insight Book Preview</TITLE>");
	OpenWindow.document.write("<BODY BGCOLOR='ffffff' leftmargin='0' rightmargin='0' bottommargin='0' topmargin='0' onLoad='document.Insight.focus()'>");
	OpenWindow.document.write("<CENTER>");
	OpenWindow.document.write(bookText);
	OpenWindow.document.write("</CENTER>");
	OpenWindow.document.write("</BODY>");
	OpenWindow.document.write("</HTML>");
}

function InsightBookReader(mode, isbn, title, author, startingPage, configUrl, buyUrl, serviceUrl, extraSwfArgs){
	
	flashInst = getFlashVersion();
	  if(flashInst >= 9){
		var myOutput = BookViewerText(mode, isbn, title, author, startingPage, configUrl, buyUrl, serviceUrl, extraSwfArgs);
		document.write(myOutput);
	  }else{
	    document.write('<div id="insight_noflash" style="text-align: center; font-family: verdana,arial; font-size: 9px;">');
	    if(mode != "audio") {
	       document.write('<a href="http://www.adobe.com/go/getflashplayer" target="_blank"><img src="http://www.randomhouse.com/images/dyn/cover/?source=' + isbn + '&height=225&maxwidth=175"/></a><br/><br/>');
	    }
	    document.write('To browse and search this book, please upgrade to the latest version of the free <a href="http://www.adobe.com/go/getflashplayer" target="_blank">Adobe Flash Player</a>.</div>')
	  }
}

function BookViewerText(mode, isbn, title, author, startingPage, configUrl, buyUrl, serviceUrl, extraSwfArgs)
{
	var isbnString = (isbn)?"&ISBN=" + isbn : "";
	var titleString = (title)?"&title=" + title : "";
	var authorString = (author)?"&author=" + author : "";
	var modeString = (mode)?"&mode=" + mode: "";
	var startPageString = (startingPage)?"&StartingPage=" + startingPage: "";
	var configUrlString = (configUrl)?"&configurationUrl=" + configUrl : "";
	var buyUrlString = (buyUrl)?"&buyUrl=" + buyUrl: "";
	var serviceUrlString = (serviceUrl)?"&serviceUrl="+serviceUrl: "";
	var flashVarParams = isbnString + titleString + authorString + modeString + startPageString + configUrlString + buyUrlString + serviceUrlString;
	
	var width = 0;
	var height = 0;
	if(mode=="preview"){
		height = 335;
		width = 195;
		var swfLocation = "http://insight.randomhouse.com/widget/InsightV2.swf"; // added by djn
	}
	else if(mode=="audio"){ // added by djn
		height = 60; // added by djn
		width = 195; // added by djn
		var swfLocation = "http://www.randomhouse.com/widget/InsightAudio.swf"; // added by djn
	} // added by djn
	else if(mode=="audiopreview"){ // added by djn
		height = 335; // added by djn
		width = 195; // added by djn
		var swfLocation = "http://www.randomhouse.com/widget/InsightAudio.swf"; // added by djn
	} // added by djn
	else{ //mode is single
		width = 610;
		height = 700;
		var swfLocation = "http://insight.randomhouse.com/widget/InsightV2.swf"; // added by djn
	}
	flashVarParams+="&width="+width;
	flashVarParams+="&height="+height;
	
	var myString = "";
	myString +=("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'");
			myString +=("id='Insight' width='"+width+"' height='"+height+"' ");
			myString +=("codebase='http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab'>");
			myString +=("<param name='movie' value='"+swfLocation+"?" + extraSwfArgs + "' />"); // edited by djn
			myString +=("<param name='quality' value='high' />");
			myString +=("<param name='FlashVars' value='"+flashVarParams+" '/>");
			myString +=("<param name='allowScriptAccess' value='always' />");
			myString +=("<param name='wmode' value='transparent' />"); // added by djn 3-26-08
			myString +=("<embed src='"+swfLocation+"?" + extraSwfArgs + "' quality='high' bgcolor='#ffffff'"); // edited by djn
			myString +=("width='"+width+"' height='"+height+"' name='Insight Online Book Viewer' align='middle' ");
			myString +=("play='true' ");
			myString +=("loop='false' ");
			myString +=("quality='high' ");
			if(flashVarParams) myString +=("flashVars='"+flashVarParams+"' ");
			myString +=("allowScriptAccess='always' ");
			myString +=("wmode='transparent' "); // added by djn 3-26-08
			myString +=("type='application/x-shockwave-flash' ");
			myString +=("pluginspage='http://www.adobe.com/go/getflashplayer'> ");
			myString +=("</embed>");
	myString +=("</object>");
	return myString;
}

/********************************** Mustard Lab's detect flash methods start here *************************************/
b = navigator.userAgent.toLowerCase();
if ( (b.indexOf('msie') != -1) && (b.indexOf('win') != -1) && (b.indexOf('opera') == -1) ) {
	document.writeln('<script language="VBscript">');
	document.writeln('Function detectActiveXControl(activeXControlName)');
	document.writeln('  on error resume next');
	document.writeln('  detectActiveXControl = False');
	document.writeln('  detectActiveXControl = IsObject(CreateObject(activeXControlName))');
	document.writeln('End Function');
	document.writeln('</scr' + 'ipt>');
}
function getFlashVersion(){
	var installedVersion = 0;
	if ( (b.indexOf('msie') != -1) && (b.indexOf('win') != -1) && (b.indexOf('opera') == -1) ) {
		for (var i=3; i<10; i++){
			if(detectActiveXControl("ShockwaveFlash.ShockwaveFlash."+i) == true) installedVersion = i;
		}
	} else {
		if (navigator.plugins["Shockwave Flash"]) {
			var pluginDesc = navigator.plugins["Shockwave Flash"].description;
			installedVersion = parseInt(pluginDesc.slice(pluginDesc.indexOf("Flash")+6,pluginDesc.indexOf(".")));
		}
		if(b.indexOf("webtv") != -1) installedVersion = 3;  
	}
	return installedVersion;
}
/********************************** Mustard Lab's detect flash methods end here *************************************/

