/*******************************************************************************
*  mtstudios_utilities.js : 22.06.2005
* -----------------------------------------------------------------------------
*  A group of useful JavaScript utilities that can aid in the development
*  of webpages.
*******************************************************************************/


/**
* SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
*
* SWFObject is (c) 2006 Geoff Stearns and is released under the MIT License:
* http://www.opensource.org/licenses/mit-license.php
*
*/
if(typeof deconcept=="undefined"){var deconcept=new Object();}if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a){if(!document.getElementById){return;}this.DETECT_KEY=_a?_a:"detectflash";this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);this.params=new Object();this.variables=new Object();this.attributes=new Array();if(_1){this.setAttribute("swf",_1);}if(id){this.setAttribute("id",id);}if(w){this.setAttribute("width",w);}if(h){this.setAttribute("height",h);}if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();if(!window.opera&&document.all&&this.installedVer.major>7){deconcept.SWFObject.doPrepUnload=true;}if(c){this.addParam("bgcolor",c);}var q=_7?_7:"high";this.addParam("quality",q);this.setAttribute("useExpressInstall",false);this.setAttribute("doExpressInstall",false);var _c=(_8)?_8:window.location;this.setAttribute("xiRedirectUrl",_c);this.setAttribute("redirectUrl","");if(_9){this.setAttribute("redirectUrl",_9);}};deconcept.SWFObject.prototype={useExpressInstall:function(_d){this.xiSWFPath=!_d?"expressinstall.swf":_d;this.setAttribute("useExpressInstall",true);},setAttribute:function(_e,_f){this.attributes[_e]=_f;},getAttribute:function(_10){return this.attributes[_10];},addParam:function(_11,_12){this.params[_11]=_12;},getParams:function(){return this.params;},addVariable:function(_13,_14){this.variables[_13]=_14;},getVariable:function(_15){return this.variables[_15];},getVariables:function(){return this.variables;},getVariablePairs:function(){var _16=new Array();var key;var _18=this.getVariables();for(key in _18){_16.push(key+"="+_18[key]);}return _16;},getSWFHTML:function(){var _19="";if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");this.setAttribute("swf",this.xiSWFPath);}_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\"";_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";var _1a=this.getParams();for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}var _1c=this.getVariablePairs().join("&");if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");this.setAttribute("swf",this.xiSWFPath);}_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\">";_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";var _1d=this.getParams();for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}var _1f=this.getVariablePairs().join("&");if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}return _19;},write:function(_20){if(this.getAttribute("useExpressInstall")){var _21=new deconcept.PlayerVersion([6,0,65]);if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){this.setAttribute("doExpressInstall",true);this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));document.title=document.title.slice(0,47)+" - Flash Player Installation";this.addVariable("MMdoctitle",document.title);}}if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){var n=(typeof _20=="string")?document.getElementById(_20):_20;n.innerHTML=this.getSWFHTML();SWFFormFix(this.getAttribute("id"));return true;}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}return false;}};deconcept.SWFObjectUtil.getPlayerVersion=function(){var _23=new deconcept.PlayerVersion([0,0,0]);if(navigator.plugins&&navigator.mimeTypes.length){var x=navigator.plugins["Shockwave Flash"];if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}return _23;};deconcept.PlayerVersion=function(_27){this.major=_27[0]!=null?parseInt(_27[0]):0;this.minor=_27[1]!=null?parseInt(_27[1]):0;this.rev=_27[2]!=null?parseInt(_27[2]):0;};deconcept.PlayerVersion.prototype.versionIsValid=function(fv){if(this.major<fv.major){return false;}if(this.major>fv.major){return true;}if(this.minor<fv.minor){return false;}if(this.minor>fv.minor){return true;}if(this.rev<fv.rev){return false;}return true;};deconcept.util={getRequestParameter:function(_29){var q=document.location.search||document.location.hash;if(q){var _2b=q.substring(1).split("&");for(var i=0;i<_2b.length;i++){if(_2b[i].substring(0,_2b[i].indexOf("="))==_29){return _2b[i].substring((_2b[i].indexOf("=")+1));}}}return "";}};deconcept.SWFObjectUtil.cleanupSWFs=function(){var _2d=document.getElementsByTagName("OBJECT");for(var i=_2d.length;i>0;i--){_2d[i].style.display="none";for(var x in _2d[i]){if(typeof _2d[i][x]=="function"){_2d[i][x]=function(){};}}}};if(deconcept.SWFObject.doPrepUnload){deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};window.attachEvent("onunload",deconcept.SWFObjectUtil.cleanupSWFs);};window.attachEvent("onbeforeunload",deconcept.SWFObjectUtil.prepUnload);}if(Array.prototype.push==null){Array.prototype.push=function(_30){this[this.length]=_30;return this.length;};}var getQueryParamValue=deconcept.util.getRequestParameter;var FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;
/* 
* SWFFormFix 1.0.0 added by Steve Kamerman (kamerman at teratechnologies.net)
* This fixes a known bug with Flash 8's ExternalInterface() class being used
* inside of an HTML Form in Internet Explorer 5,5.5,6,7.
* This script will make an alias for IE to correctly identify the newly created
* SWF Object.
*
* For more information, please visit my blog at http://www.teratechnologies.net/stevekamerman/index.php?category=8
*/
SWFFormFix=function(swfname){if(navigator.appName.toLowerCase()!="microsoft internet explorer")return false;var testnodename="SWFFormFixTESTER";document.write('<div id="'+testnodename+'" onclick="SWFFormFixCallback(this,\''+swfname+'\');return false;" style="display:none">&nbsp;</div>');document.getElementById(testnodename).onclick();};SWFFormFixCallback=function(obj,swfname){var path = document;var error=false;var testnode=obj;while(obj=obj.parentNode){if(obj.nodeName.toLowerCase()=="form"){if(obj.name!=undefined&&obj.name!=null&&obj.name.length>0){path=path.forms[obj.name];}else{alert("Error: one of your forms does not have a name!");error=true;}}};testnode.parentNode.removeChild(testnode);if(error)return false;window[swfname]=path[swfname];return true;};



