

//-------------------------------------------------------------------------------------------------
// Utilities
//-------------------------------------------------------------------------------------------------


function PageBrowserObject(){
	this.bAgent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)";
	this.bWin=true;
	this.bMac=false;
	this.bIE4=false;
	this.bIE5=false;
	this.bIE6=true;
	this.bIE4plus=true;
	this.bNS4=((document.layers)?true:false);
	this.bNS6=false;
	this.bNS7=false;
	this.bMOZ=false;
	this.bSaf=false;

	this.bVer4=(this.bNS4||this.bNS6||this.bNS7||this.bMOZ||this.bIE4plus)?true:false;
	this.bVer="6.0; windows nt 5.1; .net clr 1.1.4322)";
	this.bMajVer=6;
	this.bMinVer=6.0;
	this.SeeAll=function(){var bData="";for(a in this)if(this[a])bData+=a+"="+this[a]+"\n";alert(bData);};
}

PBO=new PageBrowserObject();

function dumpProps(obj)
{
	var	strList = new Array();
	for (prop in obj)
		if (prop.search(/html/i) == -1)
			strList[strList.length] = prop+" = "+obj[prop]+"<br>";
	strList = strList.sort();
	var outWin = window.open();
	for(str in strList)
		outWin.document.write(strList[str]);
	outWin.document.close();
}

var gDebugWin = null;
function trace(message) 
{ 
	// Create window if it does not already exist
	if(gDebugWin == null ) {
		gDebugWin = window.open("","debug","resizable=yes,scrollbars=yes,width=400,height=400");
		gDebugWin.document.write("<font face='verdana' size='2'><BR>");
	}

//	message = message.replace(/<(\\/)?(object|embed)>?/ig,'obj');
	message = message.replace(/</g, "&lt;");
	gDebugWin.document.write(message + "<BR>");
	gDebugWin.scrollBy(0,1000);
}

// Utility querystring parsing function
function parseQueryString(qsIn)
{
	if (qsIn.length==0)
		return false;

	var k="",i="",vp="",o="";
	var vploc=0,sloc=0,x=0,qs=null;
	var obj=new Object();
	if(qsIn.indexOf("?")==-1)
		qs=qsIn;
	else
		qs=qsIn.split("?")[1];

//	qs = qs.replace(/%26/g, "&");
	if(qs.indexOf("&")>-1)
	{
		while(qs.length)
		{
			vploc=qs.indexOf("&");
			var endloc = (vploc!=-1)? vploc : qs.length;
			vp=qs.substring(0,endloc);
			if(vp.indexOf("=")>-1)
			{
				sloc=qs.indexOf("=");
				k=vp.substring(0,sloc);
				i=vp.substring(sloc+1,vp.length);
				if((parseInt(i).toString().length==i.length)&&(parseInt(i).toString()!="NaN"))
					i=parseInt(i);
				else if(i.indexOf("'")>-1)
					i=i.substring(i.indexOf("'")+1,i.lastIndexOf("'"));
				obj[k]=i;
			}
			qs=qs.substring(vp.length+1,qs.length);
		}
		o=o.substring(0,o.length-1);
	}
	else
	{
		if(qs.indexOf("=")>-1)
		{
			sloc=qs.indexOf("=");
			k=qs.substring(0,sloc);
			i=qs.substring(sloc+1,qs.length);
			if((parseInt(i).toString().length==i.length)&&(parseInt(i).toString()!="NaN"))
				i=parseInt(i);
			else if(i.indexOf("'")>-1)
				i=i.substring(i.indexOf("'")+1,i.lastIndexOf("'"));
			obj[k]=i;
		}
	}
	return obj;
}


function getDOMObjectBox(obj)
{
	var oOut={t:0,l:0,w:0,h:0};
	if(obj)
		var el=obj;
	else
		var el=this;

		oOut.l=el.offsetLeft;
		oOut.t=el.offsetTop;
		var newp=el.offsetParent;
		while(newp != null){
			oOut.l+=newp.offsetLeft;
			oOut.t+=newp.offsetTop;
			newp=newp.offsetParent;}

		oOut.h=(el.height)?el.height:el.offsetHeight;
		oOut.w=(el.width)?el.width:el.offsetWidth;

	return oOut;
}

