

var DEFAULT_WIDTH = 640; 
var DEFAULT_HEIGHT = 436;
var MIN_WIDTH = 240; 

var aryTWCLinks = [];
aryTWCLinks[0] = {'title':'Local Pollen Reports', 'url':'http://www.weather.com/allergies?par=xoap&site=textlink&cm_ven=XOAP&cm_cat=TextLink&cm_pla=Link1&cm_ite=Allergies'};
aryTWCLinks[1] = {'title':'Airport Conditions', 'url':'http://www.weather.com/flights?par=xoap&site=textlink&cm_ven=XOAP&cm_cat=TextLink&cm_pla=Link2&cm_ite=BusinessTraveler'};
aryTWCLinks[2] = {'title':'Picnic Weather', 'url':'http://www.weather.com/picnic?par=xoap&site=textlink&cm_ven=XOAP&cm_cat=TextLink&cm_pla=Link3&cm_ite=Picnic'};
aryTWCLinks[3] = {'title':'Rush Hour Traffic', 'url':'http://www.weather.com/traffic?par=xoap&site=textlink&cm_ven=XOAP&cm_cat=TextLink&cm_pla=Link4&cm_ite=Traffic'};
aryTWCLinks[4] = {'title':'Lawn and Garden Weather', 'url':'http://www.weather.com/garden?par=xoap&site=textlink&cm_ven=XOAP&cm_cat=TextLink&cm_pla=Link3&cm_ite=Garden'};

var BROWSER_NONE = 0;
var BROWSER_IE = 1;
var BROWSER_FF = 2;
var BROWSER_CHROME = 3; 

if (typeof AniWeatherData == 'undefined')
{
	var AniWeatherData = {};
}

