	var THEME_COLOR;		//color for the page	
	var CATEGORY_ID;		//id of the selected category
	var LINK_ID;			//is set on each page to one of the constants below	
	var themes;
	
	//create and edit Toolbar links
	var TOOLBAR_LOGO_PAGE = 0;
	var AFFINITY_PAGE = 1;
	var WIDGETS_PAGE = 2;
	var CREATE_BUTTONS_PAGE = 3;
	var RSS_FEEDS_PAGE = 4;
	var CREATE_TOOLBAR_PAGE = 4;
	var REGISTRATION_PAGE = 4;
	var CUSTOMIZE_DOWNLOAD_PAGE = 0;
	var IMPORT_CONTACTS_PAGE=0;
	var CUSTOM_DOWNLOAD_PAGE=1;
	var CREATE_BANNER_ADS=2;
	var GALLERY = 0;
	var REPORTING_PAGE=0;
	
	
	var navigation = []
	navigation.push([TOOLBAR_LOGO_PAGE , AFFINITY_PAGE , WIDGETS_PAGE , CREATE_BUTTONS_PAGE, REGISTRATION_PAGE]); 
	navigation.push([TOOLBAR_LOGO_PAGE , AFFINITY_PAGE , WIDGETS_PAGE , CREATE_BUTTONS_PAGE, REGISTRATION_PAGE]); 
	navigation.push([IMPORT_CONTACTS_PAGE , CUSTOM_DOWNLOAD_PAGE , CREATE_BANNER_ADS]); 
	navigation.push([REPORTING_PAGE]); 
	