if (document.all && !document.getElementById) 
{
	resizeDOMObj = function(obj, w, h)
	{
		obj.style.pixelWidth = w;
		obj.style.pixelHeight = h;
	}
}
else
{
	resizeDOMObj = function(obj, w, h)
	{
		obj.style.width = w+"px";
		obj.style.height = h+"px";
	}
}
function DivObj(id, box, clientObj)
{
	this.id = id;
	this.box = box;
	this.clientObj = clientObj;
	this.parentDoc = document;
	this.attributes = new Object();

	this.styleAttr = new Object();
	this.styleAttr.position 		= "absolute";
//	this.styleAttr.border 			= "1px solid red";
	this.styleAttr.visibility		= "visible";
	this.styleAttr.backgroundColor	= "#FFFFFF";
	if (clientObj.bIE4plus)
		this.styleAttr["background-color"]	= "#FFFFFF";
}
DivObj.prototype.id 			= -1;
DivObj.prototype.clientObj		= null;
DivObj.prototype.domObj			= null;
DivObj.prototype.attributes		= null;
DivObj.prototype.styleAttr		= null;

DivObj.prototype.setAttribute = function(name, value)
{
	this.attributes[name] = value;
}

DivObj.prototype.setStyleAttribute = function(name, value)
{
	this.styleAttr[name] = value;
}

DivObj.prototype.create = function(theDoc, content)
{
	this.parentDoc = theDoc;
	var theDiv = null;
	var theHTML = "";
	if (typeof(content) != 'undefined')
		theHTML = content;
	if (this.clientObj.bIE4plus)
	{
		var attrStr = " ";
		for (var a in this.attributes)
			attrStr += a+'="'+this.attributes[a]+'" ';
		
		var styleStr = 'style="';
		for (var s in this.styleAttr)
			styleStr += s+':'+this.styleAttr[s]+'; ';
		styleStr += 'left:'+this.box.l+'px; top:'+this.box.t+'px; width:'+this.box.w+'px; height:'+this.box.h+'px;';
		styleStr += '"';
		
		var divInit = '<div ' + attrStr + styleStr;
		divInit +=' id="'+this.id+'" name="'+this.id+'">'+theHTML+'</div>';
		theDoc.body.insertAdjacentHTML('beforeEnd', divInit);

		theDiv = eval("theDoc.all."+this.id);
	}
	else
	{
		theDiv = theDoc.createElement('div');
		theDiv.innerHTML = theHTML;
		for (var a in this.attributes)
			theDiv.setAttribute(a, this.attributes[a]);
		theDiv.id = this.id;
		theDoc.body.appendChild(theDiv);
		for (var s in this.styleAttr)
			eval('theDiv.style.'+s+'="'+this.styleAttr[s]+'"');
		theDiv.style.top  = this.box.t+"px";
		theDiv.style.left = this.box.l+"px";
		theDiv.style.width = this.box.w+"px";
		theDiv.style.height = this.box.h+"px";
	}
	this.domObj = theDiv;

	return this.domObj;
}


DivObj.prototype.write = function(theHTML)
{
	if (this.domObj)
	{
		this.findDoc();
		this.domObj.innerHTML = theHTML;
	}
}

DivObj.prototype.moveTo = function(left, top)
{
	if (this.clientObj.bIE4plus)
	{
		eval("this.parentDoc.all['"+this.id+"'].style.pixelTop="+top)
		eval("this.parentDoc.all['"+this.id+"'].style.pixelLeft="+left);
	}
	else if (typeof(this.domObj.style) != 'undefined')
	{
		this.domObj.style.left = left+"px";
		this.domObj.style.top = top+"px";
	}
}

