/* MKQ 2.0 release */
function Exhibit(o)
{
	var scaleFactor;
	var shell_uiHeight = 50;

	this.id = String(o.id);
	this.exhibitNumber = String(o.exhibitNumber);
	this.header = (o.header);
	this.localeType = MKQ.__LOCALE_NAME;          //default locale

    this.width = o.width ? o.width : 1;
	this.height = o.height ? o.height : 1;
	// new width height
	//scaleFactor = 640/545;
	// new width height
		if (this.height < (this.width * .85)){
		    // if the exhibit is 2column or vertical 
	       scaleFactor = 640/545;
	    } else {
	        scaleFactor = 1.2;
	    }
	    
	this.shellWidth  = Math.floor(
		this.width * scaleFactor
	);
	this.shellHeight = Math.floor(
		this.height * scaleFactor + shell_uiHeight
	);
	
	this.urlSwf = o.urlSwf ? o.urlSwf : "";
	this.urlGif = o.urlGif ? o.urlGif : "";
	this.alt = o.alt ? o.alt : "";
	this.articleTitle = o.articleTitle ? o.articleTitle : "";
	
	
	this.popupHtml = "/sp.aspx?pgn=popup_exhibit";
	//this.popupHtml = "exhibitShellPopup.html";
	
	// determine the swf url if there is a shell vs. there is none
	//this.disableZoomPan = (o.disableZoomPan);
}

Exhibit.prototype.getReusableShellPath = function() {
	return "/inc/"  + this.localeType;    
}

Exhibit.prototype.getSwfURL = function() {
	return this.getReusableShellPath() + "/reusableShell.swf?"
		+ "swf=" + this.urlSwf
		+ "&swfID=" + this.id
		+ "&exhibitNumber=" + this.exhibitNumber
		+ "&swfHeader=" + this.header
		//+ "&enableZoomPan=" + (this.disableZoomPan ? "0" : "1")
	;
}
Exhibit.prototype.getInlineSwfURL = function()
{
	return this.getSwfURL() + "&popUpButtonVisible=1&frameNumber=1";
}
Exhibit.prototype.getPopUpSwfURL = function(frameNumber)
{
	if (frameNumber==undefined || frameNumber==null)
	{
		frameNumber="1";
	}

	return this.getSwfURL() + "&popUpButtonVisible=0" + "&frameNumber="+frameNumber;
}

function ReusableShell()
{
	this.exhibitCollection = new Array();
	this.articleTitle = "";
	this.selectedId = -1;
	ReusableShell.instance = this;
}

ReusableShell.instance = null;


ReusableShell.prototype.setArticleTitle = function(s)
{
	this.articleTitle = s;
}

ReusableShell.prototype.addExhibit = function(o)
{
	
	this.exhibitCollection[o.id] = new Exhibit(o);
}