/* event_attach() takes care of attaching event handlers (functions) to events. this 
 * simplifies the process of attaching multiple handlers to a single event
 */
function event_attach( event , func )
{
	if ( window.attachEvent )
	{
		window.attachEvent( event , func );
	}
	else
	{
		if ( ( typeof( func ) ).toLowerCase() != 'function' )
		{
			return;
		}
		if ( ( typeof( document.event_handlers ) ).toLowerCase() == 'undefined' )
		{
			document.event_handlers = new Array();
		}
		if ( ( typeof( document.event_handlers[ event ] ) ).toLowerCase() == 'undefined' )
		{
			document.event_handlers[ event ] = new Array();
		}
		if ( ( typeof( eval( 'window.' + event ) ) ).toLowerCase() != 'function' )
		{
			eval( 'window.' + event + ' = function () { if ( ( typeof( document.event_handlers[ \'' + event + '\' ] ) ).toLowerCase() != \'undefined\' ) { for ( i = 0 ; i < document.event_handlers[ \'' + event + '\' ].length ; i++ ) { document.event_handlers[ \'' + event + '\' ][ i ](); } } } ' );
		}
		document.event_handlers[ event ][ document.event_handlers[ event ].length ] = func;
	}
}

/* browser_detect() creates a simple object that can be used to determine what
 * browser the client is using. this is useful in many areas.
 */
function browser_detect() 
{
	var ua			= navigator.userAgent.toLowerCase(); 
	this.ua			= ua;
	this.isGecko		= ( ua.indexOf( 'gecko' ) != -1 );
	this.isMozilla		= ( this.isGecko && ua.indexOf( "gecko/" ) + 14 == ua.length);
	this.isIE		= ( ( ua.indexOf( "msie" ) != -1 ) && ( ua.indexOf( "opera" ) == -1) && ( ua.indexOf( "webtv" ) == -1 ) );
	this.isOpera		= ( ua.indexOf( "opera" ) != -1 );
	this.isKonqueror	= ( ua.indexOf( "konqueror" ) != -1 );
	this.isIcab		= ( ua.indexOf( "icab" ) != -1 );
	this.isAol		= ( ua.indexOf( "aol" ) != -1 );
	this.isWebtv		= ( ua.indexOf( "webtv" ) != -1 );
	this.isOmniweb		= ( ua.indexOf( "omniweb" ) != -1 );
	this.isDreamcast	= ( ua.indexOf( "dreamcast" ) != -1 );
	this.versionMinor	= parseFloat( navigator.appVersion );
	if ( this.isNS && this.isGecko ) 
	{
		this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf( '/' ) + 1 ) );
	} 
	else if ( this.isIE && this.versionMinor >= 4 ) 
	{
		this.versionMinor = parseFloat( ua.substring( ua.indexOf( 'msie ' ) + 5 ) );
	} 
	else if ( this.isOpera ) 
	{
		if ( ua.indexOf( 'opera/' ) != -1 ) 
		{
			this.versionMinor = parseFloat( ua.substring( ua.indexOf( 'opera/' ) + 6 ) );
		}
		else 
		{
			this.versionMinor = parseFloat( ua.substring( ua.indexOf( 'opera ' ) + 6 ) );
		}
	} 
	else if ( this.isKonqueror ) 
	{
		this.versionMinor = parseFloat( ua.substring( ua.indexOf( 'konqueror/' ) + 10 ) );
	} 
	else if ( this.isIcab ) 
	{
		if ( ua.indexOf( 'icab/' ) != -1 ) 
		{
			this.versionMinor = parseFloat( ua.substring( ua.indexOf( 'icab/' ) + 6 ) );
		}
		else 
		{
			this.versionMinor = parseFloat( ua.substring( ua.indexOf( 'icab ' ) + 6 ) );
		}
	} 
	else if ( this.isWebtv )
	{
		this.versionMinor = parseFloat( ua.substring( ua.indexOf( 'webtv/' ) + 6 ) );
	}
	this.versionMajor	= parseInt( this.versionMinor ); 
	this.isWin		= ( ua.indexOf( 'win' ) != -1 );
	this.isWin32		= ( this.isWin && ( ua.indexOf( '95' ) != -1 || ua.indexOf( '98' ) != -1 || ua.indexOf( 'nt' ) != -1 || ua.indexOf( 'win32' ) != -1 || ua.indexOf( '32bit' ) != -1 ) );
	this.isMac		= ( ua.indexOf( 'mac' ) != -1 );
	this.isUnix		= ( ua.indexOf( 'unix' ) != -1 || ua.indexOf( 'linux' ) != -1 || ua.indexOf( 'sunos' ) != -1 || ua.indexOf( 'bsd' ) != -1 || ua.indexOf( 'x11' ) != -1 );
	this.isIE55		= ( this.isIE && this.versionMinor == 5.5 );
	this.isIE5up		= ( this.isIE && this.versionMajor >= 5 );
	this.isIE6up		= ( this.isIE && this.versionMajor >= 6 );
}

