var richMediaRunning = false;
var rm_x1 = 0;
var rm_y1 = 0;
var rm_x = 0;
var rm_y = 0;
var rm_x2 = 0;
var rm_y2 = 0;
var rm_tin = 0;
var rm_t = 5000;
var rm_tout = 0;
var rm_fade = false;
var rm_w = 0;
var rm_h = 0;
var rm_trans = false;
var rm_b = false;
var rm_txtsz = 9;
var rm_txtrgb = "#ffffff";
var rm_bugsection = "";
var rm_cover = 0;
var rm_coverleft = 0;

function doRichMediaBasic(x, y, t, w, h, b, trans, src, txtsz, txtcolor)
{
	doRichMediaFull(x,y,x,y,x,y,0,t,0,w,h,b,false,trans,src, txtsz, txtcolor);
}

function doRichMediaFade(x, y, tin, t, tout, w, h, b, trans, src, txtsz, txtcolor)
{
	doRichMediaFull(x,y,x,y,x,y,tin,t,tout,w,h,b,true,trans,src, txtsz, txtcolor);
}

function doRichMediaSlide(x1, y1, x, y, x2, y2, tin, t, tout, w, h, b, trans, src, txtsz, txtcolor)
{
	doRichMediaFull(x1,y1,x,y,x2,y2,tin,t,tout,w,h,b,false,trans,src, txtsz, txtcolor);
}

