var _isMac = navigator.platform.toLowerCase().indexOf("mac") > -1;

$(document).ready(function(){
	
	var _tGif = "/images/site/x.gif";
	var _flashLink;
	var _flashOnclick;
	
	$(".flash2html").each(function(i){
		
		var height = $("object", this).height();
		var width = $("object", this).width();
		var zIndex = $("object", this).zIndex() + 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");
		
		$(this).removeAttr("href");
		
		if ($(this).attr("onclick")) {
			var onclick = stripFunction($(this).attr("onclick"));
			$(this).removeAttr("onclick");
		} else {
			onclick = "";
		}
		
		$(this).css({"display":"block","position":"relative"}).prepend("<a class=\"jqOverlay\" href=\""+href+"\" onclick=\""+onclick+"\" "+style+"></a>");
		
		if ($(this).attr("class")=="flash2html allowFlashRollover" && hasFlash && !_isMac) {
			
			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);
}
