var buttonData = {
	"meta": {
		"ieCount":24,
		"ffCount":24,
		//"imgSrc":"http://client.web.aol.com/toolbar/ie/aol/en-US/5.0/buttons/images"
		"imgSrc":"http://www.aolcdn.com/aoluk/aoltoolbar/icons"
	},
	
	"buttons":{
		"aol_im":{ "name":"AIM", "id":"aol_im", "icon":"aim.gif", "desc":"AOL&reg; Instant Messenger", "flag":3},
		//"aol_aimpages":{ "name":"AIM Pages", "id":"aol_aimpages", "icon":"aim_pages.gif", "desc":"With the social network at AIM Pages, it is easy to connect with buddies, find friends and meet people.","flag":3},
		"aol_alerts":{ "name":"Alerts", "id":"aol_alerts", "icon":"alert.gif", "desc":"Set reminders for important events.","flag":3},
		//"aol_autos":{ "name":"Autos", "id":"aol_autos", "icon":"auto.gif", "desc":"Search for new and used cars with AOL&reg; Autos","flag":3},
		"aol_calendar":{ "name":"Calendar", "id":"aol_calendar", "icon":"calendar.gif", "desc":"You've got a busy life, and AOL&reg; Calendar helps keep you on top of it all","flag":3},
		"aol_celebnews":{ "name":"Eleven - new", "id":"aol_celebnews", "icon":"celebritynews.gif", "desc":"Eleven lets you take a break from your everyday routine and get a fast fix of gossip, games, funny videos and style tips","flag":3},
		//"aol_celebnews":{ "name":"Celebrity News", "id":"aol_celebnews", "icon":"celebritynews.gif", "desc":"The latest happenings in the celebrity world","flag":3},
		//"aol_cityguide":{ "name":"City Guide", "id":"aol_cityguide", "icon":"city.gif", "desc":"Local entertainment guide for things to do, places to eat and scenes to see in 317 cities across the country","flag":3},
		//"aol_diets":{ "name":"Diet & Fitness", "id":"aol_diets", "icon":"diet.gif", "desc":"Every day made easy: food, home, parenting, health, diet & fitness, and more","flag":3},
		"aol_entertainment":{ "name":"Entertainment", "id":"aol_entertainment", "icon":"film-tv.png", "desc":"The latest happenings in the entertainment world","flag":3},
		"aol_money":{ "name":"Money", "id":"aol_money", "icon":"investing.gif", "desc":"Money, finance, investing, stock quotes and market news","flag":3},
		"aol_motoring":{ "name":"Motoring", "id":"aol_motoring", "icon":"auto.gif", "desc":"Motoring news","flag":3},
		"aol_movies":{ "name":"Film", "id":"aol_movies", "icon":"movies.gif", "desc":"Trailers, reviews, commentary & more","flag":3},
		//"aol_living":{ "name":"Food & Home", "id":"aol_living", "icon":"food_home.gif", "desc":"Every day made easy: food, home, parenting, health, diet & fitness, and more","flag":3},
		"aol_games":{ "name":"Games", "id":"aol_games", "icon":"games.gif", "desc":"Play free & fun online games","flag":3},
		"aol_realestate":{ "name":"Homes & Property", "id":"aol_realestate", "icon":"realestate.gif", "desc":"Access a comprehensive collection of home and apartment listings, information, tools, and advice","flag":3},
		"aol_horoscopes":{ "name":"Horoscopes", "id":"aol_horoscopes", "icon":"horoscope.gif", "desc":"Get your daily horoscopes from AOL&reg; Horoscopes","flag":3},
		"aol_living":{ "name":"Lifestyle", "id":"aol_living", "icon":"food_home.gif", "desc":" Search for a new job and get tips on how to advance your career, improve your parenting skills and take care of your health and wellbeing.","flag":3},
		//"aol_jobs":{ "name":"Jobs", "id":"aol_jobs", "icon":"jobs.gif", "desc":"AOL Find a Job offers the most comprehensive listings through its partnership with CareerBuilder.com. AOL Find a Job is the place to go on the Internet for job alerts, information, career advice, tips and tools.","flag":3},
		//"aol_love":{ "name":"Love@AOL", "id":"aol_love", "icon":"love.gif", "desc":" Search for singles near you.  Love@AOL makes online dating easier than ever!","flag":3},
		"aol_mail":{ "name":"Email", "id":"aol_mail", "icon":"email_ico.jpg", "desc":"Quick access to your AOL Email accounts.","flag":3},
		"aol_maps":{ "name":"MapQuest", "id":"aol_maps", "icon":"maps.gif", "desc":"Get one stop access to MapQuest driving directions and maps","flag":3},
		"aol_music":{ "name":"Music", "id":"aol_music", "icon":"music.gif", "desc":"Listen to AOL music radio, watch free music videos online and more","flag":3},
		//"aol_my_aol":{ "name":"My AOL", "id":"aol_my_aol", "icon":"my_aol.gif", "desc":"Access your favorite online content with MyAOL","flag":3},
		"aol_news":{ "name":"News", "id":"aol_news", "icon":"news.gif", "desc":"News stories as they unfold. Use AOL's Video On Demand video search tool to find  video news clips","flag":3},
		"aol_pictures":{ "name":"Pictures", "id":"aol_pictures", "icon":"aol_pic.gif", "desc":"Quick access to AOL Pictures","flag":3},
		//"aol_radio":{ "name":"AOL Radio", "id":"aol_radio", "icon":"radio.gif", "desc":"Free Internet radio stations featuring XM&reg; Satellite Radio","flag":3},
		//"aol_research":{ "name":"Research & Learn", "id":"aol_research", "icon":"research_learn.gif", "desc":"An online educational resource for homework help, books, & more","flag":3},
		"aol_shopping":{ "name":"Shopping", "id":"aol_shopping", "icon":"shopping.gif", "desc":"Shop AOL's network to find just what you're looking for","flag":3},
		"aol_sports":{ "name":"Sports", "id":"aol_sports", "icon":"sports.gif", "desc":"Scores, stats, player profiles - all here","flag":3},
		//"aol_tmz":{ "name":"TMZ", "id":"aol_tmz", "icon":"tmz.gif", "desc":"The latest happenings in the celebrity world","flag":3},
		"aol_tv":{ "name":"Television", "id":"aol_tv", "icon":"tv.gif", "desc":"Updates on the shows you may have missed","flag":3},
		"aol_travel":{ "name":"Travel", "id":"aol_travel", "icon":"travel.gif", "desc":"AOL&reg; Travel featuring Travelocity&reg;","flag":3},
		"aol_video":{ "name":"AOL Video", "id":"aol_video", "icon":"video_ico.jpg", "desc":"AOL's Video On Demand offers free, comprehensive video content you won't find anywhere else on the Internet","flag":3},
		"aol_weather":{ "name":"Weather", "id":"aol_weather", "icon":"weather.gif", "desc":"Find the weather in your local area","flag":3}
		//"aol_yellowpages":{ "name":"Yellow Pages", "id":"aol_yellowpages", "icon":"yellowpages.gif", "desc":"The online business directory where finding a business phone number or address in any city is made easy","flag":3}
	}, 
	"featured_buttons":{
		"aol_sports":{ "name":"Sports", "id":"aol_sports", "icon":"sports_large.gif", "desc":"Scores, stats, player profiles - all here","flag":3},
		"aol_tmz":{ "name":"TMZ", "id":"aol_tmz", "icon":"tmz_large.gif", "desc":"The latest happenings in the celebrity world","flag":3},
		"aol_maps":{ "name":"MapQuest", "id":"aol_maps", "icon":"maps_large.gif", "desc":"Get one stop access to MapQuest driving directions and maps","flag":3}
	}
};

