var d = document;
var agent=navigator.userAgent.toLowerCase();
var mac = (agent.indexOf("mac")>-1)
var safari = (agent.indexOf("safari")>-1);
var opera = ( agent.indexOf("opera")>-1 );

var ie5 = (agent.indexOf("msie 5")>-1);
var ie55 = (agent.indexOf("msie 5.5")>-1);
var ie6 = 	(agent.indexOf("msie 6")>-1);

var ie = ( (ie6 || ie5 || ie55 )&& !opera);

if(mac==true && safari==true)
{
   d.write('<link rel="stylesheet" type="text/css" href="/en/screen_safari.css" media="screen" />');
}

if(mac==true && ie5==true)
{
   d.write('<link rel="stylesheet" type="text/css" href="/en/screen_ie5mac.css" media="screen" />');
}

function toggle(  id, obj, event )
{
	if( d.getElementById )
	{
		obj.href = "#";
		s = obj.firstChild;
		if( s.src.indexOf("/_minus.gif") != -1 )
		{
			s.src = "/fm/19/_plus.gif";
			d.getElementById( id ).style.display = "none";
		}
		else
		{
			s.src = "/fm/19/_minus.gif";
			d.getElementById( id ).style.display = "block";	
		}
		window.event.returnValue = false;
		return false;
	}
}

function _toggle(  id, obj, event )
{
	if( d.getElementById )
	{
		obj.href = "#";
		s = obj.firstChild;
		if( s.src.indexOf("/_icon_minus.gif") != -1 )
		{
			s.src = "/fm/47/_icon_plus.gif";
			d.getElementById( id ).style.display = "none";
		}
		else
		{
			s.src = "/fm/47/_icon_minus.gif";
			d.getElementById( id ).style.display = "block";	
		}
		window.event.returnValue = false;
		return false;
	}
}


// flash detection
var flashCanPlay = false;
var contentVersion = 6;
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 pluginVersion = words[i]; 
	}
	
	var flashCanPlay = pluginVersion >= contentVersion;
}
else if ( ie )
{
	d.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
	d.write('on error resume next \n');
	d.write('flashCanPlay = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & contentVersion)))\n');
	d.write('</SCR' + 'IPT\> \n');
}

function openImageWindow( title, width, height, imgsrc, displayDownload )
{
	var width = ( width ) ? width : "400";
	var height = ( height ) ? height : "300";
	
	var imgtitle = ( title ) ? title : "No title";
	//var closetext = "Click to close window";
	
	var closetext = "To download this image, click the right button of your mouse and then choose \"Save Image\" from the menu list. When finished downloaded, click the left button of your mouse to close the window.";
	
	mywin = window.open('', 'zoompic', 'width=' + width + ',height='+ height + ',scrollbars=no,toolbar=no,location=no,status=no,menubar=no,resizable=yes'); 
	mywin.document.writeln('<html><head><title>' + imgtitle + '</title></head>');
	mywin.document.writeln('<body scroll=no class=image bgcolor=\'#FFFFFF\' text=\'#000000\' leftmargin=\'0\' topmargin=\'0\' marginheight=\'0\' marginwidth=\'0\'>');
	
	if ( displayDownload )
	{
		height = height + 40;
		mywin.document.writeln('<div style="padding: 2px 0px 0px 10px;font-family: Tahoma, Arial;font-size:10pt;width:100%;height:30px;background-color:#dddddd;">Title: <strong>' + title + '</strong>&nbsp;&nbsp;' );
		mywin.document.writeln( closetext + '</div>' );
	}
	
	mywin.document.writeln('<a href=\'javascript:window.close()\'><img src=\'' + imgsrc + '\' border=\'0\' alt=\'\' title=\'' + closetext + '\'/></a>');
	
	
	mywin.document.writeln('<script language=\'javascript\' type=\'text/javascript\'>function resWin() { window.resizeTo(' + width + '+(' + width +  '-window.document.body.clientWidth), ' + height + '+(' + height + '-window.document.body.clientHeight));}</script>');
	mywin.document.writeln('</body></html>');
	mywin.onload = function() { mywin.resWin() }; 
	mywin.document.close(); 
	mywin.focus(); 
	
	return false;
	 
}

function popup( htmlsrc, width, height )
{	
	var widthpic = width;
	var heightpic = height;
	
	Fwindow=Math.round(Math.random() * 1000000);
	 
	if ( widthpic )
	{
		scrollbars	= ( heightpic ) ? "0" : "1";
		height		= ( heightpic ) ? height : 450;
		aFwindow = open(""+ htmlsrc + "",Fwindow,"width="+width+",height="+height+",location=no,menubar=no,toolbar=no,status=no,resizable=1,scrollbars="+scrollbars+",scrolling="+scrollbars+",dependent=yes,screenX=50,screenY=50");
	}
	else
	{
		aFwindow = open(""+ htmlsrc + "",Fwindow,"width=400,height=300,location=no,menubar=yes,toolbar=no,status=no,scrollbars=1,scrolling=1,resizable=1,dependent=yes,screenX=50,screenY=50");
	}

	aFwindow.focus();
}


