// var for Flash to check
var jsReady = false;

// this corrects for various HTML-rendering quirks that make the content invalid XML markup
function ieInnerHTML(iHTML) {
	// innerHTML value passed in
	var zz = iHTML;
	// match all the HTML tags
	var z = zz.match(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/g);
	// if there are any matches
	if (z){
		// run through the matches
		for (var i=0;i<z.length;i++) {		
		var y, zSaved = z[i];
		// replace the uppercase tags with standards-compliant lowercase
		z[i] = z[i].replace(/(<?\w+)|(<\/?\w+)\s/,
							function(a){return a.toLowerCase();});
		// check for unquoted attributes
		y = z[i].match(/\=\w+[?\s+|?>]/g);
		// if there's a match...
		if (y){
			// ... loop through
			for (var j=0;j<y.length;j++){
			// replace with quoted attributes
			z[i] = z[i].replace(y[j],y[j]
						.replace(/\=(\w+)([?\s+|?>])/g,'="$1"$2'));
			}
		}
		// apply changes to innerHTML
		zz = zz.replace(zSaved,z[i]);
		}
	}
	// reset z
	z	= 0;
	// check for unclosed image tags
	z	= zz.match(/<img([^>]+)(\s*[^\/])>/g);
	if(z) {
		for (var i = 0; i < z.length; i++) {
			var zSaved = z[i];
			z[i] = z[i].replace(/[/>]+$/g, "/>");
			zz = zz.replace(zSaved, z[i]);
		}
	}
	
	if(jQuery.browser.version <= 7.0) {
		// if this is false, a non W3C-compliant model is being used, indicative of IE6/7
		// search for all opening LI tags and replace with close/open combo
		zz = zz.replace(/<li/g, "</li><li");
		// reset z again
		z	= 0;
		// match any opening UL tags immediately followed by closing LI (result of above replacement)
		z	= zz.match(/<ul([\s\w<>="]*?)>([\s\w.]*?)<\/li>/g);
		if(z) {
			for (var i = 0; i<z.length; i++) {
				var zSaved = z[i];	
				z[i] = z[i].replace(/<\/li>/g, "");
				zz = zz.replace(zSaved, z[i]);
				flashTalk(z[i] + "\n");
			}
		}
	}

	return zz;
}
function isReady() {
	// Flash checks this to determine if it can proceed to ask for data
	return jsReady;
}
function pageInit() {
	// fires on $(document).ready
	jsReady = true;
	flashTalk("\n" + "JavaScript is ready.\n");
}
function thisMovie(movieName) {
	// returns movie
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		return document[movieName];
	}
}
function sendToActionScript(value) {
	// send information to Flash (called from JS)
	flashTalk("Javascript says: " + value + "\n");
	thisMovie("flashEI").sendToActionScript(value);
}
function sendToJavaScript(value) {
	// send information to JS (called from Flash)
	flashTalk("ActionScript says: " + value + "\n");
}

function infoPlease() {
	// function called by Flash, grabs contents of #flashData
	var id			= "flashData";
	// correct for IE oddities
	var grabbed		= ieInnerHTML($("#" + id).html());
	flashTalk("JS GET: " + grabbed + "\n");
	// Flash will unescape this -- we'll send it escaped just to be sure no special characters obstruct the transmission
	return escape(grabbed);
}

function swoFlashEI(src, srcEI, vars) {
	if(swfobject.ua.pv[0] != 0) {
		//$("#banner div#flashEI").css("color", "0x222222");
		// embed the SWF
		var myDate	= new Date();
		var flashvars	= vars;
		var params		= {
			menu:	"false",
			wmode:	"transparent"
		}
		swfobject.embedSWF((src + "?" + myDate.getTime()), "flashEI", "1011", "370", "9", srcEI, flashvars, params);
		
	} else {
		var noFlash = "<a href=\"http://adobe.com/go/getflashplayer\" style = \"position:absolute; right:0px; bottom:0px; display:none;\" class = \"getFlash\">";
		noFlash += "<img src = \"/images/artwork/alt_getFlash.jpg\" />";
		noFlash += "</a> ";
		$("#banner #flashEI div")
			.append(noFlash)
			.find("a.getFlash")
			.fadeIn(500);
	}
}

function flashTalk(str) {
	/*if ($("textarea[name=flashOutput]").length >= 1) {
		$("textarea[name=flashOutput]").append(str);
	}
	if(!jQuery.support.boxModel) {
		console.log(str);
	}*/
}

$(document).ready(
	function() {
		pageInit();


				var flashvars = {
					cssPath: "/css/flashStyle.css"
				}
				swoFlashEI("/flash/flash-home.swf", "/flash/expressInstall.swf", flashvars);



		$("div#features li.gbox").hover(
			function() {
				$(this)
					.addClass("hover")
					.end();
			},
			function() {
				$(this)
					.removeClass("hover")
					.end();
			}
		);
		
		/*if(jQuery.browser.version <= 7.0) {
			$("div.popup").supersleight();
		}*/
		
		$("div#partnerships dd").hover(
			function() {
				$(this)
					.find("div.popup")
					.fadeIn(250)
					.end();
			},
			function() {
				$(this)
					.find("div.popup")
					.fadeOut(250)
					.end()
			}
		);
	}
);