DivObj.prototype.findDoc= function()
{
	this.doc = this.domObj.contentDocument;
	if (this.domObj.contentDocument)	// For NS6    
		this.doc = this.domObj.contentDocument;
	else if (this.domObj.contentWindow) // For IE5.5 and IE6    
		this.doc = this.domObj.contentWindow.document;
	else if (this.domObj.document) // For IE5
		this.doc = eval(this.domObj.id+".document");
	
	return this.doc;
}

// Mac IE is a special animal since there is no Flash Player scripting support.
// We must use a secondary transient Flash movie and LocalConnection to communciate inbound
// messages to the AdBuilder in this configuration.
// Looks like Mac Netscape 7.1 and Safari fall into the same category as Mac IE here.

var gReflectorDone 	= false;
var gReflector		= null;
function reflectorDone()
{
	gReflectorDone = true;
}

function reflectorNeeded(clientObj)
{
	return ((clientObj.bMac && clientObj.bIE4plus) || (clientObj.bMac && clientObj.bNS7 && clientObj.bMinVer >= 7.1) || clientObj.bSaf || clientObj.bMOZ  || (clientObj.bNS7 && clientObj.bMinVer < 7.1));
}


function Reflector(id, url, debugLevel, clientObj)
{
	this.id 			= id;
	this.url 			= url;
	this.debugLevel 	= debugLevel;
	this.clientObj		= clientObj;
	
	gReflector = this;
}

Reflector.prototype.reflectorDiv	= null;
Reflector.prototype.interval		= 0;
Reflector.prototype.id			= "";
Reflector.prototype.url			= "";
Reflector.prototype.debugLevel	= 0;
Reflector.prototype.clientObj		= null;

Reflector.prototype.doNextCmd = function(cmdStr)
{
	if (gReflectorDone)
	{
		this.killTimer();
		gReflectorDone = false;
		this.reflectorDiv.write(cmdStr);
	}
}

Reflector.prototype.sendCommand = function(cmdQS)
{
	myobj = '<EMBED src="'+this.url+'" quality=high bgcolor="#eaeaea" ';
	myobj += 'swLiveConnect=TRUE WIDTH="1" HEIGHT="1" NAME="reflector" ALIGN="" menu="false" ';
	myobj += 'flashvars="js=1&gDebugLevel='+this.debugLevel+'&reflectorid='+this.id+'&'+cmdQS+'" ';
	myobj += 'TYPE="application/x-shockwave-flash" PLUGINSPAGE="' + document.location.protocol + '//www.macromedia.com/go/getflashplayer"> ';
	myobj += '</EMBED> ';

	// If reflector div doesn't exist, create it.
	// Otherwise, set timer to pass command to reflector when it's ready to receive.
	if (this.clientObj.bMac && this.clientObj.bIE4plus && !this.clientObj.bSaf) 
		document.body.insertAdjacentHTML('beforeEnd', myobj);
	else 
	{
		if (this.reflectorDiv == null)
		{
			var testDiv = new DivObj("refDiv", {l:-1000,t:-1000,w:300,h:200}, this.clientObj);
			testDiv.create(document, myobj);
			this.reflectorDiv = testDiv;
		}
		else
		{
			this.killTimer();
			this.interval = setInterval("gReflector.doNextCmd('"+myobj+"')", 200);
		}
	}
}

Reflector.prototype.killTimer = function()
{
	if (this.interval != 0)
	{
		clearInterval(this.interval);
		this.interval = 0;
	}
}
// Flash installation check
if (typeof(gMM_contentVersion) == 'undefined')
	var gMM_contentVersion = 7;
if (typeof(gLatestFlashVersion) == 'undefined')
	var gLatestFlashVersion = 8;