var hasFF = false;
var hasFFTB = false;
var hasIE = false;
				
function foundFFTB()
{
	hasFFTB = true;
}

function toggleDescription(evt)
{
	var src = evt.target ? evt.target : evt.srcElement;
	if (src)
	{
		src.innerHTML = src.innerHTML=="Show Description"? "Hide Description":"Show Description";
		src.style.fontWeight = src.style.fontWeight==""? "bold":"";
		var div = src.nextSibling;
		if (div)
		{
			div.style.display = div.style.display ? "":"block";
		}
	}
}



var g_Toolbar = null;


this.AOLToolbarInit = AOLToolbarInit;
function AOLToolbarInit(Tool)
{
	if (Tool)
	{
		g_Toolbar = Tool;
	}
	
}

function getToolbar()
{
	setTimeout("window.location = 'http://client.web.aol.com/toolbar/ie/aol/en-US/5.0/buttons/tbGetToolbar.htm'", 300);
}

/* REMOVED - 18/12/07 
function addButtonURL(name, url, btn)
{
	var ok = false;
	// grab the file
	if (hasToolbar())
	{
		if (hasIE)
		{
			if (g_Toolbar)
			{
				var ver = g_Toolbar.Version("aoltb.dll");
				if ((ver.length > 2) && (ver.charAt(0) >= '4'))
				{
					try
					{
						var params = new ActiveXObject("AOLTB.ToolbarParams");
						if (params)
						{
							params.Add("name", name);
							params.Add("btnXML", url);
							params.Add("btnID", btn);
							params.Add("isFile", "1");	
							g_Toolbar.CreateAppButton("toolbar", params);
							delete params;
							params = null;
							ok = true;
						}
					}
					catch(e)
					{
					}
				}
				else
				{
					// older version
					getToolbar();
				}
			}
			else
			{
				// no toolbar object
				window.location = 'http://toolbar.aol.com/ie/addbutton?id="'+btn+'"&url="'+encodeURI(url) +'"';
				ok = true;
			}
		}
		else if (hasFFTB)
		{
			// load the firefox button
			window.aolButtonGalleryExternalObject.addFromButtonGallery('aol', btn, url);
			ok = true;
		}
		else
		{
			// no toolbar installed or wrong browser
			getToolbar();
		}
	}
	else
	{
		// no toolbar installed or wrong browser
		getToolbar();
	}
	return ok;
}
REMOVED - 18/12/07 */