var d = document;
var _CI = null;
var _arrowGif 		= '<img class="subnav" src="lib/arrow.gif" />';
var _count 				= 0;
var _lvl1Offset 	= 130;
var _hideTimeOut 	= null;
var _hideDelay 	= 750;
var _itemList		= new Array();
var _showDelay 	= 250;
var _smOffset 		= 3;


function ActionItem(item, P, isMain, idSub, O)
{
	_itemList[_itemList.length] = item;
	var index = _itemList.length - 1;
	idSub =(!idSub) ? 'null' :('\'' + idSub + '\'');
	O = '\'' + O + '\'';
	P = '\'' + P + '\'';
	return ' onmouseover="Over(this,' + P + ',' + isMain + ',' + idSub + ',' + O + ',' + index + ')" onmouseout="Out(this,' + _hideDelay + ')" ';
}

function Draw(menu, O, P)
{
	var P =(P != null) ? P : '';
	var str = '<div class="'+ P +'M">';
	var strSub = '';
	if(!O) O = 'hbr';
	var OStr = String(O);
	var OSub = 'v' + OStr.substr(1, 2);
	var item, idSub, hasChild;

	for(var i = 0; i < menu.length; ++i)
	{
		item = menu[i];
		if(!item) continue;
		if (d.URL.match("/"+item[2])){
		str += '<a href="'+ item[2] +'" title="'+ item[4] +'" class="'+ P +'lvl1a"';
		}
		else
		{
		str += '<a href="'+ item[2] +'" title="'+ item[4] +'" class="'+ P +'lvl1"';
		}
		hasChild =(item.length > 5);
		idSub = hasChild ? '_' +(++_count) : null;
		str += ActionItem(item, P, 1, idSub, O ) + '>';
		str += item[1];
		str += '</a>';
		if(hasChild) strSub += DrawSM(item, P, idSub, OSub );
	}
	d.write( str + strSub + '</div>' );
}

function DrawSM(sm, P, id, O )
{
	var str = '<div class="'+ P +'SM" id="' + id + '">';
	var strSub = '';
	var item, idSub, hasChild;

	for(var i = 5; i < sm.length; ++i)
	{
		item = sm[i];
		if(!item) continue;
		hasChild =(item.length > 5);
		idSub = hasChild ? '_' + (++_count) : null;
		str += '<a href="'+ item[2] +'" title="'+  item[4]  +'" class="'+ P +'lvl2"' + ActionItem(item, P, 0, idSub, O ) + '>';
		if(hasChild)
		{
			str += _arrowGif;
			strSub += DrawSM(item, P, idSub, O);
		}
		str += item[1];
		str += '</a>';
	}
	str += '</div>' + strSub;
	return str;
}

function Over(o, P, isMain, idSub, O, index)
{
	clearTimeout(_hideTimeOut);


	if(!o.Prefix)
	{
		o.Prefix = P;
		o.IsMain = isMain;
	}

	var thisM = GetThisM(o, P);
	if(!thisM.Items) thisM.Items = new Array();
	for(var i = 0; i < thisM.Items.length; ++i)
	{
		if(thisM.Items[i] == o) break;
	}
	if(i == thisM.Items.length)
	{
		thisM.Items[i] = o;
	}

	if(_CI)
	{
		if(_CI == thisM) return;

		var thatPrefix = _CI.Prefix;
		var thatM = GetThisM(_CI, thatPrefix);
		if(thatM != thisM.PM)
		{
			if(thatM.id != idSub) HideM(thatM, thisM, thatPrefix);
		}
	}

	_CI = o;

	var item = _itemList[index];

	if(idSub)
	{
		var sm = d.getElementById(idSub);
		ShowSM(o, P, sm, O);
	}
}

function Out(o, delayTime)
{
	if(!delayTime) delayTime = _hideDelay;
	_hideTimeOut = window.setTimeout('HideMTime()', delayTime);
}