ReusableShell.prototype.detectFlash = function()
{

	//var flashInfo = new MM_FlashInfo();
	
	if (DetectFlashVer(7, 0, 0))
	{
		if (document.getElementById('ctl00_body') && document.getElementById("ctl00_body").className.indexOf('printableArticle') != -1)
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	else
	{
		return false;
	}
}

ReusableShell.prototype.writeExhibitById = function(id, exhibitNumber)
{
	var exhibit = this.exhibitCollection[id];
	if (exhibit == null ) return;
	var strOutput = "";
	if (this.detectFlash())
	{
		strOutput += "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' ";
		strOutput += " id='exhibit" + id + "'";
		strOutput += " exhibitNumber='" + exhibitNumber + "'";
		strOutput += " width='" + String(exhibit.shellWidth) + "'";
		strOutput += " height='" + String(exhibit.shellHeight) + "'";
		strOutput += ">";
		strOutput += "<param name='movie' value='" + exhibit.getInlineSwfURL() +"' />";
		strOutput += "<param name='quality' value='high' />";
		strOutput += "<param name='bgcolor' value='#ffffff' />";
		strOutput += "<param name='align' value='TL' />";
		strOutput += "<param name='wmode' value='transparent' />";
		strOutput += "<embed src='" + exhibit.getInlineSwfURL() + "'";
		strOutput += " play='true' loop='true' quality='high' wmode='transparent' menu='true' bgcolor='#ffffff' swLiveconnect='false'";
		strOutput += " width='" + String(exhibit.shellWidth) + "'";
		strOutput += " height='" + String(exhibit.shellHeight) + "'";
		strOutput += " name='exhibit" + id + "'";
		strOutput += " exhibitNumber='" + exhibitNumber + "'";
		strOutput += " align='TL'";
		strOutput += "></embed>";
		strOutput += "</object>";
	}
	else
	{
		strOutput += "<img src='" + exhibit.urlGif + "'";
		strOutput += " alt='" + exhibit.alt + "'";
		strOutput += "/>";
		
		// TODO: ASK: this shouldn't display on a printer friendly page
		if(1) {            
            if( MKQ.__LOCALE_NAME == "zh-CN" ) {
                strOutput += "<p class='expandView'>??????,??? 7.0 ???????? <a href='http://www.adobe.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash&P2_Platform=Win32&P3_Browser_Version=MSIE&P5_Language=S_Chinese&Lang=S_Chinese'>Adobe Flash Player plugin</a>?</p>";
            } else {
			    strOutput += "<p class='expandView'>To view enlarged exhibits, please install the <a href='http://www.macromedia.com/go/getflashplayer'><img src='/img/icon-enlarge.gif' /> Adobe Flash Player plugin</a> version 7 or greater.</p>";
		    }
		}
	}

	document.writeln(strOutput);
}

ReusableShell.prototype.popExhibitById = function (id, frameNumber)
{
	var exhibit = this.exhibitCollection[id];
	if (exhibit == null || exhibit==undefined)
	{
		return;
	}
	//added default to catch exceptions
	if (frameNumber == null || frameNumber==undefined)
	{
		frameNumber==1;
	}
	
	this.selectedId          = id;
	this.selectedFrameNumber = frameNumber;
	

	var windowW = screen.availWidth; //*.8;
	var windowH = screen.availHeight; //*.8;
	
	var winOpen = window.open(exhibit.popupHtml, "winExhibit", "width="+windowW+",height="+windowH+",toolbars=no, resizable=yes, screenX=5, screenY=5");
    
    //insert call to lightbox here

}

ReusableShell.prototype.writePopupExhibit = function(winPop)
{
	// retriev exhibit
	var exhibit = this.exhibitCollection[this.selectedId];

	// exit function if exhibit not found
	if (exhibit == null || exhibit==undefined) return;
	
	// document object of the popup window
	var doc = winPop.document;
	
	// determine if we need to change the width of the shell
	var shellW = "100%";
	var shellH = "88%";	
	
	var o = "";
	o += "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' ";
	o += " id='exhibitPopup'";
	o += " width='"  + shellW + "'";
	o += " height='" + shellH + "'";
	o += ">";
	o += "<param name='movie' value='" + exhibit.getPopUpSwfURL(this.selectedFrameNumber) +"' />";
	o += "<param name='quality' value='high' />";
	o += "<param name='bgcolor' value='#ffffff' />";
	o += "<param name='align' value='TL' />";
	o += "<embed src='" + exhibit.getPopUpSwfURL(this.selectedFrameNumber) + "'";
	o += " play='true' loop='true' quality='high' menu='true' bgcolor='#ffffff' swLiveconnect='false'";
	o += " width='"  + shellW + "'";
	o += " height='" + shellH + "'";
	o += " name='exhibitPopup'";
	o += " align='TL'";
	o += "></embed>";
	o += "</object>";


	doc.writeln(this.articleTitle);
	doc.writeln(o);
}


function popExhibitById(id, frameNumber)
{
	ReusableShell.instance.popExhibitById(id, frameNumber);
}