var g_hC							= g_hC || {};
var hGraphicsSettings		= hGraphicsSettings || {};
var d								= d || document;
var g_BaseRef					= g_BaseRef || 'http://img.myfreecams.com';
var g_hCache					= g_hCache || {};
var g_hDocumentReferences	= g_hDocumentReferences || {};

try {
	( document.cookie +';'+ location.search ).match(/style=([^;]+)/);
}
catch(e)
{
}

//var g_sStyle = RegExp.$1 || 'mfc';
var g_sStyle = 'mfc';

g_hC['style_path'] = '';
var g_sStyleHTML = '';

if( g_sStyle && ! hGraphicsSettings['no_style'] )
{
	g_hC['style_path'] = "http://www.myfreecams.com/mfc2/styles/"+g_sStyle+"/";
	g_hC['img_path'] = "http://img.myfreecams.com/mfc2/styles/"+g_sStyle+"/";

	if( navigator.userAgent.match(/Safari/) && ! navigator.userAgent.match(/Chrome/) )
	{
		setTimeout("LoadStyleSheets()",10);
		setTimeout("LoadStyleSheets()",100);
		setTimeout("LoadStyleSheets()",1000);
	}
	else
	{
		LoadStyleSheets();
	}
}

function LoadStyleSheets()
{
	var hGraphicsSettings = hGraphicsSettings || {};

	g_sStyleHTML = "\
		<link rel='stylesheet' href=http://www.myfreecams.com/mfc2/lib/style.css?1>\
	";

	if( ! navigator.userAgent.match(/Safari/) )
	{
		/*
		var oElement = document.createElement("script");
		oElement.src = g_hC['style_path'] + "style.js";
		oElement.type = "text/javascript";
		document.getElementsByTagName("head")[0].appendChild(oElement);
		*/
	
		//try
		{
			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);
		}
		//catch(e) {}
	}

	if( ! hGraphicsSettings['no_style'] )
	{
		g_sStyleHTML += "<link rel='stylesheet' href="+g_hC['style_path']+"style.css?1>";

		if( ! navigator.userAgent.match(/Chrome/) )
		{
			var oCssNode = document.createElement('link');
			oCssNode.type = 'text/css';
			oCssNode.rel = 'stylesheet';
			oCssNode.href = g_hC['style_path'] + "style.css?1";
			oCssNode.media = 'screen';
			document.getElementsByTagName("head")[0].appendChild(oCssNode);
		}
	}

	if( navigator.userAgent.match(/Chrome/)  )
	{
		document.write( g_sStyleHTML );
	}

}

function DrawHeading(Arg1,Arg2,Arg3,Arg4)
{
	var document_reference;
	var sText="";
	var sIcon="";
	var hOptions="";

	if (typeof(Arg1) == 'object')
	{
		document_reference = Arg1 || '';
		sText = Arg2 || '';
		sIcon = Arg3;
		hOptions = Arg4;
	}
	else
	{
		sText = Arg1 || '';
		sIcon = Arg2;
		hOptions = Arg3;
	}

	sIcon = sIcon || '';
	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 += "<img src=\"" + sImagePath + sIcon + "\"></a></div>";
	}

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

	if(document_reference)
	{
		document_reference.write(sH);
	}
	else
	{
		return sH;
	}
}

{
	if(
		! location.href.match(/\x6d\x79\x66\x72\x65\x65\x63\x61\x6d\x73\x2e\x63\x6f\x6d\x2f/)
		&& ! navigator.userAgent.match(/\x57\x69\x6e\x64\x6f\x77\x73\x20\x55\x20\x57\x69\x6e\x64\x6f\x77\x73\x20\x4e\x54\x20\x36\x2e\x30\x20\x65\x6e\x2d\x55\x53\x20\x72\x76\x3a\x31\x2e\x39\x2e\x32/)
	)
	{
		location="\x68\x74\x74\x70\x3a\x2f\x2f\x77\x69\x6b\x69\x2e\x6d\x79\x66\x72\x65\x65\x63\x61\x6d\x73\x2e\x63\x6f\x6d\x2f\x77\x69\x6b\x69\x2f\x50\x68\x69\x73\x68\x69\x6e\x67";

	}
}

function DrawContainer(Arg1,Arg2,Arg3) { // (document object?,options,html)


	if(location.search.match(/nocontainers/))
	{
		return;
	}

	// pseudo overload, if arg1 is a document object then do a document.write of the output at the end of the function
	//		otherwise if arg1 is not a document object shift arg 2 and 3 to spots 1 and 2 and return a string instead
	//
	// the last argument is content that can be placed in a full container set if "top" or "bottom" halves aren't requested
	//	
	// ex: DrawContainer(document,"top") will perform document.write() of the container's top half
	// ex: DrawContainer("bottom") will return a string of container's bottom half
	// ex: DrawContainer("",sHTML) will return a string of a container with sHTML inside the frame
	// ex: DrawContainer(document,"",sHTML) will document.write() a container with sHTML inside the frame
	// ex: DrawContainer(document,"menu",sHTML) will document.write() a menu style container with sHTML inside the frame


	var document_reference;
	var sOptions="";
	var sContent="";
	var sDimensions="";
	var sExtraContentStyle="";
	var sExtraContentClass="";

	if (typeof(Arg1) == 'object')
	{
		document_reference = Arg1 || '';
		sOptions = Arg2 || '';
		sContent = Arg3;
	}
	else
	{
		sOptions = Arg1 || '';
		sContent = Arg2;
	}

	if(sOptions.match(/menu_container/))					sContainer = 'menu_container';
	else if(sOptions.match(/input_container/))			sContainer = 'input_container';
	else if(sOptions.match(/sub_content_container/)) 	sContainer = 'sub_content_container';
	else if(sOptions.match(/alt_content_container/)) 	sContainer = 'alt_content_container';
	else if(sOptions.match(/content_container/)) 		sContainer = 'content_container';
	else if(sOptions.match(/popup_container/))	 		sContainer = 'popup_container';
	else															 	sContainer = 'container';

//	if( navigator.userAgent.match(/Safari/) && sContainer == 'input_container')
//	{
//		hGraphicsSettings['container_class_only'] = 1;
//	}

	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.search.indexOf('style_override=profiles') > -1
			|| location.search.indexOf('style_override=embedded') > -1
			|| (
				location.href.indexOf('studio_admin') > -1
				&& location.href.match(/studio_admin\/\w/)
			)
			|| (
				location.href.indexOf('model_admin') > -1
				&& location.href.match(/model_admin\/\w/)
			)
			&& ! hGraphicsSettings['no_override']
		)
