$(document).ready(function () {

    var _hasFlash = detectFlash();	
	var _tGif = "/images/x.gif";
	var _flashLink;
	var _flashOnclick;
	
	$(".flash2html").each(function(i){
        	
		var height = $("object", this).height();
		var width = $("object", this).width();
		var zIndex = $("object", this).css("z-index") + 1;
		var style = "style='background: url("+_tGif+");width:"+width+"px;height:"+height+"px;display:block;position:absolute;top:0;left:0;z-index:"+zIndex+";'";
		var href = $(this).attr("href");
		var id = $(this).attr("id");

		$(this).removeAttr("href");
		$(this).removeAttr("id");
		
		if ($(this).attr("onclick")) {
			var onclick = stripFunction($(this).attr("onclick"));
			$(this).removeAttr("onclick");
		} else {
			onclick = "";
		}
		
		$(this).css({"display":"block","position":"relative"}).prepend("<a id=\""+id+"\" class=\"jqOverlay\" href=\""+href+"\" onclick=\""+onclick+"\" "+style+"></a>");
		
		if ($(this).attr("class")=="flash2html allowFlashRollover" && _hasFlash) {
			
			var overlay = $(".jqOverlay", this);
			
			$(this).mouseenter(function(){
				_flashLink = overlay.attr("href");
				_flashOnclick = stripFunction(overlay.attr("onclick"));
				overlay.hide();
			}).mouseleave(function(){
				_flashLink = null;
				_flashOnclick = null;
				overlay.show();
			})
		}
		
	})
	
	$(document).mouseup(function(){
		if (_flashLink) {
			var fl = _flashLink;
			eval(_flashOnclick);
			window.location = fl;
		}
	})
	
})

function stripFunction(evt){
	var strEvent = String(evt);
	var from = strEvent.indexOf("{")+1;
	var to =  strEvent.lastIndexOf("}");
	return strEvent.substring(from,to);
}

function detectFlash() {
    var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
    var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
    var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

    if ((navigator.plugins != null && navigator.plugins.length > 0) && (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"])) return true;
    else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) return true;
    else if (isIE && isWin && !isOpera) {
        try {
            axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
            return true;
        } catch (e) { return false; }
    }
    return false;
}