function doRichMediaFull(x1, y1, x, y, x2, y2, tin, t, tout, w, h, b, fade, trans, src, txtsz, txtcolor)
{
	try
	{
		if (richMediaRunning)
		{
			setTimeout("doRichMediaFull(" + x1 + "," + y1 + "," + x + "," + y + "," + x2 + "," + y2 + "," + 
			tin + "," + t + "," + tout + "," + w + "," + h + "," + b + "," + fade + "," + trans + ",'" + src + 
			"'," + txtsz + ",'" + txtcolor + "');",(t + 1000));
			return;
		}
		richMediaRunning = true;

		rm_x1 = x1;
		rm_y1 = y1;
		rm_x = x;
		rm_y = y;
		rm_x2 = x2;
		rm_y2 = y2;
		rm_tin = tin;
		rm_t = t;
		rm_tout = tout;
		rm_fade = fade;
		rm_b = b;
		rm_w = w;
		rm_h = h;
		rm_trans = trans;
		if (txtsz != null) rm_txtsz = parseInt(txtsz);
		else rm_txtsz = 9;
		if (txtcolor != null) rm_txtrgb = txtcolor;
		else rm_txtrgb = "#ffffff";
		if (rm_bugsection == "") 
		{
			rm_bugsection = "WeatherBug";
			rm_cover = 1;
			var l = document.location + "";
			l = l.toLowerCase();
			if (l.indexOf("/weatherwindow/") > 0) { rm_bugsection = "Weather Window"; rm_cover = 0; }
			else if (l.indexOf("/common/enlarge") > 0)
			{
				if (l.indexOf("enlarge_control=camera/") > 0) { rm_bugsection = "Live Cameras"; rm_coverleft = 801; }
				else if (l.indexOf("enlarge_control=forecast/") > 0) { rm_bugsection = "Forecast"; rm_coverleft = 714; }
				else if (l.indexOf("enlarge_control=radar/") > 0) { rm_bugsection = "Radar & Maps"; rm_coverleft = 715; }
				else if (l.indexOf("enlarge_control=yourphotos/") > 0) { rm_bugsection = "Your Photos"; rm_coverleft = 675; }
				else if (l.indexOf("enlarge_control=stormcentral/") > 0) { rm_bugsection = "Storm Central"; rm_coverleft = 736; }
				else if (l.indexOf("enlarge_control=weatherfun/") > 0) { rm_bugsection = "Weather Fun"; rm_coverleft = 687; }
				else if (l.indexOf("enlarge_control=news/") > 0) { rm_bugsection = "News & Features"; rm_coverleft = 715; }
				if (rm_coverleft > 0) rm_cover = 2;
				else rm_cover = 0;
			}
			else if (l.indexOf("/camera/") > 0) rm_bugsection = "Live Cameras";
			else if (l.indexOf("/forecast/") > 0) rm_bugsection = "Forecast";
			else if (l.indexOf("/health/") > 0) rm_bugsection = "Health & Outdoors";
			else if (l.indexOf("/stormcentral/") > 0) rm_bugsection = "Storm Central";
			else if (l.indexOf("/news/") > 0) rm_bugsection = "News & Features";
			else if (l.indexOf("/observations/liveobservations") > 0) rm_bugsection = "Live Observations";
			else if (l.indexOf("/radar/") > 0) rm_bugsection = "Radar & Maps";
			else if (l.indexOf("/severeweather/") > 0) rm_bugsection = "Severe Weather";
			else if (l.indexOf("/traffic/") > 0) rm_bugsection = "Traffic";
			else if (l.indexOf("/weatherfun/") > 0) rm_bugsection = "Weather Fun";
			else if (l.indexOf("/yourphotos/") > 0) rm_bugsection = "Your Photos";
			if ((rm_cover != 2) && (rm_bugsection == "WeatherBug")) rm_cover = 0;
		}
		
		code = "<iframe onload=\"richMediaLoaded();\" id=\"richMediaIframe\" name=\"richMediaIframe\" frameborder=\"no\" scrolling=\"no\" src=\"" + 
			src + "\" style=\"z-index:9991; visibility:visible; position:absolute; left:-10000px; top:-10000px; height:" + h + "px; width:" + w + 
			"px; overflow:hidden;\"";
		
		if (trans) 
		{
			code += " allowtransparency=\"true\"";
		}		
		code += " background-color=\"transparent\"></iframe>";
		if ((rm_txtsz > 0) || (rm_b))
		{
			code += "<div id=\"richMediaCloseButtonDiv\" style=\"z-index:9992; visibility:hidden; position:absolute; width:" + w + "px;\" class=\"wx\">" +
				"<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" class=\"wx\"><tr><td align=\"right\" nowrap=\"true\">" +
				"<table cellpadding=\"1\" cellspacing=\"0\" border=\"0\" class=\"wx\"><tr>";				
			if (rm_txtsz > 0)
			{
				code += "<td nowrap=\"true\" style=\"font-family:Tahoma,Verdana,Arial,sans-serif; font-size:" + rm_txtsz + "px; color:" + rm_txtrgb + ";\">" + 
					"<a style=\"font-family:Tahoma,Verdana,Arial,sans-serif; font-size:" + rm_txtsz + "px; color:" + rm_txtrgb + ";\" href=\"javascript:feedback();\" alt=\"\">" +
					"Feedback on this ad</a>&#160;|&#160;" +
					"<a style=\"font-family:Tahoma,Verdana,Arial,sans-serif; font-size:" + rm_txtsz + "px; color:" + rm_txtrgb + ";\" href=\"JavaScript:richMediaFinished();\" alt=\"\">" +
					"Direct to " + rm_bugsection + "</a></td>";
			}
			if (rm_b)
			{
				code += "<td valign=\"middle\"><a style=\"font-family:Tahoma,Verdana,Arial,sans-serif; font-size:" + rm_txtsz + "px; color:" + rm_txtrgb + ";\" href=\"JavaScript:richMediaFinished();\" alt=\"\">" +
					"<img src=\"../../images/common/close.gif\" width=\"12\" height=\"12\" border=\"0\" alt=\"\" /></a></td>";
			}
			code += "</tr></table></td></tr></table></div>";
		}
		if (rm_cover == 1)
		{
			code += "<div id=\"coverdiv\" style=\"background-color:#EEF2FB; visibility:visible; position:absolute; left:480px; top:3px; width:130px; height:22px;\" class=\"wx\">&#160;</div>";
		}
		else if (rm_cover == 2)
		{
			code += "<div id=\"coverdiv\" style=\"background-color:#638CC6; visibility:visible; position:absolute; left:" + rm_coverleft + "px; top:3px; width:60px; height:20px;\" class=\"wx\">&#160;</div>";
		}
		rmlp = document.getElementById("richMediaLaunchPoint");
		rmlp.innerHTML = code;
	}
	catch (e) 
	{ 
		//window.alert(e.message); 
	}
}

