var d = d || document; // document shorthand alias




var g_hC							= g_hC || {};
var hGraphicsSettings		= hGraphicsSettings || {};
var g_hCache					= g_hCache || {};
var g_hDocumentReferences	= g_hDocumentReferences || {};




/*
	old functions above this point, oo replacements below

	MfcGraphics
*/


function MfcGraphics( hConstructorOptions )
{
	// merge global config and constructor options into a setting assoc array

	this.hCache = {};

	this.oSelf = this;

	var g_hC = g_hC || {};

	this.hSettings = {};

	for( sK in g_hC )
	{
		this.hSettings[sK] = g_hC[sK];
	}

	if( hConstructorOptions )
	{
		for( sK in hConstructorOptions )
		{
			this.hSettings[sK] = hConstructorOptions[sK];
		}
	}


	this.load_style();
}

MfcGraphics.prototype.load_style = function()
{
	var sStyle = 'mfc';

	if( this.hSettings['no_style'] )
		return;

	this.hSettings['style_path'] = "http://www.myfreecams.com/mfc2/styles/"+sStyle+"/";
	this.hSettings['img_path'] = "http://img.myfreecams.com/mfc2/styles/"+sStyle+"/";

//	this.load_style_execute();
//};
//	
//MfcGraphics.prototype.load_style_execute = function()
//{

//	if( this.hSettings['no_style'] )
//		return;

	var oCssNode = document.createElement('link');
	oCssNode.type = 'text/css';
	oCssNode.rel = 'stylesheet';
	oCssNode.href = '/mfc2/lib/style.css?1';
	oCssNode.media = 'screen';
	document.getElementsByTagName("head")[0].appendChild(oCssNode);

	var oCssNode = document.createElement('link');
	oCssNode.type = 'text/css';
	oCssNode.rel = 'stylesheet';
	oCssNode.href = this.hSettings['style_path'] + "style.css?1";
	oCssNode.media = 'screen';
	document.getElementsByTagName("head")[0].appendChild(oCssNode);
};

