var navtitle = "Trended.com";

$.ajax({
	type: "GET",
	url: "/topnav.static.xml",
	dataType: "xml",
	success: function(xml) {
		// start loop through root element
		$(xml).find('topnav').each(function(){
			$(this).find("topNav2").each(function(){
				$(this).find("link").each(function(){
					var thislink = $(this).attr('href');
					$("<p class='link'></p>")
						.html($(this).text())
						.hover(
							   function() {
								   $(this).addClass('over');
							   },
							   function() {
								   $(this).removeClass('over');
							   }
						)
						.click(
							   function() {
								   window.open(thislink,"e");
							   }
						)
						.appendTo("#topbar-line2")
				}); // end each link
			}); // end topNav2			
			
			$(this).find("topNav3").each(function(){
				$(this).find("link").each(function(){
					$("<span></span>")
						.html(
								"<a target='_blank' href='" + $(this).attr("href") + "'><img src='" + $(this).attr("image") + "' align='absmiddle' alt='" + 
								$(this).text() + "' border='0'></a> <a target='_blank' href='" + $(this).attr("href") + "'>" + $(this).text() + "</a> &nbsp;&nbsp;"
						)
						.appendTo("#topbar-line3")
				}); // end each link
			}); // end topNav3
				
			$(this).find('CALink').each(function(){
				$('<div class="externalLink"></div>')
					.html("<b><a target='_blank' href='" + $(this).attr('href') + "'>" + $(this).text() + "</a></b>")
					.appendTo("#externals")
			}); // end each USLink loop
			$(this).find('USLink').each(function(){
				$('<div class="externalLink"></div>')
					.html("<a target='_blank' href='" + $(this).attr('href') + "'>" + $(this).text() + "</a>")
					.appendTo("#externals")
			}); // end each USLink loop			
			// end each leftNav tag loop
			
		}); // end each topnav tag loop
	} // end success
}); // end ajax


///////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////BEGIN LEFT NAV///////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////


$.ajax({
	type: "GET",
	url: "/publicnav.xml",
	dataType: "xml",
	success: function(xml) {
		$(xml).find('Navigation').each(function(){												
			$(this).find("item1").each(function(){
				var children1 = $(this).attr("children");												
				var id1 = $(this).attr("id");
				var lnk = $(this).attr("link");
				var nam = $(this).attr("name");
				if (nam == 'blank')
				{
					$('<div id="i1' + id1 + '" class="internalLink-blank"></div>')
						.appendTo("#leftnavitems");
						$('<span id="i1i'+id1+'">&nbsp;</span>')
						.appendTo("#i1"+id1);					
				} else {
					var onyes = '';
					if (_pageid == id1)
					{
						document.title = document.title + ' - ' + nam;
						onyes = "-Selected";
					} else {
						onyes = "";
					}
						
					if ($(this).attr("prompt"))
					{
						msg = " onclick=\"return confirm('" + $(this).attr("prompt") + "');\" ";
					} else {
						msg = '';
					}
					
					$('<div id="i1' + id1 + '" class="internalLink'+onyes+'"></div>')
						.appendTo("#leftnavitems");
						$('<span id="i1i'+id1+'"></span>')
						.html("<a href='" + lnk + "'" + msg + ">" + nam + "</a>")
						.appendTo("#i1"+id1);
						
					if (children1 != 0 && _pageid == id1)
					{
						$("#i1"+id1).addClass("internalLink-On");
						$(this).find("item2").each(function(){
															
							var id2 = $(this).attr("id");
							var lnk2 = $(this).attr("link");
							var nam2 = $(this).attr("name");
							
							var on2yes = '';
							if (_subpageid == id2)
							{
								document.title = document.title + ' - ' + nam2;
								on2yes = "-On";
							} else {
								on2yes = "";
							}															
							
							$('<div id="i2'+id2+'" class="internalLinkSub1'+on2yes+'"></div>')
								.appendTo("#leftnavitems");
							$('<span id="i2i'+id2+'"></span>')
								.html("<a href='" + lnk2 + "'>" + nam2 + "</a>")
								.appendTo("#i2"+id2);
						}); // end each item2;
					} // end if children != 0;
				} // end if blank;
			}); // end each item1;
		}); // end each Navigation root tag;
	} // end success;
}); // end ajax;