/* opacity() will enable PNG transparency for Internet Explorer
 */
function opacity( strId , strPath , intWidth , intHeight , strClass , strAlt )
{	
	if ( document.pngAlpha )
	{
		document.write( '<div style="height:'+intHeight+'px;width:'+intWidth+'px;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+strPath+'.png\', sizingMethod=\'scale\')" id="'+strId+'" class="'+strClass+'"></div>' );
	}
	else if ( document.pngNormal )
	{
		document.write( '<img src="'+strPath+'.png" width="'+intWidth+'" height="'+intHeight+'" name="'+strId+'" border="0" class="'+strClass+'" alt="'+strAlt+'" />' );
	}
	else if ( document.layers )
	{
		return( '<img src="'+strPath+'.gif" width="'+intWidth+'" height="'+intHeight+'" name="'+strId+'" border="0" class="'+strClass+'" alt="'+strAlt+'" />' );
	}
	else
	{
		document.write( '<img src="'+strPath+'.gif" width="'+intWidth+'" height="'+intHeight+'" name="'+strId+'" border="0" class="'+strClass+'" alt="'+strAlt+'" />' );
	}
	return( '' );
}

/* opacity_init() handles some variable initializations required for opacity() to function
 */
function opacity_init()
{
	var browser = new browser_detect();
	document.pngAlpha = false;
	document.pngNormal = false;
	document.strExt = ".gif";

	if ( ( browser.isIE55 || browser.isIE6up ) && browser.isWin32 )
	{
		document.pngAlpha = true;
		document.strExt = ".png";
	}
	else if ( 
			( browser.isGecko ) || 
			( browser.isIE5up && browser.isMac ) || 
			( browser.isOpera && browser.isWin && browser.versionMajor >= 6 ) || 
			( browser.isOpera && browser.isUnix && browser.versionMajor >= 6 ) || 
			( browser.isOpera && browser.isMac && browser.versionMajor >= 5 ) || 
			( browser.isOmniweb && browser.versionMinor >= 3.1 ) || 
			( browser.isIcab && browser.versionMinor >= 1.9 ) || 
			( browser.isWebtv ) || 
			( browser.isDreamcast ) 
		)
	{
		document.pngNormal = true;
		document.strExt = ".png";
	}
}

/* handler for Netscape Navigator clients that screw up the display
 * of CSS pages when reloaded
 */
function NN_reloadPage( init )
{
	if ( init == true ) with ( navigator )
	{
		if ( ( appName == "Netscape" ) && ( parseInt ( appVersion ) == 4 ) )
		{
			document.NN_pgW = innerWidth;
			document.NN_pgH = innerHeight;
			event_attach ( 'onresize' , NN_reloadPage );
		}
	}
	else if ( innerWidth != document.NN_pgW || innerHeight != document.NN_pgH )
	{
		location.reload();
	}
}

/* set_min_width_rs() takes a different approach to emulating min-width functionality
 */
function set_min_width_rs( element_id , min_width )
{
	if ( document.getElementById && navigator.appVersion.indexOf( "MSIE" ) > -1 && !window.opera )
	{
		document.mw_element_id = element_id;
		document.mw_min_width = min_width;
		event_attach( 'onload' , control_min_width_rs );
		event_attach( 'onresize' , control_min_width_rs );
	}
}