MfcGraphics.prototype.container = function( sOptions, sContent )
{
	if( location.search.match(/nocontainers/) )
		return;

	// merge object settings and passed in string of options into an assoc array of options
	var hOptions = {};
	for( sK in this.hSettings ) { hOptions[sK] = this.hSettings[sK]; }

	aOptions = sOptions.match(/\w+/g);
	for( n=0; n < aOptions.length; n++ )
	{
		hOptions[ aOptions[n] ] = true;
	}

	var sDimensions="";
	var sExtraContentStyle="";
	var sExtraContentClass="";

	if(hOptions['menu_container'])					sContainer = 'menu_container';
	else if(hOptions['input_container'])			sContainer = 'input_container';
	else if(hOptions['sub_content_container'])	sContainer = 'sub_content_container';
	else if(hOptions['alt_content_container'])	sContainer = 'alt_content_container';
	else if(hOptions['content_container']) 		sContainer = 'content_container';
	else if(hOptions['popup_container'])	 		sContainer = 'popup_container';
	else														sContainer = 'container';

	var bIsFramed=0;
	try
	{
		if( top.location.href != window.location.href )
		{
			bIsFramed = 1;
		}
	}
	catch( oError )
	{
		bIsFramed = 1;
	}

	// special exception code, use profile style 
	if( 
		bIsFramed
		&& location.href.indexOf('/top') == -1
		&& location.href.indexOf('/player') == -1
		&& ! hOptions['no_override']
	)
	{
		if(sContainer == 'menu_container')
		{
			sContainer = 'alt_content_container';
		}
		else if(sContainer == 'input_container')
		{
			return;
		}
		
		hOptions['container_class_only'] = 1;
		document.body.style.margin = '0px';
		document.body.className = 'inner_body';
	}
	// special exception code, overide styles if embeded in MFC feature frame
	else if( 
		! opener
		&& parent
	)
	{
		var nEmbed = 0;
		try
		{
			if(
				top.location.href.match(/profiles.myfreecams.com/)
				&& (
					parent.location.href != location.href
					|| parent.name == 'top_level'
				)
			)
			{
				nEmbed = 1;
			}
		}
		catch(oError)
	 	{
			nEmbed = 1;
		}

		try
		{
			if( nEmbed )
			{
				hOptions['no_style'] = 1;

				if(sContainer == 'container')
				{
					sContainer = 'content_container';
				}
				else if(sContainer == 'input_container')
				{
					return;
				}
			
				sOptions += ' ' + sContainer;		
				document.body.className = 'inner_body';
			}
		}
		catch(oError)
		{
		}
	}

	if( ! sContent && this.hCache[sOptions] )
	{
		return this.hCache[sOptions];
	}

	if( hOptions['expanded'] )
	{
		sDimensions = " height=100% width=100% ";
		sExtraContentStyle	= "font-size:13px;";
	}
	else if( hOptions['contracted'] || hOptions['input_container'] )
	{
		sDimensions = " ";
		sExtraContentStyle	= "font-size:1px;";
	}
	else
	{
		sDimensions = " width=100% ";
		sExtraContentStyle	= "font-size:13px;";
	}

	if(sExtraContentClass)
	{
		sExtraContentClass = " class='" + sExtraContentClass + "'";
	}

	var sTop='',sBottom='',sStyleDivs='';

	if ( hOptions['container_class_only'] )
	{
		sTop = "\
			<div class=" + sContainer + ">\
				<div class=" + sContainer + "_table_td>\
		";
		sBottom = "\
				</div>\
			</div>\
		";
	}
	else if ( hOptions['stylesheet'] || hOptions['no_style'] )
	{
		sTop = "\
			<div class=container_padding>\
				<div class=container_transparency >\
					<div class=container >\
		";
		sBottom = "\
					</div>\
				</div>\
			</div>\
		";
	}
	//else if( navigator.userAgent.match(/Firefox|Chrome|Safari/) )
	else if( ! navigator.userAgent.match(/MSIE/) )
	{
		sTop = "\
			<table cellpadding=0 cellspacing=0 " + sDimensions + " border=0>\n\
			 <td class='" + sContainer + "_wrapper'>\n\
				<table class='" + sContainer + "_table' " + sDimensions + " cellpadding=0 cellspacing=0 border=0>\
					<td class='" + sContainer + " " + sContainer + "_css3 " + sContainer + "_table_td " + sContainer + "_outer_content "+sExtraContentClass+"' valign=top style=\"" + sExtraContentStyle + "\">\
		";

		sBottom = "\
			 	 </td>\
				</table>\
		 	 </td>\
			</table>\
		";
	} 
	else 
	{
		sTop = "\n\
			<table cellpadding=0 cellspacing=0 " + sDimensions + " border=0>\n\
			 <td class='" + sContainer + "_wrapper'>\n\
				<table class='" + sContainer + "_table' " + sDimensions + " cellpadding=0 cellspacing=0 border=0 width=100%>\n\
				 <tr>\n\
				  <td colspan=2 class='graphic " + sContainer + "_table_td " + sContainer + "_l' valign=top align=left style=\"background-image:url('" + hOptions['img_path'] + "/images/" + sContainer + "/t.gif'); \"><i" + "mg class=" + sContainer + "_img_tl src=\"" + hOptions['img_path'] + "/images/" + sContainer + "/tl.gif\"></td>\n\
				  <td rowspan=2 class='graphic " + sContainer + "_table_td graphic " + sContainer + "_t' valign=top align=right style=\"background:url('" + hOptions['img_path'] + "/images/" + sContainer + "/r.gif') repeat-y scroll top right;\"><i" + "mg class=" + sContainer + "_img_tr src=\"" + hOptions['img_path'] + "/images/" + sContainer + "/tr.gif\"></td>\n\
				 </tr>\n\
				 <tr>\n\
				  <td rowspan=2 class='graphic " + sContainer + "_table_td " + sContainer + "_l' valign=bottom align=left\n\
						style=\"background:url('" + hOptions['img_path'] + "/images/" + sContainer + "/l.gif') repeat-y scroll bottom left;vertical-align:bottom;\"><i" + "mg class=" + sContainer + "_img_bl src=\"" + hOptions['img_path'] + "/images/" + sContainer + "/bl.gif\"></td>\n\
				  <td height=100% width=100%\
						class='" + sContainer + " " + sContainer + "_table_td " + sContainer + "_outer_content "+sExtraContentClass+"'\
						valign=top style=\"" + sExtraContentStyle + "\">";
	
		sBottom = "</td>\n\
				 </tr>\n\
				 <tr>\n\
				  <td colspan=2 class='graphic " + sContainer + "_table_td " + sContainer + "_b' valign=bottom align=right\n\
						style=\"background:url('" + hOptions['img_path'] + "/images/" + sContainer + "/b.gif') repeat-x scroll bottom right;\"><i" + "mg class=" + sContainer + "_img_br src=\"" + hOptions['img_path'] + "/images/" + sContainer + "/br.gif\"></td>\n\
				 </tr>\n\
				</table>\n\
			 </td>\n\
			</table>\n\
		";
	}

	var sH = "";
	if( hOptions['top'] )
	{
		sH = sTop;
	}
	else if( hOptions['bottom'] )
	{
		sH = sBottom;
	}
	else
	{
		sH = sTop + sContent + sBottom;
	}

	this.hCache[sOptions] = sH;

	return sH;
};

MfcGraphics.prototype.heading = function(sText,sIcon,hOptions)
{
	var sIconHtml = '';

	if( sIcon )
	{
		var sImagePath = '';
		if( sIcon.indexOf('ico/') > -1 )
		{
			sImagePath = "http://graphics.myfreecams.com/";
		}	
		else
		{
			sImagePath = "http://img.myfreecams.com/mfc2/images/icons/";
		}

		sIconHtml = "<div class=icon>";
		if( hOptions && hOptions['link'] )
		{
			sIconHtml += hOptions['link'];
		}
	
		sIconHtml += "<i" + "mg src=\"" + sImagePath + sIcon + "\"></a></div>";
	}

	sH = "\
		<div class=heading style=\"border:0px dashed gray;\">\
			" + sIconHtml + "\
			<div class=text> " + sText + " </div>\
		</div>\
	";

	return sH;
};


