/**
 * @author ryanarchy
 */
safireLocation = "http://www.jewelerformula.com/common/safire_core/safire_release.swf"
$jq = jQuery.noConflict();
loadcss("http://www.jewelerformula.com/common/safire-plugin/assets/history.css");
loadcss("http://www.jewelerformula.com/common/safire-plugin/assets/colorbox.css");
//loadjs("lib/jquery.colorbox.js");
//loadjs("lib/AC_OETags.js");
colorboxLoaded = false;
oetagsLoaded = false;
$jq(document).ready(
		function()
		{
			// misc js and css files that need to be sourced
			$jq.getScript("http://www.jewelerformula.com/common/safire-plugin/lib/jquery.colorbox.js", function() { 	colorboxLoaded = true;
																	colorboxLoad(); });
			$jq.getScript("http://www.jewelerformula.com/common/safire-plugin/lib/AC_OETags.js", function() { 			oetagsLoaded = true;
																	colorboxLoad(); });
			$jq.getScript("http://www.jewelerformula.com/common/safire-plugin/lib/history.js");
			
			// set up our divs
			$jq("body").append('<div id="safireInvis" style="display:none"/>');
			// content for everyone except IE
			$jq("#safireInvis").append('<div id="safireContent" />');
			$jq("#safireContent").append('<embed id="safEmbed"/>');
			document.getElementById('safEmbed').setAttribute("src", safireLocation);
			document.getElementById('safEmbed').setAttribute("quality", "high");
			document.getElementById('safEmbed').setAttribute("name", "safire_app");
			document.getElementById('safEmbed').setAttribute("bgcolor", "#000000");
			document.getElementById('safEmbed').setAttribute("width", "515");
			document.getElementById('safEmbed').setAttribute("height", "507");
			document.getElementById('safEmbed').setAttribute("play", "true");
			document.getElementById('safEmbed').setAttribute("align", "middle");
			document.getElementById('safEmbed').setAttribute("wmode", "opaque");
			document.getElementById('safEmbed').setAttribute("flashvars", $jq(".safireLink").attr("data-flashvars"));
			document.getElementById('safEmbed').setAttribute("type", "application/x-shockwave-flash");
			document.getElementById('safEmbed').setAttribute("allowScriptAccess", "always");
			document.getElementById('safEmbed').setAttribute("pluginspace", "http://www.adobe.com/go/getflashplayer");
			document.getElementById('safEmbed').setAttribute("loop", "false");
			// set up IE specific stuff
			$jq("#safireInvis").append("<div id='safireContentIE' />");
			$jq("#safireContentIE").append("<object id='safEmbedIE' width='515' height='507' align='middle' type='application/x-shockwave-flash' name='safire'>" +
					"<param name='movie' value='" + safireLocation + "' />" +
					"<param name='quality' value='high' />" +
					"<param name='bgcolor' value='#000000' />" +
					"<param name='allowScriptAccess' value='always'/>" +
					"<param name='flashVars' value='" + $jq(".safireLink").attr("data-flashvars") + "' />" +
					"</object>");			
			/*if ($jq.browser.msie)
			{
				$jq(".safireLink").colorbox({inline:true, innerWidth:515, innerHeight:507, href:"#safireContentIE"});
			}
			else
			{
				$jq(".safireLink").colorbox({inline:true, innerWidth:515, innerHeight:507, href:"#safireContent"});
			}
			
			if (window.location.hash.length > 1)
			{
				$jq(".safireLink").colorbox({open:true});
			} */
		});

function loadcss(filename)
{
	var fileref = document.createElement("link");
	fileref.setAttribute("rel", "stylesheet");
	fileref.setAttribute("type", "text/css");
	fileref.setAttribute("href", filename)

	if (typeof fileref != "undefined")
	{
		document.getElementsByTagName("head")[0].appendChild(fileref);
	}
}

function loadjs(filename)
{
	var fileref = document.createElement("script");
	fileref.setAttribute("type", "text/javascript");
	fileref.setAttribute("src", filename);
	
	if (typeof fileref != "undefined")
	{
		document.getElementsByTagName("head")[0].appendChild(fileref);
	}
}

function colorboxLoad()
{
	if ( colorboxLoaded && oetagsLoaded )
	{
		if ($jq.browser.msie)
		{
			$jq(".safireLink").colorbox({inline:true, innerWidth:515, innerHeight:507, href:"#safireContentIE"});
		}
		else
		{
			$jq(".safireLink").colorbox({inline:true, innerWidth:515, innerHeight:507, href:"#safireContent"});
		}
		
		if (window.location.hash.length > 1)
		{
			$jq(".safireLink").colorbox({open:true});
		}
	}
	
}