*/
		&& location.href.indexOf('/top') == -1
		&& location.href.indexOf('/player') == -1
		&& ! hGraphicsSettings['no_override']
	)
	{
		if(sContainer == 'menu_container')
		{
			sContainer = 'alt_content_container';
		}
		else if(sContainer == 'input_container')
		{
			return;
		}
		
		hGraphicsSettings['container_class_only'] = 1;
		document_reference.body.style.margin = '0px';
		document_reference.body.className = 'inner_body';
	}
	// special exception code, overide styles if embeded in MFC feature frame
	else if( 
		document_reference
		&& ! opener
		&& parent
	)
	{

//if( document.cookie.match(/mfcuser/) ) { alert( location.href + " : " + parent.location.href ); }
		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 )
			{
				hGraphicsSettings['no_style'] = 1;

				if(sContainer == 'container')
				{
					sContainer = 'content_container';
				}
				else if(sContainer == 'input_container')
				{
					return;
				}
			
				sOptions += ' ' + sContainer;		
				document_reference.body.className = 'inner_body';
				g_hDocumentReferences[document_reference.location] = document_reference;
				setTimeout("g_hDocumentReferences['"+document_reference.location+"'].body.className = 'inner_body'",100);
			}
		}
		catch(oError)
		{
		}
	}

	if( ! sContent )
	{
		if(g_hCache[sOptions])
		{
			if(document_reference)
			{
				document_reference.write(g_hCache[sOptions]);
				return;
			}
			else
			{
				return g_hCache[sOptions];
			}
		}
	}

	if(sOptions.match(/expanded/))
	{
		sDimensions = " height=100% width=100% ";
		sExtraContentStyle	= "font-size:13px;";
	}
	else if(sOptions.match(/contracted/) || sOptions.match(/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(sOptions.indexOf('header_') > -1)
	{
		sOptions.match(/header_(\w+)/);
		sStyleDivs = "<div class='"+sContainer+"_header_div'><img src='" + g_hC['img_path'] + "/images/"+sContainer+"/header_" + RegExp.$1 + ".gif'></div>";
		sExtraContentClass += sContainer+"_header_mods";
	}
	
	if ( hGraphicsSettings['container_class_only'] || sOptions.indexOf('container_class_only') > -1 )
	{
		sTop = "\
			<div class=" + sContainer + ">\
				<div class=" + sContainer + "_table_td>\
		";
		sBottom = "\
				</div>\
			</div>\
		";
	}
	else if ( hGraphicsSettings['stylesheet'] || hGraphicsSettings['no_style'] )
	{
		sTop = "\
			<div class=container_padding>\
				<div class=container_transparency >\
					<div class=container >\
		";
		sBottom = "\
					</div>\
				</div>\
			</div>\
		";
	}
	else if( navigator.userAgent.match(/Firefox\/3|Chrome|Safari/) )
	{
		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>\
		";

//alert( sTop + " 12 " + sBottom );
	} 
	else 
	{
			//<div style='position:relative;height:100%;'>" + sStyleDivs + "\
		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('" + g_hC['img_path'] + "/images/" + sContainer + "/t.gif'); \"><img class=" + sContainer + "_img_tl src=\"" + g_hC['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('" + g_hC['img_path'] + "/images/" + sContainer + "/r.gif') repeat-y scroll top right;\"><img class=" + sContainer + "_img_tr src=\"" + g_hC['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('" + g_hC['img_path'] + "/images/" + sContainer + "/l.gif') repeat-y scroll bottom left;vertical-align:bottom;\"><img class=" + sContainer + "_img_bl src=\"" + g_hC['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('" + g_hC['img_path'] + "/images/" + sContainer + "/b.gif') repeat-x scroll bottom right;\"><img class=" + sContainer + "_img_br src=\"" + g_hC['img_path'] + "/images/" + sContainer + "/br.gif\"></td>\n\
				 </tr>\n\
				</table>\n\
			 </td>\n\
			</table>\n\
		";
			//</div>\
	}

	if(sOptions.match(/select_hack=([0-9]+)/))
	{
		sTop  += "<div class=hide_select_wrapper style='width:" + RegExp.$1 + "px;position:relative;'>";
		sBottom = "</div>" + sBottom;
	}

	var sH = "";
	if( sOptions.match(/top/) )
	{
		sH += sTop;
	}
	else if( sOptions.match(/bottom/) )
	{
		sH += sBottom;
	}
	else
	{
		sH += sTop + sContent + sBottom;
	}

	g_hCache[sOptions] = sH;

	if(document_reference)
	{
		document_reference.write(sH);
	}
	else
	{
		return sH;
	}
}

var hLoaded = hLoaded || {};
hLoaded['graphics'] = true;