AniWeatherData.TipList = function()
{
	this.aryTips = [];

	// this.aryTips.push('<img src="images/bulb.png" alt="Tip" width="16" height="16" align="absmiddle" />&nbsp;If you like AniWeather, you may also like our another Add-on: <a href="https://addons.mozilla.org/en-US/firefox/addon/7750" style="color:#00FF00;" target="_blank">Cleeki - Internet Accelerators</a>');
	// this.aryTips.push('<img src="images/bulb.png" alt="Tip" width="16" height="16" align="absmiddle" />&nbsp;Want AniWeather to speak your language? <span style="color:#EEEE00;" >We need your help!</span> <a href="translate.html" style="color:#00FF00;" target="_blank">Learn More</a>');		
	// this.aryTips.push('Why not share AniWeather with your friends? <a class="st-taf" href="http://tellafriend.socialtwist.com:80" onclick="return false;" style="border:0;padding:0;margin:0;"><img alt="SocialTwist Tell-a-Friend" style="vertical-align:middle; border:0;padding:0;margin:0;" src="http://images.socialtwist.com/2009053018259/button.png" onmouseout="STTAFFUNC.hideHoverMap(this); "  onmouseover="STTAFFUNC.showHoverMap(this, \'2009053018259\', window.location, document.title)" onclick="STTAFFUNC.cw(this, {id:\'2009053018259\', link: window.location, title: document.title });"/></a>');
	// this.aryTips.push('<img src="images/bulb.png" alt="Tip" width="16" height="16" align="absmiddle" />&nbsp;Read our release notes for upgrade details. <a href="releasenotes.html" style="color:#00FF00;" target="_blank">Learn More</a>'); 
	// this.aryTips.push('<img src="images/bulb.png" alt="Tip" width="16" height="16" align="absmiddle" />&nbsp;Do you know: AniWeather works for both Firefox and Chrome. <a href="index.html" style="color:#00FF00;" target="_blank">Try it out</a>'); 
	// this.aryTips.push('<img src="images/bulb.png" alt="Tip" width="16" height="16" align="absmiddle" />&nbsp;Got problems? Check out the <a href="troubleshooting.html" style="color:#00FF00;" target="_blank">Trouble Shooting List</a> first.'); 
	// this.aryTips.push('<img src="images/warning_16.png" alt="Warning" width="16" height="16" align="absmiddle" />&nbsp;FlashBlock and NoScript users: <a href="troubleshooting.html#cac" style="color:#FF3333;" target="_blank">Please read this security note</a>.'); 
	// this.aryTips.push('<img src="images/sponsored.png" alt="Tip" width="86" height="16" align="absmiddle" />&nbsp;&nbsp;Get a professional weather station at home. <a href="http://rover.ebay.com/rover/1/711-53200-19255-0/1?ff3=4&pub=5574718791&toolid=10001&campid=5336188214&customid=&mpre=http%3A%2F%2Felectronics.shop.ebay.com%2Fi.html%3F_nkw%3Dweather%2Bstation%26_sacat%3D293%26_trksid%3Dm270%26_odkw%3Dweather%26_osacat%3D293" style="color:#00FF00;" target="_blank">Learn More</a><img style="text-decoration:none;border:0;padding:0;margin:0;" src="http://rover.ebay.com/roverimp/1/711-53200-19255-0/1?ff3=4&pub=5574718791&toolid=10001&campid=5336188214&customid=&mpt=[CACHEBUSTER]">'); 
	// this.aryTips.push('<img src="images/sponsored.png" alt="Tip" width="86" height="16" align="absmiddle" />&nbsp;&nbsp;Get a watch with weather forecast. <a target="_blank"  style="color:#00FF00;" target="_blank" href="http://rover.ebay.com/rover/1/711-53200-19255-0/1?ff3=4&pub=5574718791&toolid=10001&campid=5336188214&customid=&mpre=http%3A%2F%2Fshop.ebay.com%2Fi.html%3F_nkw%3Dweather%2Bforecast%2Bwatch%26_sacat%3D0%26_trksid%3Dp3286.m270.l1313%26_odkw%3Dweather%2Bwatch%26_osacat%3D0">Learn More</a><img style="text-decoration:none;border:0;padding:0;margin:0;" src="http://rover.ebay.com/roverimp/1/711-53200-19255-0/1?ff3=4&pub=5574718791&toolid=10001&campid=5336188214&customid=&mpt=[CACHEBUSTER]">'); 
	// this.aryTips.push('<img src="images/sponsored.png" alt="Tip" width="86" height="16" align="absmiddle" />&nbsp;&nbsp;Get books about <a target="_blank" style="color:#00FF00;" target="_blank" href="http://rover.ebay.com/rover/1/711-53200-19255-0/1?ff3=4&pub=5574718791&toolid=10001&campid=5336188214&customid=&mpre=http%3A%2F%2Fbooks.shop.ebay.com%2Fi.html%3F_nkw%3Dunderstanding%2Bweather%26_sacat%3D267%26_trksid%3Dp3286.m270.l1313%26_dmpt%3DUS_Texbook_Education%26_odkw%3Dunderstanding%2Bweather%2Bclimate%26_osacat%3D267">Understanding Weather</a><img style="text-decoration:none;border:0;padding:0;margin:0;" src="http://rover.ebay.com/roverimp/1/711-53200-19255-0/1?ff3=4&pub=5574718791&toolid=10001&campid=5336188214&customid=&mpt=[CACHEBUSTER]">'); 
	// this.aryTips.push('hide');
	
	// this.aryTips.push('<img src="images/aniweather_ipad_icon_48.png" alt="iPad" width="32" height="32" align="absmiddle" />&nbsp;&nbsp;<span style="font-size:12px; color:#ffff00;">AniWeather is now for iPad! <a href="ipad.html" style="color:#00FF00;" target="_blank">Learn More</a></span>'); 

	this.aryTips.push('<img src="images/aniweather_4_iphone.png" alt="iPad" width="48" height="36" align="absmiddle" />&nbsp;&nbsp;<span style="font-size:12px; color:#ffffff;">AniWeather is now for iPhone/iPad! <a href="iphone.html" style="color:#00FF00;" target="_blank">iPhone</a>&nbsp;&nbsp;<a href="ipad.html" style="color:#00FF00;" target="_blank">iPad</a></span>'); 
	
	// this.aryTips.push('<img src="images/bulb.png" alt="Tip" width="16" height="16" align="absmiddle" />&nbsp;AniWeather encountered technical issues on 04/06/10 PDT. <a href="notes.html" style="color:#00FF00;" target="_blank">Learn More</a>');		
	this.lenTips = this.aryTips.length; 
	this.getAtIndex = function(idx)
	{
		if(idx < 0 || idx >= this.lenTips)
			idx = Math.floor(Math.random()*0.99*this.lenTips); 

		return this.aryTips[idx]; 
	}
}

var lstTips = new AniWeatherData.TipList(); 

function getBrowserType()
{
	var browserType;
    if(navigator.userAgent.indexOf("MSIE") >= 0)
		browserType = BROWSER_IE;
	else if(navigator.userAgent.toLowerCase().indexOf("firefox") >= 0)
		browserType = BROWSER_FF;	
	else if(navigator.userAgent.toLowerCase().indexOf("chrome") >= 0)
		browserType = BROWSER_CHROME;				
	else
		browserType = BROWSER_FF;
		
	return browserType;
}
		
function attachAWCLinks(args)
{
	var pos = args.indexOf('linkidx='); 
	if(pos >= 0)
	{
		var idxes = args.substr(pos+8);
		pos = idxes.indexOf('&'); 
		if(pos > 0)
			idxes  = idxes.substr(0, pos); 	
		aryIdx = idxes.split(','); 
		if(aryIdx.length < 4)
			aryIdx = new Array(0,1,2,3);
		args = args + '&linktitles='+aryTWCLinks[aryIdx[0]].title+','+aryTWCLinks[aryIdx[1]].title+','+aryTWCLinks[aryIdx[2]].title+','+aryTWCLinks[aryIdx[3]].title+'&linkurls='+escape(aryTWCLinks[aryIdx[0]].url)+','+escape(aryTWCLinks[aryIdx[1]].url)+','+escape(aryTWCLinks[aryIdx[2]].url)+','+escape(aryTWCLinks[aryIdx[3]].url);
	}
	
	return args;
}