var gMM_FlashCanPlay = false;
var gFlashVersionInstalled = false;
var gBaseFlashVersionInstalled = false;
var gLatestFlashVersionInstalled = false;
var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
if (plugin) 
{
	var words = navigator.plugins["Shockwave Flash"].description.split(" ");
    for (var i = 0; i < words.length; ++i)
    {
		if (isNaN(parseInt(words[i])))
			continue;
		var gMM_PluginVersion = words[i]; 
    }
	gBaseFlashVersionInstalled = gMM_PluginVersion >= gMM_contentVersion;
	gLatestFlashVersionInstalled = gMM_PluginVersion >= gLatestFlashVersion;
	gFlashVersionInstalled = (gBaseFlashVersionInstalled || gLatestFlashVersionInstalled);
	gMM_FlashCanPlay = gFlashVersionInstalled;
}
else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 && (navigator.appVersion.indexOf("Win") != -1)) 
{
	document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n'); //FS hide this from IE4.5 Mac by splitting the tag
	document.write('on error resume next \n');
	document.write('gLatestFlashVersionInstalled = false\n');
	document.write('gLatestFlashVersionInstalled = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & gLatestFlashVersion)))\n');
	document.write('gBaseFlashVersionInstalled = false\n');
	document.write('gBaseFlashVersionInstalled = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & gMM_contentVersion)))\n');
	document.write('</SCR' + 'IPT\> \n');
	
	gFlashVersionInstalled = gBaseFlashVersionInstalled || gLatestFlashVersionInstalled;
	
	// IE can auto-install
	gMM_FlashCanPlay = true;
}
// END - Flash installation check


var gClient = PBO;

// These functions are used to reload images on a page if the viewer is invoked prior to page
// load completion.
var gImgCount = 0;
function imgLoaded() 
{
	gImgCount--;
	if (gImgCount <= 0)
		gViewer.pageLoadComplete = true;
}

function reloadImages() 
{
	gImgCount = document.images.length;
	for(var x = 0, y; y = document.images[x]; x++)
	{
		y.onload = imgLoaded;
		y.src = y.src;		
	}
}