/* control_min_width_rs() is the event handler used by set_min_width_rs. This method fixes a couple bugs with
 * the p7 approach that can lead to the browser crashing. This method specifically targets IE although perhaps
 * it could be modified to work with other browsers later.
 */
function control_min_width_rs()
{
	var e = document.getElementById( document.mw_element_id );
	var offset = parseInt( 0 + e.currentStyle.paddingLeft ) + parseInt( 0 + e.currentStyle.paddingRight ) + parseInt( 0 + e.currentStyle.borderLeftWidth ) + parseInt( 0 + e.currentStyle.borderRightWidth );

	if ( ( document.body.clientWidth - ( e.offsetLeft * 2 ) ) <= ( document.mw_min_width - offset ) && parseInt( 0 + e.style.width ) != document.mw_min_width )
		e.style.width = document.mw_min_width + "px";
	else if ( document.body.clientWidth > ( document.mw_min_width + offset + e.offsetLeft * 2 ) )
		e.style.width = "auto";
}

/* set_min_width() initializes min-width-like functionality
 */
function set_min_width( obj_name , min_width , ieOnly )
{

	if ( ( typeof( ieOnly ) ).toLowerCase() == 'undefined' )
	{
		ieOnly = true;
	}
	if ( ieOnly == false || ( document.getElementById && navigator.appVersion.indexOf( "MSIE" ) > -1 && !window.opera ) )
	{
		document.min_width_obj_name = obj_name;
		document.min_width_size = min_width;
		document.resizing = false;
		event_attach( 'onload' , control_min_width );
		event_attach( 'onresize' , control_min_width );
	}
}

/* control_min_width() is the event handler setup and used by set_min_width()
 * it is based on the Project Seven min-width code
 */
function control_min_width()
{

	var cw , w , pl , pr , ml , mr , br , bl , ad , theDiv = document.min_width_obj_name;
	var g = document.getElementById( theDiv );
	w = parseInt(document.min_width_size);
	if ( g && document.body && document.body.clientWidth )
	{
		gs = g.currentStyle;
		cw = parseInt( document.body.clientWidth );
		pl = parseInt( gs.paddingLeft );
		pr = parseInt( gs.paddingRight );
		ml = parseInt( gs.marginLeft );
		mr = parseInt( gs.marginRight );
		bl = parseInt( gs.borderLeftWidth );
		br = parseInt( gs.borderRightWidth );
		ml = ml ? ml : 0;
		mr = mr ? mr : 0;
		pl = pl ? pl : 0;
		pr = pr ? pr : 0;
		bl = bl ? bl : 0;
		br = br ? br : 0;
		ad = pl + pr + ml + mr + bl + br;
		if ( cw <= w )
		{
			w -= ad;
			g.style.width = w + "px";
		}
		else
		{
			g.style.width = "auto";
		}
	}
}

/* cookie functions, blatantly ripped off from some site i've since forgotten. sorry.
 */
function setCookie( name, value, expires, path, domain, secure )
{
	document.cookie= name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
}
function getCookie( name )
{
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf( "; " + prefix );
	if ( begin == -1 )
	{
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	}
	else
	{
		begin += 2;
	}
	var end = document.cookie.indexOf( ";", begin );
	if ( end == -1 )
	{
		end = dc.length;
	}
	return unescape(dc.substring(begin + prefix.length, end));
}
function deleteCookie( name, path, domain )
{
	if ( getCookie( name ) )
	{
		document.cookie = name + "=" + 
			((path) ? "; path=" + path : "") +
			((domain) ? "; domain=" + domain : "") +
			"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

/* minor accessibility deal here with font sizes
 * requires the following javascript to be executed:
 *
 *	var font_sizes = new Array( 80, 100, 120 ); 
 *	var current_font_size = 0;
 *	var _old_onload = null;
 *	old_onload = window.onload;
 *	window.onload = loadFontSize;
 */
function loadFontSize ()
{
	current_font_size = parseInt( '0' + getCookie ( "font_size" ) );
	setFontSize ( current_font_size );
	if ( _old_onload != null )
	{
		_old_onload();
	}
}
function setFontSize( size )
{
	if( size >= 0 && size < font_sizes.length )
	{
		current_font_size = size;
	}
	else if( ++current_font_size >= font_sizes.length )
	{
		current_font_size = 0;
	}
	if ( document.body )
	{
		document.body.style.fontSize = font_sizes[ current_font_size ] + '%';
		setCookie( "font_size" , current_font_size );
	}
}

function trim( str )
{
   return str.replace(/^\s*|\s*$/g,"");
}