function addButtonURL(name, url, btn)
{
	var ok = false;
	// grab the file
	if (hasToolbar())
	{
		if (g_Toolbar)
		{
			try
			{
				var ver = g_Toolbar.Version("aoltb.dll");
				if ((ver.length > 2) && (ver.charAt(0) >= '4'))
				{					
					var params = new ActiveXObject("AOLTB.ToolbarParams");
					if (params)
					{
						params.Add("name", name);
						params.Add("btnXML", url);
						params.Add("btnID", btn);
						params.Add("isFile", "1");	
						g_Toolbar.CreateAppButton("toolbar", params);
						delete params;
						params = null;
						ok = true;
					}
				}
				else
				{
					// older version
					getToolbar();
				}
			}
			catch(e)
			{
				window.location = 'http://toolbar.aol.com/ie/addbutton?id="'+btn+'"&url="'+encodeURI(url) +'"';
				ok = true;
			}
		}
		else
		{
			// no toolbar object
			window.location = 'http://toolbar.aol.com/ie/addbutton?id="'+btn+'"&url="'+encodeURI(url) +'"';
			ok = true;
		}		
	}
	else
	{
		// no toolbar installed or wrong browser
		getToolbar();
	}
	return ok;
}


function addNewButton(evt)
{
	var src = evt.target ? evt.target : evt.srcElement;
	if (src)
	{
		var url = "";
		var id = src.parentNode.id;
		if (hasIE)
		{
			//url = "http://client.web.aol.com/toolbar/ie/aol/en-US/5.0/buttons/buttons.xml";
			//url = "http://ukweb01.office.aol.com:11029/test/buttons.xml";
			url = "http://info.aol.co.uk/aoltoolbar/5-0/i/buttons.xml";
			
		}
		else if (hasFF)
		{
			//url = "http://client.web.aol.com/toolbar/ie/aol/en-US/5.0/buttons/ssffbuttons.xml";
		}

		var ok = addButtonURL('aol', url, id);	
		if (ok)
		{
			showPrompt(id, true);
		}
	}

}

var foundToolbar = false;
/* REPLACED - 20/12/07 
function hasToolbar()
{
	if (!foundToolbar)
	{
		if (hasIE)
		{
			try
			{
				var	testObj = new ActiveXObject("AOLTB.ToolbarParams");	
				if (testObj)
				{
					foundToolbar = true;
					delete testObj;			
				}	
			}
			catch(e){}
		}
		else if (hasFF)
		{
			foundToolbar = hasFFTB;
		}
	}	
	
	return foundToolbar;
}
REPLACED - 20/12/07 */


function hasToolbar()
{
	if (!foundToolbar)
	{
		if (hasIE)
		{
			// return true for IE
			foundToolbar = true;
		}
		else if (hasFF)
		{
			foundToolbar = hasFFTB;
		}
	} 
	return foundToolbar;
}


function showButton(Flag)
{
	// assume true so that on non-IE and non-Firefox browsers we display all buttons	
	ok = true;
	if (hasIE)
	{
		ok = (Flag & 1);
	}
	else if (hasFF)
	{
		ok = (Flag & 2);
	}
	return ok;
}
				
