(
	function()
	{
		var window = this, undefined;

		ognc =
		{
			exists: true,

			init: function()
			{
				// Allow console.log debugging cross all browsers
				/*try
				{
				console.log('...ognc is now running...');
				}
				catch(e)
				{
				console =
				{
				log : function()
				{
							
				}
				}
				}*/
			},

			//Commonly used functions/helpers
			showFlash: function(argSwf, argElement, argFlashVars)
			{
				if ($(argElement))
				{
					var isSafari = "";
					var isLTOpera92 = "";

					navigator.userAgent.indexOf("Safari") >= 0 ? isSafari = true : isSafari = false;
					navigator.userAgent.indexOf("Opera") >= 0 && parseFloat(navigator.appVersion) < 9.2 ? isLTOpera92 = true : isLTOpera92 = false;

					//Should Flash even be shown? (does user want it / can their browser support Flash 8 functionality)
					if (isLTOpera92 == false)
					{
						var site_config =
						{
							"host": location.host,
							"src": location.href,
							"title": document.title,
							"isSafari": isSafari,
							"isLTOpera92": isLTOpera92,
							"EOF": "EOF"
						};

						var flash_vars = "";

						for (k in site_config)
						{
							if (k != "toJSONString")
							{
								flash_vars += "&" + k + "=" + encodeURIComponent(site_config[k]);
							}
						}

						// deep link & query strings
						if (location.href.indexOf("?") != -1)
						{
							// if we have a src in the query we need to strip it out to avoid overwrite
							if (location.href.indexOf("src=") != -1)
							{
								// split on the src
								var queryCleanedArray = location.href.split("src=");

								// if we have additional values past the src value
								if (queryCleanedArray[1].indexOf("&") != -1)
								{
									// remove the src altogether
									queryCleanedArray[1] = queryCleanedArray[1].substring(queryCleanedArray[1].indexOf("&") + 1, queryCleanedArray[1].length);
								}
								else
								{
									// set the val to empty
									queryCleanedArray[1] = "";
								}

								// join on empty
								var cleanedVersion = queryCleanedArray.join("");
								flash_vars += "&" + cleanedVersion.substr(location.href.indexOf("?") + 1);
							}
							else
							{
								flash_vars += "&" + location.href.substr(location.href.indexOf("?") + 1);
							}
						}

						if ($(argElement))
						{
							var render_foo = document.getElementById(argElement);
							render_foo.style.display = "block";
						}

						// set the name fo the flash based on the div
						flashName = argElement + "_flash";

						// pass the containing div height and width
						flash_vars += "&stageWidth=" + parseInt($("#" + argElement).width(), 10) + "&stageHeight=" + parseInt($("#" + argElement).height(), 10);

						if (argFlashVars != null)
						{
							flash_vars += argFlashVars;
						}

						var flash_version = 10;
						var flashvars = false;
						var params =
						{
							bgcolor: "#FFFFFF",
							scale: "noscale",
							wmode: "transparent",
							play: "true",
							quality: "high",
							menu: "false",
							flashvars: flash_vars,
							AllowScriptAccess: "always"
						};
						var attributes =
						{
							id: flashName,
							name: flashName
						};

						//SWFObject replaces the entire DIV, so lets create an injection DIV inside our target
						var flash_injetcion_id = argElement + "__flash_injection";
						$("#" + argElement).empty();
						$("#" + argElement).append($("<div id=\"" + flash_injetcion_id + "\">test</div>"));

						flash_version_string = flash_version.toString() + ".0.0";
						swfobject.embedSWF
						(
						 	argSwf,
							flash_injetcion_id,
							"100%",
							"100%",
							flash_version_string,
							"expressInstall.swf",
							flashvars,
							params,
							attributes
						);
						$(argElement).css("visibility", "visible");
					}
				}
			},

			//Commonly used functions/helpers
			getFlashDataFromDiv: function(divID, flashDivID)
			{
				// feed the data
				var page_XHTML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
				page_XHTML += ognc.dom2xml.convert("#" + divID);
				window.document[flashDivID + "_flash"].setData(page_XHTML);
			},

			//Set Domain Cookie
			setCookie: function(c_name, value, expiredays)
			{
				var exdate = new Date();
				exdate.setDate(exdate.getDate() + expiredays);
				document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
			},

			//Get Domain Cookie
			getCookie: function(c_name)
			{
				if (document.cookie.length > 0)
				{
					c_start = document.cookie.indexOf(c_name + "=");

					if (c_start != -1)
					{
						c_start = c_start + c_name.length + 1;
						c_end = document.cookie.indexOf(";", c_start);

						if (c_end == -1)
						{
							c_end = document.cookie.length;
						}
						
						return unescape(document.cookie.substring(c_start, c_end));
					}
				}
				return "";
			}
		}

		ognc = window.ognc;

		$(document).ready
		(
			function()
			{
				ognc.init();
			}
		);
	}
)();