function init_header()
{
	var divHeader = document.getElementById('divHeaderBar'); 
	if(divHeader)
	{
		divHeader.innerHTML = '[ <a href="index.html">Home</a> ] [ <a href="faq.html">FAQ</a> ] [ <a href="releasenotes.html">Release Notes</a> ] [ <a href="aniweather.config6.html">Help</a> ] [ <a href="aniweather.config6.html#settings">Configure</a> ]'; 
	}
}

function getUrlParameters(url, mode)
{
	var mode = (typeof mode == "undefined") ? 0 : mode;
	var pos = url.indexOf("?"); 
	if(pos <= 0)
		return null; 

	var params = url.substr(pos+1); 
	var aryParams = params.split('&'); 
	var len = aryParams.length;
	var type; 
	var width = 100; 
	var ch = 0; 	
	var augs = "";
	var icon = 32; 
	var phase = 15;
	for(var i=0;i<len;i++)
	{
		var pair = aryParams[i];
		aryValues = pair.split('='); 
		if(aryValues[0] == "width")
			width = parseInt(aryValues[1]);
		else if(aryValues[0] == "ch")
			ch = parseInt(aryValues[1]);
		else if(aryValues[0] == "p")
		{
			augs = decodeURIComponent(aryValues[1]);		
			augs = attachAWCLinks(augs); 
		}
		else if(aryValues[0] == "phase")
			phase = parseInt(aryValues[1]);
		else if(aryValues[0] == "icon")
			icon = aryValues[1];
	}
	
	if(mode == 0)
		return {'width':width, 'ch':ch, 'augs':augs};
	else
		return {'width':width, 'icon':icon, 'phase':phase};
}

function initWeatherPage()
{
	var docurl = document.URL;
	var objParam =  getUrlParameters(docurl); 

	var extendedWidth = DEFAULT_WIDTH;
	var extendedHeight = DEFAULT_HEIGHT;
	var params = "";
	var weatherMediaBase = 'http://aniweather.s3.amazonaws.com/'; 
	var fileName = "weather5.swf"; 
	var objHolder = document.getElementById('divWeatherHolder'); 
	if(objParam != null)
	{
		if(objParam.width > MIN_WIDTH)
		{
			extendedWidth = objParam.width;
			extendedHeight = DEFAULT_HEIGHT*extendedWidth/DEFAULT_WIDTH;
			params = objParam.augs;
		}	
		
		if(objParam.ch > 0)
		{
			var top = Math.max(4, objParam.ch - extendedHeight);
			objHolder.style.top = top + "px";
			var objNotice = document.getElementById('divWeatherNotice'); 
			var objSense = document.getElementById('divWeatherSense'); 
			if(objNotice)
			{
				objNotice.style.top = Math.max(0, (top - 24)/2) + 'px';
				if(objSense)
					objSense.style.top = objNotice.style.top;
						
				var contents = lstTips.getAtIndex(-1);
				if(contents == "hide")
				{
					objNotice.style.display = "none"; 
					if(objSense)
						objSense.style.display = "block"; 
				}
				else
				{
					objNotice.style.display = "block"; 
					objNotice.innerHTML = contents;
					if(objSense)
						objSense.style.display = "none"; 
				}
			}		
		}
	}
	
	if(objHolder){
		objHolder.innerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+extendedWidth+'" height="'+extendedHeight+'"><param name="movie" value="'+weatherMediaBase+'media/'+fileName+'" /><param name="FlashVars" value="'+params+'" /><param name="wmode" value="transparent"><param name="quality" value="high" /><embed src="'+weatherMediaBase+'media/'+fileName+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" FlashVars="'+params+'" type="application/x-shockwave-flash" width="'+extendedWidth+'" height="'+extendedHeight+'" wmode="transparent"></embed></object>'
	}
	

}

function initMiniPage()
{
	var docurl = document.URL;
	var objParam =  getUrlParameters(docurl, 1); 
	 
	var defaultWidth = 100;
	var defaultHeight = 120;
	
	var width = Math.max(objParam.width, 64); 
	var height = defaultHeight * width / defaultWidth;
	
	var params = "nowicon="+objParam.icon+"&phase="+objParam.phase;
	var weatherMediaBase = 'http://aniweather.s3.amazonaws.com/'; 
	var fileName = "weather5s.swf"; 
	var objHolder = document.getElementById('divMiniHolder'); 
	
	if(objHolder){
		objHolder.innerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+width+'" height="'+height+'"><param name="movie" value="'+weatherMediaBase+'media/'+fileName+'" /><param name="FlashVars" value="'+params+'" /><param name="wmode" value="transparent"><param name="quality" value="high" /><embed src="'+weatherMediaBase+'media/'+fileName+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" FlashVars="'+params+'" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'" wmode="transparent"></embed></object>';
		objHolder.style.display="block";
	}
}