/*Array of theme objects, keeping track of important images and colors*/
var themes=[{
	id: 1,
		background: "background_inner_01.png",
		linkBackground: "btn_subnav_step_01.png",
		themeColor: "#009245",
		button: "btn_step_01.png"
	},
	{
		id: 2,
		background: "background_inner_02.png",
		linkBackground: "btn_subnav_step_02.png",
		themeColor: "#EDA200",
		button: "btn_step_02.png"
	},
	{
		id: 3,
		background: "background_inner_03.png",
		linkBackground: "btn_subnav_step_03.png",
		themeColor: "#00adef",
		button: "btn_step_03.png"
	},
	{
		id: 4,
		background: "background_inner_04.png",
		linkBackground: "btn_subnav_step_04.png",
		themeColor: "#00CC66",
		button: "btn_step_04.png"
	},
	{
		id: 5,
		background: "background_inner_05.png",
		linkBackground: "btn_subnav_step_05.png",
		themeColor: "#0078bf",
		button: "btn_step_05.png"
	},
	{
		id: 6,
		background: "background_inner_06.png",
		linkBackground: "btn_subnav_step_06.png",
		themeColor: "#FE6110",
		button: "btn_step_06.png"
	}]
	
	
	function updateNavCookie(){
		//setting the cookie to save what links the user has visited
		var cookie = getCookie("SSTBNavigation");
		navHistory = cookie.split("&");
		
		var temp = navHistory[CATEGORY_ID].substr( navHistory[CATEGORY_ID].indexOf("[")+1 , navHistory[CATEGORY_ID].indexOf("]")-2  );		

		if(temp.indexOf(LINK_ID) == -1){
			temp+=LINK_ID + ",";
			navHistory[CATEGORY_ID] = CATEGORY_ID + "[" + temp + "]"
		}
		
		cookie='';
		for(var x=0;x<navHistory.length;x++){
			cookie+=navHistory[x]+"&";
		}	
		
		cookie = cookie.substr(0,cookie.length-1);
		setCookie("SSTBNavigation",cookie);
	}
	//changes the location of the page to go to the specified link
	function goTo(i,changeLocation,toolbarID){		

		if(!hasChanged){
			updateNavCookie();

			var  URL="";
			if(changeLocation || changeLocation==null){
				URL = window.location.toString().split("?")[0];	
				
				//removes form field
				$("#affinitiessubmit").remove();
				
				if(!toolbarID){
					if(URL.indexOf("createToolbar.jhtml") != -1)
						URL = URL + "?_target" + i;	
					else{
						window.location = "createToolbar.jhtml?" + window.location.toString().split("?")[1];
						return;
					}	
				}	
				else
					URL+= (toolbarID) ? "?t="+toolbarID : "" 
					
				URL = URL.replace(/#/g,'');
				window.location = URL;
			}
		}
		else{
			error=true;
			Modal.display({type:"dialogue", title:"Save Changes",message:"You have not yet saved changes to your toolbar. Are you sure you want to navigate away and lose your changes?",confirmText:"Yes",confirmHandler: function(){ hasChanged=false; goTo(i,changeLocation); } });
			$(".cancel").click(function(){ error=false });
		}
	}
		
	/*displays the selected category and highlights the selected link within that category*/
	function highlightSelected(){
		var navHistory = getCookie("SSTBNavigation");
		navHistory = navHistory.split("&");
		
		if(!LINK_ID) LINK_ID = 0;
		if(!CATEGORY_ID) CATEGORY_ID = 0;
		
		//highlights the currentStepNumber
		$("#StepTitleNum, #StepTitleColor").css("backgroundPosition","0px -" + LINK_ID * 31 + "px");			
		
		try{
			var bgp = $(".jump_step")[LINK_ID+1].style.backgroundPosition.split(" ");
			$(".jump_step")[LINK_ID+1].style.backgroundPosition = bgp[0] + " -28px";
			$(".jump_step")[LINK_ID+1].setAttribute("selected","selected");
		}catch(Exception){}
		
		$("#toolbar_container").css("backgroundPosition","0px -" + (46 * LINK_ID) + "px")
		//changes background image to match theme
		
		$("#content_background").css("backgroundImage","url(" + imageDirectory + "global/" + themes[LINK_ID].background+")");
		
		//highlight the selected category
		$(".side_nav > a").each(function(i){	
			var catHeight = parseInt($(this).css("height"));
			$(this).next("div").css("display","none");
			
			//display the selected category
			if(i==CATEGORY_ID){
				$(this).removeAttr("class");
				$(this).addClass("header_nav_selected");
				$(this).next("div").css("display","block");			
			}
						
			//highlight selected link within each category
			$(this).next("div").find("a").each(function(j){
				//parses the cookie
				var temp = navHistory[i].substr( navHistory[i].indexOf("[")+1 , navHistory[i].indexOf("]")-2  );
				if(temp.indexOf(j)!= -1)
					$(this).addClass("visited");
						
				//sets the background color	
				$(this).css("backgroundImage","url("+imageDirectory + "side_navigation/" + themes[j].linkBackground + ")");
				if(navigation[CATEGORY_ID][j]==LINK_ID){
					//apply the theme colors to the page
					$(this).removeAttr("class");
					$(this).addClass("sub_nav_selected");
					
					THEME_COLOR = themes[j].themeColor;
										
					//stretches the line on the side to the current selected link					
					var linkHeight = parseInt($(this).css("height")) + parseInt($(this).css("padding-top"))-1;
					var height = catHeight*(CATEGORY_ID+1) + linkHeight*(LINK_ID+1) + LINK_ID;
					
					if($(".ToolbarSelectContainer").length !=0){ 
						height += $(".ToolbarSelectContainer")[CATEGORY_ID].clientHeight;
					}

					//stretch the border to where the link is
					$("#sideNavBorder").css("border-color",THEME_COLOR);
					$("#sideNavBorder").css("height",height + 'px');
				}
				
				height=0;
			});
			
			//highlight only the one that was clicked
			if($(this).attr("selected"))
				$(this).css("backgroundPosition",bgp[0]+ " " +newBGPosition);
		});	
	}	
	
	/*initializes the color and click events of the "next and previous" step navigation*/
	function stepNavSetup(element,j){
		$(element).css("backgroundColor",themes[j].themeColor);
		$(element).hover(function(){
			$(element).css("backgroundColor","#666");
		},
		function(){
			$(element).css("backgroundColor",themes[j].themeColor);
		});
		
	}
	
	/*function to remove the Create Section links from the page*/
	function removeSection(which){
		$($(".side_nav > div")[which]).remove();
		$($(".side_nav > a")[which]).remove();
	}	
	
	/*Forces the theme of a particular page that is not in the norma navigational flow*/
	function setTheme(which){
		//sets the previous and next button theme colors
		$(".previousStep").css({backgroundColor:themes[which].themeColor, height: "30px"});				
		$(".nextStep").css({backgroundColor: themes[which+1].themeColor, height: "30px"});
				
		$(".ThemeColor").css("color",themes[which].themeColor);
		
		$($(".side_nav > div > a")[which]).removeAttr("class");
		$($(".side_nav > div > a")[which]).addClass("sub_nav_selected");
		$("#content_background").css("backgroundImage","url("+imageDirectory + "global/" + themes[which].background+")");
					
		var linkHeight = $($(".side_nav > div > a")[which]).css("height");
		linkHeight = parseInt(linkHeight);
		
		//stretch the border to where the link is
		$("#sideNavBorder").css("border-color",themes[which].themeColor);
		$("#sideNavBorder").css("height",linkHeight * (which+2) + 'px');
	}
	