// JavaScript Document
var isSafari         = (/Safari/.test(navigator.userAgent))?true:false;
var isKonq_Saf_KHTML = (/Konqueror|Safari|KHTML/.test(navigator.userAgent))?true:false;
var isMSIE           = (/MSIE/.test(navigator.userAgent))?true:false;
var isGecko          = (/Gecko/.test(navigator.userAgent)&&!isKonq_Saf_KHTML)?true:false;
var isFirefox        = (/Firefox\/2/.test(navigator.userAgent)&&!isSafari)?true:false;

var rand = Math.ceil(Math.random()*65000);

var loaderURL = "swf/loader.swf?rand="+rand;
var flashPDFURL = "swf/flashPDF.swf";
var assetsURL = "swf/bookAssets.swf?rand"+rand;
var expressInstallURL = "swf/expressinstall.swf?rand="+rand;
var customer_id  = 1; // default customer, maybe customer_id with value 1 should be the default demo book for flashPDF, if one is ever created.
var catalogue_id = -1; // catalogue_id is not 1 by default, because there is possibility to set the default value in the configuration's archive node.
var page_id = 1;
var licence_key  = "dec4585d186fed223904a8ae399a427affa19738";


// using firefox, javascript can close window only if that window has been opened by javascript itself. this is workaround. 
function _onLoad(){
	if(isFirefox && !window.opener)
	{
		window.opener.mywin = window.open(window.location,"");
	}
	else
	{
		embedFlashPDF();
	}
}
function embedFlashPDF()
{
		var so = new SWFObject(loaderURL, "flashpdf_swf", "100%", "100%", "9", "#e0dfe1");
		so.addParam("scale", "noscale");
		so.addParam("allowscriptaccess", "always");
		so.addParam("allowFullScreen", "true");
		so.useExpressInstall(expressInstallURL);
		so.write("flashcontent");	

}



// EXTERNAL INTERFACE////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Functions being called from swf //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// function called from flash by external interface
function closeWin()
{
	if(isMSIE)
	{
			window.opener='x';
	}
	if(!window.parent)
	{
		window.close();
	}
	else
	{
		window.parent.close();
	}
}

// this function is called from loader.swf ( ExternalInterface ) , to get  flashPDF.swf URL.
// this has been done this way because sometimes when passing flashvars to loader.swf directly, we could see wrong vaersion of flashPDF.swf ( maybe some cache thing )
function getFlashPDFURL()
{
		var ret = flashPDFURL + "?rand="+rand+"&licenceKey="+licence_key+"&customer_id="+customer_id;
		if(catalogue_id != -1)
		{
			ret += ("&catalogue_id="+catalogue_id);
		}
		if(page_id > 1)// default value in flashPDF.swf is 1, so do not bother if it is 1 or less.
		{
			ret += ("&page_id="+page_id);
		}
		return escape(ret);
}

// this function is called from loader.swf ( ExternalInterface ) , to get  bookAssets.swf URL.
// this has been done this way because sometimes when passing flashvars to loader.swf directly, we could see wrong vaersion of flashPDF.swf ( maybe some cache thing )
function getAssetsURL()
{
		return escape(assetsURL);
}