function feedback()
{
	window.open("../../Common/RichMediaAbout.aspx?section=" + escape(rm_bugsection),"feedback","toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=550,height=115").focus();
}

var rm_xstep = 0;
var rm_ystep = 0;
var rm_fadestep = 0;
var rm_tstep = 50;
var rm_xcurr = 0;
var rm_ycurr = 0;
var rm_fadecurr = 0;

function richMediaLoaded()
{
	try
	{
		steps = 0;
		if (rm_tin > 0)
		{
			steps = Math.ceil(rm_tin / rm_tstep);
			rm_xstep = (rm_x - rm_x1) / (steps * 1.0);
			rm_ystep = (rm_y - rm_y1) / (steps * 1.0);
			rm_fadestep = Math.round(100 / steps);
		}		

		if (rm_fade)
		{
			rm_fadecurr = 0;
		}
		else
		{
			rm_fadecurr = 100;		
		}
		rm_xcurr = rm_x1;
		rm_ycurr = rm_y1;

		frame = document.getElementById("richMediaIframe");
		if ((rm_txtsz > 0) || (rm_b)) closer = document.getElementById("richMediaCloseButtonDiv");

		richMediaSetOpacity(frame,rm_fadecurr);
		frame.style.left = rm_xcurr + 'px';
		frame.style.top = rm_ycurr + 'px';
		frame.style.visibility = "visible";
		if ((rm_txtsz > 0) || (rm_b)) 
		{
			closer.style.left = rm_xcurr + 'px';
			closer.style.top = rm_ycurr + 'px';
			richMediaSetOpacity(closer,rm_fadecurr);
			closer.style.visibility = "visible";
		}

		if (rm_tin > 0)
		{
			setTimeout("richMediaStepIn();",rm_tstep);
		}
		else if (rm_tout > 0)
		{
			setTimeout("richMediaStepOut();",rm_t);
		}
		else if (rm_t > 0) 
		{
			setTimeout("richMediaFinished();",rm_t);				
		}	
	}
	catch (e) 
	{
		richMediaFinished();
	}
}

function richMediaStepIn()
{
	try
	{
		xlimit_found = true;
		ylimit_found = true;
		flimit_found = true;
		if (((rm_x > rm_x1) && (rm_xcurr < rm_x)) || ((rm_x1 > rm_x) && (rm_xcurr > rm_x))) xlimit_found = false;
		if (((rm_y > rm_y1) && (rm_ycurr < rm_y)) || ((rm_y1 > rm_y) && (rm_ycurr > rm_y))) ylimit_found = false;
		if (rm_fadecurr < 100) flimit_found = false

		if (xlimit_found && ylimit_found && flimit_found)
		{
			if (rm_t > 0) 
			{
				steps = 0;
				if (rm_tout > 0)
				{
					steps = Math.ceil(rm_tout / rm_tstep);
					rm_xstep = (rm_x2 - rm_x) / (steps * 1.0);
					rm_ystep = (rm_y2 - rm_y) / (steps * 1.0);
					rm_fadestep = Math.round(100 / steps);
					setTimeout("richMediaStepOut();",rm_t);				
				}		
				else
				{
					setTimeout("richMediaFinished();",rm_t);				
				}
			}	
		}
		else
		{
			if (flimit_found)
			{
				rm_fadecurr = 100;
			}
			else
			{
				rm_fadecurr += rm_fadestep;
			}
			rm_xcurr += rm_xstep;
			if (((rm_x > rm_x1) && (rm_xcurr >= rm_x)) || ((rm_x1 > rm_x) && (rm_xcurr <= rm_x))) xlimit_found = true;
			if (xlimit_found) 
			{	
				rm_xcurr = rm_x;
			}
			rm_ycurr += rm_ystep;
			if (((rm_y > rm_y1) && (rm_ycurr >= rm_y)) || ((rm_y1 > rm_y) && (rm_ycurr <= rm_y))) ylimit_found = true;
			if (ylimit_found) 
			{
				rm_ycurr = rm_y;
			}
			if (rm_fade) richMediaSetOpacity(frame,rm_fadecurr);
			frame.style.left = rm_xcurr + 'px';
			frame.style.top = rm_ycurr + 'px';
			if ((rm_txtsz > 0) || (rm_b))
			{
				closer.style.left = rm_xcurr + 'px';
				closer.style.top = rm_ycurr + 'px';
				if (rm_fade) richMediaSetOpacity(closer,rm_fadecurr);
			}
			setTimeout("richMediaStepIn();",rm_tstep);
		}
	}
	catch (e) 
	{
		richMediaFinished();
	}
}

