

$(document).ready(function(){
	
/*
Extended Tabs by Peter Allen
Version 1.0 5/3/2010
Purpose: Add a tabs to the beginning (prepend) or end (append) of the default SharePoint Top Navigation tabs.
Script Setup: To make this script work you will need to provide several pieces of data which are listed out below.

[tabSide] - Specify either 'append' or 'prepend'. This will indicated if the new tab will go before or after the default tabs.
				Tab front Example: 'prepend'
				Tab End Example: 'append'
[titleTabName] - Specify a name for the tab, this will be displayed in the tab. 
				Tab Name Example: 'Intranet'
[urlTab] - Specify a link only if you want the tab to be clickable, otherwise leave blank with two quotes, ''. 
				Link Example: 'http://www.google.com'
				No Link Example: ''
[listName] - Specify the name of the list for the pull down.
				List Name Example: 'Links'
[listSiteUrl] - Specify the url of the site where the list is located. URL needs to be of the site location NOT of the list location.
				Incorrect Example: 'http://www.intranet.com/SiteName/List/ListName/'
				Correct Example: 'http://www.intranet.com/SiteName/'

All above variables will then be constructed as follows, make sure that each field has a ' at the beginning and end of each.

Construct:
	extendedTabs('[tabSide]','[titleTabName]','[urlTab]','[listName]','[listSiteURL]')
	
Example:
	extendedTabs('append','Projects','http://www.sites.com/Projects/','Projects','http://www.site.com/Resources/');
	
This example adds a tab at the end, a link for the Tab to the Project site, the list for the pull down is called Projects and the list resides in the Resources site.

You can have multiple extendTabs like so:

	extendedTabs('append','Projects','','Projects','http://www.bitsofsharepoint.com/ConsultingPoint/ClientPoint/snc/');
	extendedTabs('append','Team Sites','http://www.google.com','Team Sites','http://www.bitsofsharepoint.com/ConsultingPoint/ClientPoint/snc/');
	extendedTabs('prepend','Intranet','http://www.bitsofsharepoint.com/ConsultingPoint/ClientPoint/snc/default.aspx','Links','http://www.bitsofsharepoint.com/ConsultingPoint/ClientPoint/snc/');
	
Placement of your extendedTabs will dictate the order the tabs are displayed.
*/

//	Place your extendedTabs below:

	extendedTabs('append','Projects','','Projects','http://www.bitsofsharepoint.com/ConsultingPoint/ClientPoint/snc/');
	extendedTabs('append','Team Sites II','http://www.google.com','Team Sites','http://www.bitsofsharepoint.com/ConsultingPoint/ClientPoint/snc/');
	extendedTabs('prepend','Intranet II','http://www.bitsofsharepoint.com/ConsultingPoint/ClientPoint/snc/default.aspx','Links','http://www.bitsofsharepoint.com/ConsultingPoint/ClientPoint/snc/');

	
	var i = 1; 
	
	function extendedTabs(tabSide,titleTabName,urlTab,listName,listSiteURL) {

		var titleTabID = 'zz1_TopNavigationMenun' + titleTabName.replace(/[-' ']/g,'');
		var showTabPD = titleTabID + 'Show';
		var showTabAppend = titleTabID + 'Append';

		if (urlTab != '') {
	
			var urlTabShow = 'href=' + urlTab;
		
		} else {
		
			var urlTabShow = '';
		
		}

			var tableRow = '<td id="' + titleTabID + '" onkeyup="Menu_Key(event)" onmouseout="Menu_Unhover(this)" onmouseover="Menu_HoverRoot(this)"><table  width="100%" cellspacing="0" cellpadding="0" border="0" class="ms-topnav zz1_TopNavigationMenu_4"><tbody><tr id="mouse"><td style="white-space: nowrap;"><a ' + urlTabShow + ' style="border-style: none; font-size: 1em;" class="zz1_TopNavigationMenu_1 ms-topnav zz1_TopNavigationMenu_3">'	+ titleTabName + '</a><td valign="top" style="width:0pt;" ><img style="border-style:none; vertical-align:top;" alt="" src="/_layouts/images/menudark.gif"></td></tr></tbody></table><div style="position:absolute;height: 0px;z-index:1;"><div id="' + showTabPD + '" class="zz1_TopNavigationMenu_8" style="display:none;position:relative;top:0px; clip: rect(auto, auto, auto, auto);z-index:1;"><table cellspacing="0" cellpadding="0" border="0" style="top: 0px;" id="' + showTabAppend + '"></table></div></div></td>';
	
		if (tabSide == 'prepend') {
				
			$('table#zz1_TopNavigationMenu').children().children().prepend(tableRow);
		
		} else {
		
			$('table#zz1_TopNavigationMenu').children().children().append(tableRow);

		}

		$().SPServices({

			operation: "GetListItems",

			webURL: listSiteURL, 

			listName: listName,

			completefunc: function (xData, Status) {

				$(xData.responseXML).find('[nodeName=z:row]').each(function() { 

					var URLdataTN1 = $(this).attr("ows_URL").split(','); 

					var linksTN1 = $(this).attr("ows_LinkType");

					if (linksTN1 == 'Header') {

						$('#' + showTabAppend).append('<tr id="zz1_TopNavigationMenun' + i + '" onkeyup="Menu_Key(event)" onmouseout="Menu_Unhover(this)" onmouseover="Menu_HoverDynamic(this)"><td><table cellspacing="0" cellpadding="0" border="0" width="100%" class="ms-topNavFlyOuts zz1_TopNavigationMenu_7 ms-topNavFlyOutsHover"><tbody><tr><td style="white-space: nowrap; width: 100%;"><a style="border-style: none; font-size: 1em;" class="zz1_TopNavigationMenu_1 ms-topNavFlyOuts zz1_TopNavigationMenu_6 ms-topNavFlyOutsHover"><strong>' + URLdataTN1[1] + '</strong></a></td></tr></tbody></table></td></tr>');
						i++;


					} else if (linksTN1 == 'Header Link') {

						$('#' + showTabAppend).append('<tr id="zz1_TopNavigationMenun' + i + '" onkeyup="Menu_Key(event)" onmouseout="Menu_Unhover(this)" onmouseover="Menu_HoverDynamic(this)"><td><table cellspacing="0" cellpadding="0" border="0" width="100%" class="ms-topNavFlyOuts zz1_TopNavigationMenu_7 ms-topNavFlyOutsHover"><tbody><tr><td style="white-space: nowrap; width: 100%;"><a style="border-style: none; font-size: 1em;" href="' + URLdataTN1[0] + '" class="zz1_TopNavigationMenu_1 ms-topNavFlyOuts zz1_TopNavigationMenu_6 ms-topNavFlyOutsHover"><strong>' + URLdataTN1[1] + '</strong></a></td></tr></tbody></table></td></tr>');

						i++;

					} else {

						$('#' + showTabAppend).append('<tr id="zz1_TopNavigationMenun' + i + '" onkeyup="Menu_Key(event)" onmouseout="Menu_Unhover(this)" onmouseover="Menu_HoverDynamic(this)"><td><table cellspacing="0" cellpadding="0" border="0" width="100%" class="ms-topNavFlyOuts zz1_TopNavigationMenu_7"><tbody><tr><td style="white-space: nowrap; width: 100%;"><a style="border-style: none; font-size: 1em;" href="' + URLdataTN1[0] + '" class="zz1_TopNavigationMenu_1 ms-topNavFlyOuts zz1_TopNavigationMenu_6">' + URLdataTN1[1] + '</a></td></tr></tbody></table></td></tr>');
						i++;

					}

				});

			}

		});


		$('#' + titleTabID).mouseover(function(){

			$('#' + showTabPD).show();

		});
		$('#' + titleTabID).mouseleave(function(){

			$('#' + showTabPD).hide();


		});

	}

});