function init()
{
	if (navigator.userAgent.indexOf("MSIE") != -1)
	{
		// make sure not AOL
		if (navigator.userAgent.indexOf("AOL 9.0") == -1)
		{
			hasIE = true;
		}
	}
	else if (navigator.userAgent.indexOf("Firefox") != -1)
	{
		hasFF = true;
	}
	
	var i = 0;

	var topDiv = document.getElementById("featured");
	if (topDiv)
	{
		for (var button in buttonData.featured_buttons)
		{

			if (showButton(buttonData.featured_buttons[button].flag))
		  	{
				var name = buttonData.featured_buttons[button].name;
					
				var featuredDiv = document.createElement("div");
				if (featuredDiv)
				{
					featuredDiv.className = "featuredDiv";
					var img = document.createElement("div");
					if (img)
					{
						img.className = "featuredButtonImage";
						img.style.backgroundImage = "url("+buttonData.meta.imgSrc + '/' + buttonData.featured_buttons[button].icon+")";					
						featuredDiv.appendChild(img);
					}
					var p1 = document.createElement("div");
					if (p1)
					{
						p1.className = "featuredButtonTitle";
						p1.innerHTML =  name;
						featuredDiv.appendChild(p1);
					}
					var p2 = document.createElement("p");
					if (p2)
					{
						p2.className = "featuredButtonDescription";
						p2.innerHTML =  buttonData.featured_buttons[button].desc;
						featuredDiv.appendChild(p2);
					}
					var a1 = document.createElement("a");
					if (a1)
					{
						a1.id = button;
						a1.href = "javascript:void(0);" 
						if (a1.attachEvent)
						{
							a1.attachEvent("onclick", addNewButton);
						}
						else
						{
							a1.addEventListener("click", addNewButton, false);
						}
						var imgNormal = buttonData.meta.imgSrc +'/add_button_sm.gif';
						var imgClick = buttonData.meta.imgSrc +'/add_button_sm_down.gif';
						a1.innerHTML = '<img class="addButtonSmall" src="' + buttonData.meta.imgSrc +'/add_button_sm.gif" alt="Add ' + name + ' Button To AOL Toolbar" title="Add ' + name + ' Button To AOL Toolbar">';
						featuredDiv.appendChild(a1);
					}
					topDiv.appendChild(featuredDiv);
				}			
			}
		}
	}
	
	
	var half;
	if (hasFF)
	{
		 half = buttonData.meta.ffCount / 2;
	}
	else
	{
		half = buttonData.meta.ieCount / 2;
	}
	var leftDiv = document.getElementById("leftCol");
	var rightDiv = document.getElementById("rightCol");
	if (leftDiv && rightDiv)
	{
				
		for (var button in buttonData.buttons)
		{
			if (showButton(buttonData.buttons[button].flag))
		  	{
				var outerDiv = document.createElement("div");
				if (outerDiv)
				{
					outerDiv.className = "buttonContainer";
					var img = document.createElement("img");
					if (img)
					{
						img.className = "buttonIcon";
						img.src = buttonData.meta.imgSrc + '/' + buttonData.buttons[button].icon;
						outerDiv.appendChild(img);
					}
					var p1 = document.createElement("p");
					if (p1)
					{
						p1.className = "buttonName";
						p1.innerHTML =  buttonData.buttons[button].name;
						outerDiv.appendChild(p1);
					}
					
					var a1 = document.createElement("a");
					if (a1)
					{
						a1.id = button;
						a1.className = "addLink";
						a1.href = "javascript:void(0);" 
						
						if (a1.attachEvent)
						{
							a1.attachEvent("onclick", addNewButton);
						}
						else
						{
							a1.addEventListener("click", addNewButton, false);
						}
						a1.innerHTML = '<img class="addButtonSmall" src="' + buttonData.meta.imgSrc +'/add_button_sm.gif" alt="Add ' + buttonData.buttons[button].name + ' Button To AOL Toolbar" title="Add ' + buttonData.buttons[button].name + ' Button To AOL Toolbar">';
						outerDiv.appendChild(a1);
					}
					var a2 = document.createElement("a");
					if (a2)
					{
						a2.id = button + "_desc"; 
						a2.className="descriptionLink";
						a2.href = "javascript:void(0);"  
						a2.innerHTML = "Show Description";
						if (a2.attachEvent)
						{
							a2.attachEvent("onclick", toggleDescription);
						}
						else
						{
							a2.addEventListener("click", toggleDescription, false);
						}
						outerDiv.appendChild(a2);
					}
					var div = document.createElement("p");
					if (div)
					{
						div.className = "descriptionBlurbDiv";
	
						var p2 = document.createElement("p");
						if (p2)
						{
							p2.className = "descriptionBlurb";
							p2.innerHTML =  buttonData.buttons[button].desc;
							div.appendChild(p2);
						}
						outerDiv.appendChild(div);
					}
				}
				if (i++ < half)
				{
					leftDiv.appendChild(outerDiv);
				}
				else
				{
					rightDiv.appendChild(outerDiv);
				}
			}
		}
	}
}

function showPrompt(btnID, showFlag)
{
	
	if (showFlag)
	{
		alert('The "'+ buttonData.buttons[btnID].name + '" button has been added to your toolbar.');		
	}
	
}