function getPageSize() 
{
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) 
	{
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} 
	else if( document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
	{
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} 
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
	{
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	return {w:myWidth, h:myHeight};
}

// Mac IE is a special animal since there is no Flash Player scripting support.
// We must use a secondary transient Flash movie and LocalConnection to communciate inbound
// messages to the Viewer in this configuration.
// Looks like Mac Netscape 7.1, Mozilla and Safari fall into the same category as Mac IE here.
var gViewer 	= null;

function ViewerParms()
{
}
ViewerParms.prototype.pageDomain 			= document.location.hostname;
ViewerParms.prototype.themeColor	 		= "0xC8DAA9";
ViewerParms.prototype.uiStyle		 		= "floating";
ViewerParms.prototype.gDebugLevel 			= 0;
ViewerParms.prototype.transparent			= 0;
ViewerParms.prototype.showcaption 			= 1;
ViewerParms.prototype.onLoadHandler 		= "javascript:gViewer.onLoad";
ViewerParms.prototype.onMediaLoadedHandler 	= "javascript:gViewer.onMediaLoaded";
ViewerParms.prototype.openCompleteHandler 	= "javascript:gViewer.openComplete";
ViewerParms.prototype.closeCompleteHandler 	= "javascript:gViewer.closeComplete";
ViewerParms.prototype.onCloseHandler 		= "javascript:gViewer.onClose";
ViewerParms.prototype.onErrorHandler 		= "javascript:gViewer.onError";
ViewerParms.prototype.sizeHandler 			= "javascript:gViewer.onSize";
ViewerParms.prototype.adserverurl 			= "http://v.s0.gc.sj.ipixmedia.com/rimfire/admission";
ViewerParms.prototype.paypalurl 				= "https://www.paypal.com/cgi-bin/webscr";
ViewerParms.prototype.preview				= 0;
ViewerParms.prototype.ipixdomain 			= "c.s0.gc.sj.ipixmedia.com";
ViewerParms.prototype.localitycode 			= "en";
ViewerParms.prototype.bannerid 				= "";						// Spotlight banner id for event logging
ViewerParms.prototype.pageid				= "";						// spotlight:banner tracking ID OR non-spotlight:page tracking id
ViewerParms.prototype.pageurl				= escape(document.URL);	// pageurl for event logging
ViewerParms.prototype.eventlog				= 1;						// set eventlog to 1 (partner can override)
ViewerParms.prototype.trackinginfo			= "7aaf49f17e6e363ce2097f6af6976252";		// set unique session id for tracking

ViewerParms.prototype.buildFlashVars = function()
{
	var flashvars = "";
	for (prop in this)
	{
		if (prop != null && typeof(this[prop]) != 'function')
			flashvars += prop.toLowerCase()+"="+this[prop];
		flashvars += "&";
	}
	if (flashvars.lastIndexOf("&") == flashvars.length-1)
		flashvars = flashvars.substring(0,flashvars.length-1);
	
	return flashvars;
}

function Viewer()
{
}
Viewer.prototype.errorCode 				= 0;
Viewer.prototype.errorHandler 			= null;
Viewer.prototype.loadHandler 			= null;
Viewer.prototype.mediaLoadHandler 		= null;
Viewer.prototype.closeHandler 			= null;
Viewer.prototype.viewerDiv 				= null;
Viewer.prototype.reflectorDiv 			= null;
Viewer.prototype.pos 					= {l:0,t:0};
Viewer.prototype.size 					= {w:0,h:0};
Viewer.prototype.bOpen 					= false;
Viewer.prototype.parms 					= new ViewerParms();
Viewer.prototype.interval				= 0;
Viewer.prototype.pendingCmd				= null;
Viewer.prototype.imgOffset				= {x:0,y:0};
Viewer.prototype.imgID					= "viewerloc";
Viewer.prototype.pageLoadComplete		= false;
Viewer.prototype.reflector				= null;
Viewer.prototype.bReady				= false;

Viewer.prototype.setProp = function(propName, value)
{
	this[propName] = value;
}

Viewer.prototype.getProp = function(propName)
{
	return this[propName];
}

Viewer.prototype.setParm = function(parmName, value)
{
	this.parms[parmName] = value;
}

Viewer.prototype.getParm = function(parmName)
{
	return this.parms[parmName];
}

Viewer.prototype.createClientComponentHTML = function(moviePath, w, h)
{	
	var flashvars = this.parms.buildFlashVars();
	if ((PBO.bNS6 || PBO.bNS7 || PBO.bMOZ) && PBO.bWin)
		this.parms.transparent = 0;
	
	var wmode = (this.parms.transparent == 1) ? "transparent" : "window";
	if(PBO.bIE4plus && !PBO.bMac)
	{
		var myobj = ' \
		<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" \
		codebase="' + document.location.protocol + '//download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" \
		ID="viewer" WIDTH="'+w+'" HEIGHT="'+h+'" ALIGN=""> \
		<PARAM NAME=movie VALUE="'+moviePath+'"> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=#ffffff> \
		<PARAM NAME=wmode VALUE="'+wmode+'"> \
		<PARAM NAME=menu VALUE=false> \
		<PARAM NAME=flashvars VALUE="'+flashvars+'"> \
		<PARAM NAME=BASE VALUE="."> \
		</OBJECT> ';
	}
	else
	{
		var myobj = '\
		<EMBED src="'+moviePath+'" quality=high bgcolor=#FFFFFF \
		swLiveConnect=TRUE WIDTH="'+w+'" HEIGHT="'+h+'" NAME="viewer" ALIGN="" wmode="'+wmode+'" menu="false" \
		flashvars="'+flashvars+'"  \
		TYPE="application/x-shockwave-flash" PLUGINSPAGE="' + document.location.protocol + '//www.macromedia.com/go/getflashplayer" BASE="."> \
		</EMBED> ';
	
	}
	return myobj;
}

Viewer.prototype.createMovie = function(moviePath, l, t, w, h, imgID, groupHandle, descriptionText)
{
	this.imgID = imgID;
	var movieSize = {w:w, h:h};
	if (PBO.bIE4plus && !PBO.bMac)
	{
		w = "100%";
		h = "100%";
	}
	var movieCode = this.createClientComponentHTML(moviePath,w,h);
//alert(movieCode);
	var testDiv = new DivObj("vwrDiv", {l:l,t:t,w:movieSize.w,h:movieSize.h}, gClient);
	if (PBO.bIE4plus && this.parms.transparent == 1)
		testDiv.setStyleAttribute("background-color", "transparent");
	testDiv.create(document, movieCode);
	this.viewerDiv = testDiv;
}

Viewer.prototype.createInlineMovie = function(moviePath, imgID, groupHandle, descriptionText)
{
	this.imgID = imgID;
	var oData = getDOMObjectBox(document.images[imgID]);	
	if ((typeof(descriptionText) == 'undefined') || (descriptionText == null))
	{
		var descriptionText = this.textFromDiv(imgID+"txt");
		this.setParm("description", escape(descriptionText));
	}
	this.createMovie(moviePath,oData.l,oData.t,oData.w,oData.h, imgID, groupHandle, descriptionText);
}

Viewer.prototype.textFromDiv = function(divID)
{
	var descriptionText = "";
	var txtDiv = null;
	if (PBO.bIE4plus)
	{
		txtDiv = document.getElementById(divID);
	}
	else if (PBO.bNS6 || PBO.bNS7 || PBO.bSaf || PBO.bMOZ)
	{
		txtDiv = document.getElementById(divID);
	}
	if (txtDiv != null && typeof(txtDiv) != 'undefined' && typeof(txtDiv.childNodes) != 'undefined' && txtDiv.childNodes.length > 0)
	{
		descriptionText = txtDiv.childNodes[0].nodeValue;
		
		// Replace any newline/carriage return characters to avoid double-spacing in Netscape
		descriptionText = descriptionText.replace(/\r\n/g," ");
		descriptionText = descriptionText.replace(/\r/g," ");
		descriptionText = descriptionText.replace(/\n/g," ");
	}
	return descriptionText;
}

Viewer.prototype.getViewerCtrl = function()
{
	var ctrl = null;
	var viewerDoc = this.viewerDiv ? this.viewerDiv.findDoc() : null;
	if(PBO.bIE4plus && !PBO.bMac)
		ctrl = (viewerDoc ? viewerDoc.viewer : null);
  	else if(PBO.bNS4)
		ctrl = (viewerDoc ? viewerDoc.embeds['viewer'] : null);
  	else if((PBO.bNS6 || PBO.bNS7 || PBO.bMOZ || PBO.bMac) && !PBO.bSaf)
		ctrl = document.embeds['viewer'];
  	else if(PBO.bSaf)
		ctrl = viewer;
	return ctrl;
}

Viewer.prototype.createReflector = function()
{
	if (reflectorNeeded(gClient))
		this.reflector = new Reflector(this.parms.reflectorid,  'http://c.s0.gc.sj.ipixmedia.com/admission/classified/viewer/swf/reflector.swf', this.parms.gDebugLevel, gClient);
}

Viewer.prototype.sendCommand = function(cmdQS)
{	
	if (gViewer.bReady)		
	{
		if (this.reflector != null)
		{
			this.reflector.sendCommand(cmdQS);
		}
		else
		{
			var ctrl = this.getViewerCtrl();
			ctrl.SetVariable("cmd",cmdQS);
		}
	}
	else
		setTimeout("gViewer.sendCommand('"+cmdQS+"')",100);		
}

Viewer.prototype.doPendingCmd = function()
{
	if (this.pendingCmd != null)
	{
		this.sendCommand(this.pendingCmd);
		this.pendingCmd = null;
	}
}

Viewer.prototype.isFloatStyle = function()
{
	return (this.parms.uiStyle == "floating");
}

Viewer.prototype.calcPos = function(imgID)
{
	var oData = getDOMObjectBox(document.images[imgID]);	
	this.pos.l = oData.l + this.imgOffset.x;
	this.pos.t = oData.t-1 + this.imgOffset.y;
}

Viewer.prototype.privateLoadMedia = function(cmdStr, imgID, descriptionText)
{
	if (this.viewerDiv == null)
		this.loadViewer();
	
	this.imgID = imgID;
	this.calcPos(imgID);
	
	if ((typeof(descriptionText) != 'undefined') && (descriptionText != null))
	{
		cmdStr += "&description="+escape(descriptionText);
	}
	else	
	{
		var descriptionText = this.textFromDiv(imgID+"txt");
		cmdStr += "&description="+escape(descriptionText);
	}
	
	// If no close is required, no notification will occur so force the open directly
	if (!this.bOpen)
	{
		this.moveTo(this.pos.l, this.pos.t);
		cmdStr += "&displayAction=open";
	}
	
	cmdStr += "&adserverurl="+this.parms["adserverurl"];

	// If floating and open, close the viewer and wait for completion before sending the
	// open and load commands.
	if (this.isFloatStyle() && this.bOpen)
	{
		//this.pendingCmd = "action=open&"+cmdStr;
		this.pendingCmd = cmdStr;
		cmdStr = "action=closeAndNotify";
	}
	// For Netscape. The sendCommand() needs to occur in a separate thread for some Netscapey reason
	setTimeout("gViewer.sendCommand('"+cmdStr+"')",100);
}

Viewer.prototype.loadMedia = function(mediasetPath, imgID, descriptionText)
{
	var cmdStr = "action=viewMediaset&mediasetPath="+mediasetPath;
	this.privateLoadMedia(cmdStr, imgID, descriptionText);	
}

Viewer.prototype.viewAd = function(acct, adID, imgID, descriptionText)
{
	var cmdStr = "action=viewAd&adid="+adID+"&account="+acct;
	this.privateLoadMedia(cmdStr, imgID, descriptionText);	
}


Viewer.prototype.close = function()
{
	this.sendCommand("action=close");
}

Viewer.prototype.hide = function()
{
	if (this.viewerDiv)
		this.viewerDiv.moveTo(-1024, -1024);
}

Viewer.prototype.onError = function(errorCode)
{
	this.setProp("errorCode",errorCode);
	if (this.errorHandler)
	{
		eval(this.errorHandler+"('"+errorCode+"')");
	}
}

Viewer.prototype.onLoad = function()
{
	this.bReady = true;
	if (this.loadHandler)
		eval(this.loadHandler+"()");

	if (this.pageLoadComplete == false)
		setTimeout("reloadImages()",200);
}

Viewer.prototype.doOpenViewer = function()
{
	this.sendCommand("action=open");
}

Viewer.prototype.onMediaLoaded = function()
{
	if (this.mediaLoadHandler)
		eval(this.mediaLoadHandler+"()");
	
	if (this.pageLoadComplete == false)
		setTimeout("reloadImages()",200);
}

Viewer.prototype.onClose = function()
{
	this.bOpen = false;
	this.hide();
	if (this.closeHandler)
		eval(this.closeHandler+"()");

	if (this.pageLoadComplete == false)
		setTimeout("reloadImages()",200);
}

Viewer.prototype.openComplete = function()
{
	this.bOpen = true;
}

Viewer.prototype.closeComplete = function()
{
	this.moveTo(this.pos.l, this.pos.t);
	this.bOpen = false;
	setTimeout("gViewer.doPendingCmd()",100);
}

Viewer.prototype.loadViewer = function()
{
	if (this.viewerDiv == null)
	{
		if (bLoadEmbedded)
		{
			gViewer.parms['cmd'] = "open"; // triggers movie to open at initialization	
			gViewer.createInlineMovie("http://c.s0.gc.sj.ipixmedia.com/admission/classified/viewer/classified/viewer.swf", "viewerloc", this.parms['mediasetPath'], this.parms['description']);
		}
		else
		{
			var l = -1000;
			var t = l;
			gViewer.createMovie("http://c.s0.gc.sj.ipixmedia.com/admission/classified/viewer/classified/viewer.swf", l, t,this.parms['uiWidth'],this.parms['uiHeight']);
		}
	}
}

Viewer.prototype.onPageLoad = function()
{
	this.pageLoadComplete = true;
	if (this.viewerDiv == null)
		setTimeout("gViewer.loadViewer()",500);
}

Viewer.prototype.onResize = function()
{
	if (this.bOpen)
	{
		this.calcPos(this.imgID);
		if (this.viewerDiv)
			this.viewerDiv.moveTo(this.pos.l, this.pos.t);
	}
}

Viewer.prototype.isReady = function()
{
	var ctrl = this.getViewerCtrl();
	return (this.bReady && this.viewerDiv && ctrl && ((typeof(ctrl.SetVariable) != 'undefined') || (typeof(ctrl.movie) != 'undefined') || (typeof(ctrl.src) != 'undefined')));
}

Viewer.prototype.moveTo = function(l, t)
{
	if (this.viewerDiv)
	{
		this.viewerDiv.moveTo(l, t);
		
		if (t < document.body.scrollTop)
			window.scrollTo(l, t);
		else 
		{
			var pageSize = getPageSize();
			var bScrollIt = false;
			if (t + this.parms['uiHeight'] > document.body.scrollTop + pageSize.h)
			{
				t = t + this.parms['uiHeight'] - pageSize.h;
				bScrollIt = true;
			}
			if (l + this.parms['uiWidth'] > document.body.scrollLeft + pageSize.w)
			{
				l = l + this.parms['uiWidth'] - pageSize.w;
				bScrollIt = true;
			}
			if (bScrollIt)
				window.scrollTo(l, t);
		}
	}
}

Viewer.prototype.applySize = function()
{
	var ctrl = this.getViewerCtrl();
	if (ctrl)
	{
		if (bLoadEmbedded == true)
		{
			var placeholderImg = document.images[this.imgID];	
			resizeDOMObj(placeholderImg, this.size.w, this.size.h);
		}
		resizeDOMObj(this.viewerDiv.domObj, this.size.w, this.size.h);
		resizeDOMObj(ctrl, this.size.w, this.size.h);
	}
}

Viewer.prototype.onSize = function(w,h)
{
	this.size.w = w;
	this.size.h = h;
	gViewer.applySize();
}

// gViewer Object Creation
gViewer = new Viewer();

// Reset the window.onload method
Viewer.prototype.setWindowHandlers = function()
{
	var wO = window.onload;
	if(wO)
	{
		var OL = window.onload.toString();
		if (OL.indexOf("gViewer.onPageLoad") == -1)
		{
			OL = "gViewer.onPageLoad();\r"+OL.substring(OL.indexOf("{")+1,OL.lastIndexOf("}"))+"\r;";
			window.onload = new Function(OL);
		}
	}
	else
	{
		window.onload = new Function("gViewer.onPageLoad();");
	}
	
	
	// Catch onResize event to ensure uploader iframe is positioned correctly
	var saveOnResize = window.onresize;
	if(saveOnResize)
	{
		var newOnResize = window.onresize.toString();
		if (newOnResize.indexOf("gViewer.onResize") == -1)
		{
			newOnResize = "gViewer.onResize();\r"+newOnResize.substring(newOnResize.indexOf("{")+1,newOnResize.lastIndexOf("}"))+"\r;";
			window.onresize = new Function(newOnResize);
		}
	}
	else
	{
		window.onresize = new Function("gViewer.onResize();");
	}
}


function duringPageLoad()
{
	bLoadEmbedded = false;
	//This will setup the size of the movie to be a size based on what is passed in via the XML file for each viewer movie.

	gViewer.parms['uiWidth'] = 452;
	gViewer.parms['uiHeight'] = 529;

	//Set XML ad server URL
	gViewer.parms['adserverurl'] = "http://v.s0.gc.sj.ipixmedia.com/rimfire/admission";
	var now = new Date();
	gViewer.parms['reflectorid'] = "_reflector_lc"+now.getTime(); //Reflector unique id to avoid conflicts
	gViewer.createReflector();
	
	//This will grab all parms off of the imagename if there are any.
	if(document.images['viewerloc'] && document.images['viewerloc'].src.indexOf("?")>-1)
	{
		var parms = parseQueryString(document.images['viewerloc'].src);
		for(a in parms)
		{
			gViewer.parms[a] = parms[a];
		}
		bLoadEmbedded = true;
	}

		gViewer.parms['vwStyle'] = "classified";

		gViewer.parms['uiStyle'] = "floating";

	
	gViewer.setWindowHandlers();
}

duringPageLoad();