function richMediaStepOut()
{
	try
	{
		xlimit_found = true;
		ylimit_found = true;
		flimit_found = true;
		if (((rm_x > rm_x2) && (rm_xcurr > rm_x2)) || ((rm_x2 > rm_x) && (rm_xcurr < rm_x2))) xlimit_found = false;
		if (((rm_y > rm_y2) && (rm_ycurr > rm_y2)) || ((rm_y2 > rm_y) && (rm_ycurr < rm_y2))) ylimit_found = false;
		if (rm_fadecurr > 0) flimit_found = false
		if (xlimit_found && ylimit_found && flimit_found)
		{
			richMediaFinished();				
		}
		else
		{
			if (flimit_found)
			{
				rm_fadecurr = 0;
			}
			else
			{
				rm_fadecurr -= rm_fadestep;
			}		
			rm_xcurr += rm_xstep;
			if (((rm_x > rm_x2) && (rm_xcurr <= rm_x2)) || ((rm_x2 > rm_x) && (rm_xcurr >= rm_x2))) xlimit_found = true;
			if (xlimit_found) 
			{			
				rm_xcurr = rm_x2;
			}
			rm_ycurr += rm_ystep;
			if (((rm_y > rm_y2) && (rm_ycurr <= rm_y2)) || ((rm_y2 > rm_y) && (rm_ycurr >= rm_y2))) ylimit_found = true;
			if (ylimit_found) 
			{
				rm_ycurr = rm_y2;
			}
			if (rm_fade) richMediaSetOpacity(frame,rm_fadecurr);
			frame.style.left = rm_xcurr + 'px';
			frame.style.top = rm_ycurr + 'px';
			if ((rm_txtsz > 0) || (rm_b))
			{
				closer.style.left = rm_xcurr + 'px';
				closer.style.top = rm_ycurr + 'px';
				if (rm_fade) richMediaSetOpacity(closer,rm_fadecurr);
			}
			setTimeout("richMediaStepOut();",rm_tstep);
		}
	}
	catch (e) 
	{
		richMediaFinished();
	}
}

function richMediaFinished()
{
	try
	{
		frame = document.getElementById("richMediaIframe");
		frame.style.visibility = "hidden";
		frame.style.left = '0px';
		frame.style.top = '0px';
		if ((rm_txtsz > 0) || (rm_b)) 
		{
			closer = document.getElementById("richMediaCloseButtonDiv");
			closer.style.left = '0px';
			closer.style.top = '0px';
			closer.style.visibility = "hidden";	
		}
		cover = document.getElementById("coverdiv");
		cover.style.visibility = "hidden";	
		richMediaRunning = false;
	}
	catch (e) {}
}

function richMediaSetOpacity(obj,opacity)
{
	try
	{
		obj.style.filter = "Alpha(Opacity=" + opacity + ")";
	}
	catch (e) {}
}

try
{
	document.write("<div id=\"richMediaLaunchPoint\"></div>");
	document.domain = "weatherbug.com";
}
catch (e) {}