function MoveSM(o, sm, O)
{
	var mode = String(O);
	if(mode.charAt(0) == 'h')
	{
		if( o.IsMain )
		{
			sm.style.top = _lvl1Offset + 'px';
		}
		else
		{
			if(mode.charAt(1) == 'b') sm.style.top =(GetY(o) + o.offsetHeight) + 'px';
			else sm.style.top =(GetY(o) - sm.offsetHeight) + 'px';	
		}
		if(mode.charAt(2) == 'r') sm.style.left =(GetX(o)) + 'px';
		else sm.style.left =(GetX(o) + o.offsetWidth - sm.offsetWidth) + 'px';
	}
	else
	{
		if(mode.charAt(2) == 'r') sm.style.left =(GetX(o) + o.offsetWidth) + 'px';
		else sm.style.left =(GetX(o) - sm.offsetWidth) + 'px';
		if(mode.charAt(1) == 'b')sm.style.top =(GetY(o)) + 'px';
		else sm.style.top =(GetY(o) + o.offsetHeight - sm.offsetHeight) + 'px';
	}
}

function ShowSM(o, P, sm, O)
{
	if(!sm.PM)
	{
		var thisM = GetThisM(o, P);
		sm.PM = thisM;
		if(!thisM.SM) { thisM.SM = new Array(); }
		thisM.SM[thisM.SM.length] = sm;
	}

	MoveSM(o, sm, O);

	sm.style.visibility = "visible";

	if(d.all)
	{
		sm.Overlap = new Array();
		// IFRAME?, OBJECT?
		HideControl("SELECT", sm);
	}
}

function HideMTime()
{
	if(_CI)
	{
		var P = _CI.Prefix;
		HideM(GetThisM(_CI, P), null, P);
	}
}

function HideM(thisM, currentM, P)
{
	var str = P + 'SM';
	if(thisM.SM)
	{
		for(var i = 0; i < thisM.SM.length; ++i)
		{
			HideSM(thisM.SM[i], P);
		}
	}

	while(thisM && thisM != currentM)
	{
		if(thisM.className == str)
		{
			thisM.style.visibility = 'hidden';
			ShowControl(thisM);
		}
		else break;
		thisM = GetThisM(thisM.PM, P);
	}
}

function HideSM(thisM, P)
{
	if(thisM.style.visibility == 'hidden') return;
	if(thisM.SM)
	{
		for(var i = 0; i < thisM.SM.length; ++i)
		{
			HideSM(thisM.SM[i], P);
		}
	}
	thisM.style.visibility = 'hidden';
	ShowControl(thisM);
}

function HideControl(tagName, sm)
{
	var x = GetX(sm);
	var y = GetY(sm);
	var w = sm.offsetWidth;
	var h = sm.offsetHeight;

	for(var i = 0; i < d.all.tags(tagName).length; ++i)
	{
		var o = d.all.tags(tagName)[i];
		if(!o || !o.offsetParent) continue;

		var ox = GetX(o);
		var oy = GetY(o);
		var ow = o.offsetWidth;
		var oh = o.offsetHeight;

		if(ox >(x + w) ||(ox + ow) < x) continue;
		if(oy >(y + h) ||(oy + oh) < y) continue;
		sm.Overlap[sm.Overlap.length] = o;
		o.style.visibility = "hidden";
	}
}

function ShowControl(sm)
{
	if(sm.Overlap)
	{
		var i;
		for(i = 0; i < sm.Overlap.length; ++i)
			sm.Overlap[i].style.visibility = "";
	}
	sm.Overlap = null;
}

function GetThisM(o, P)
{
	var str1 = P + 'SM';
	var str2 = P + 'M';
	while(o)
	{
		if(o.className == str1 || o.className == str2)
			return o;
		o = o.parentNode;
	}
	return null;
}

function GetX(o)
{
	var x = 0;
	do
	{
		x += o.offsetLeft;
		o = o.offsetParent;
	}
	while(o);
	return x;
}

function GetY(o)
{
	var y = 0;
	do
	{
		y += o.offsetTop;
		o = o.offsetParent;
	}
	while(o);
	
	return y + _smOffset;
}



/*
 * FlashObject embed
 * http://blog.deconcept.com/2004/10/14/web-standards-compliant-javascript-flash-detect-and-embed/
 *
 * by Geoff Stearns (geoff@deconcept.com, http://www.deconcept.com/)
 *
 * v1.0.7 - 11-17-2004
 *
 * Create and write a flash movie to the page, includes detection
 *
 * Usage:
 *
 *	myFlash = new FlashObject("path/to/swf.swf", "swfid", "width", "height", flashversion, "backgroundcolor");
 *	myFlash.altTxt = "Upgrade your Flash Player!";                // optional
 *	myFlash.addParam("wmode", "transparent");                     // optional
 *	myFlash.addVariable("varname1", "varvalue");                  // optional
 *	myFlash.addVariable("varname2", getQueryParamValue("myvar")); // optional
 *	myFlash.write();
 *
 */

FlashObject = function(swf, id, w, h, ver, c) {
	this.swf = swf;
	this.id = id;
	this.width = w;
	this.height = h;
	this.version = ver || 6; // default to 6
	this.align = "middle"; // default to middle
	this.redirect = "";
	this.sq = document.location.search.split("?")[1] || "";
	this.altTxt = "Please <a href='http://www.macromedia.com/go/getflashplayer'>upgrade your Flash Player</a>.";
	this.bypassTxt = "<p>Already have Flash Player? <a href='?detectflash=false&"+ this.sq +"'>Click here if you have Flash Player "+ this.version +" installed</a>.</p>";
	this.params = new Object();
	this.variables = new Object();
	if (c) this.color = this.addParam('bgcolor', c);
	this.addParam('quality', 'high'); // default to high
	this.doDetect = getQueryParamValue('detectflash');
}

FlashObject.prototype.addParam = function(name, value) {
	this.params[name] = value;
}

FlashObject.prototype.getParams = function() {
    return this.params;
}

FlashObject.prototype.getParam = function(name) {
    return this.params[name];
}

FlashObject.prototype.addVariable = function(name, value) {
	this.variables[name] = value;
}

FlashObject.prototype.getVariable = function(name) {
    return this.variables[name];
}

FlashObject.prototype.getVariables = function() {
    return this.variables;
}

FlashObject.prototype.getParamTags = function() {
    var paramTags = "";
    for (var param in this.getParams()) {
        paramTags += '<param name="' + param + '" value="' + this.getParam(param) + '" />';
    }
    if (paramTags == "") {
        paramTags = null;
    }
    return paramTags;
}

FlashObject.prototype.getHTML = function() {
    var flashHTML = "";
    if (window.ActiveXObject && navigator.userAgent.indexOf('Mac') == -1) { // PC IE
        flashHTML += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + this.width + '" height="' + this.height + '" id="' + this.id + '" align="' + this.align + '">';
        flashHTML += '<param name="movie" value="' + this.swf + '" />';
        if (this.getParamTags() != null) {
            flashHTML += this.getParamTags();
        }
        if (this.getVariablePairs() != null) {
            flashHTML += '<param name="flashVars" value="' + this.getVariablePairs() + '" />';
        }
        flashHTML += '</object>';
    }
    else { // Everyone else
        flashHTML += '<embed type="application/x-shockwave-flash" src="' + this.swf + '" width="' + this.width + '" height="' + this.height + '" id="' + this.id + '" align="' + this.align + '"';
        for (var param in this.getParams()) {
            flashHTML += ' ' + param + '="' + this.getParam(param) + '"';
        }
        if (this.getVariablePairs() != null) {
            flashHTML += ' flashVars="' + this.getVariablePairs() + '"';
        }
        flashHTML += '></embed>';
    }
    return flashHTML;	
}


FlashObject.prototype.getVariablePairs = function() {
    var variablePairs = new Array();
    for (var name in this.getVariables()) {
        variablePairs.push(name + "=" + escape(this.getVariable(name)));
    }
    if (variablePairs.length > 0) {
        return variablePairs.join("&");
    }
    else {
        return null;
    }
}

FlashObject.prototype.write = function(elementId) {

	if(detectFlash(this.version) || this.doDetect=='false') {
		if (elementId) {
			document.getElementById(elementId).innerHTML = this.getHTML();
		} else {
			document.write(this.getHTML());
		}
	} else {
		if (this.redirect != "") {
			document.location.replace(this.redirect);
		} else {
			if (elementId) {
				document.getElementById(elementId).innerHTML = this.altTxt +""+ this.bypassTxt;
			} else {
				document.write(this.altTxt +""+ this.bypassTxt);
			}
		}
	}		
}

function getFlashVersion() {
	var flashversion = 0;
	if (navigator.plugins && navigator.plugins.length) {
		var x = navigator.plugins["Shockwave Flash"];
		if(x){
			if (x.description) {
				var y = x.description;
	   			flashversion = y.charAt(y.indexOf('.')-1);
			}
		}
	} else {
		result = false;
	    for(var i = 15; i >= 3 && result != true; i--){
   			execScript('on error resume next: result = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.'+i+'"))','VBScript');
   			flashversion = i;
   		}
	}
	return flashversion;
}

function detectFlash(ver) {	
	if (getFlashVersion() >= ver) {
		return true;
	} else {
		return false;
	}
}

// get value of querystring param
function getQueryParamValue(param) {
	var q = document.location.search;
	var detectIndex = q.indexOf(param);
	var endIndex = (q.indexOf("&", detectIndex) != -1) ? q.indexOf("&", detectIndex) : q.length;
	if(q.length > 1 && detectIndex != -1) {
		return q.substring(q.indexOf("=", detectIndex)+1, endIndex);
	} else {
		return "";
	}
}

/* add Array.push if needed */
if(Array.prototype.push == null){
	Array.prototype.push = function(item){
		this[this.length] = item;
		return this.length;
	}
}