﻿jQuery(function() {                                         

	// SELECTED TOP NAV MENU STYLE ---------------------------------------------------------------------------------------------		
			
			$("div.menu-horizontal > ul > li > ul > li.selected > a").wrap(
				"<div id='selNavWrapper'>" +
					"<div id='selNavCenter'></div>" +
					"<div id='selNavLeft'></div>" + 
					"<div id='selNavRight'></div>" +  
				"</div>");
			
	// MASTERPAGECONTENT LIST DATA ---------------------------------------------------------------------------------------------
			var currentURL = location.pathname;	
			var currentLanguage = currentURL.substring(1, 3).toLowerCase(); // this needs to be parsed from the url 
			var languageList = ''; // variable to hold the list of languages to show in the lang hover menu
			
			$().SPServices({
			    operation: "GetListItems",
			    async: false,
			    webURL: "/",
			    listName: "MasterPageContent",
			    CAMLViewFields: "<ViewFields><FieldRef Name='Title' /><FieldRef Name='Language' />" +
			    				"<FieldRef Name='FooterLinks' /><FieldRef Name='FooterText' />" + 
			    				"<FieldRef Name='HeaderLinks' /><FieldRef Name='SiteUrl' />" +
			    				"<FieldRef Name='SiteLanguage' /><FieldRef Name='FlagImage' />" +
			    				"</ViewFields>",
			    completefunc: function (xData, Status) {
						$(xData.responseXML).find("[nodeName='z:row']").each(function() { 
							
							// if we're on the current language we need to set the header
							// nav, footer nav, footer text and the current language & map
							if ($(this).attr("ows_SiteLanguage").toLowerCase() == currentLanguage)
							{
								$("div#headerNav").html($(this).attr("ows_HeaderLinks"));
								$("div#FooterNavigation").html($(this).attr("ows_FooterLinks"));
								
								$("div#FooterNavigation li:last-child").css({'border': '0'});
								$("div#FooterText").html($(this).attr("ows_FooterText"));
								
								// if the current url is part of the header nav, show the selected
								// nav item with the dark gray background
								$("div#headerNav a[href='" + 
									window.location.pathname + "']").wrap(
									"<div id='selHeaderNavWrapper'>" +
										"<div id='selHeaderNavCenter'></div>" +
										"<div id='selHeaderNavLeft'></div>" + 
										"<div id='selHeaderNavRight'></div>" +  
									"</div>");
									
								// set up the current language and the div that will hold
								// all of the language options the user can select
								$("div#languageSelector").html($(this).attr("ows_Title") +
									" " + "<img src='" + $(this).attr("ows_FlagImage").replace(", ", "") + "' id='languageFlag' width='18' height='12' />&nbsp;" +
		                   			"<img src='/SiteStructureImages/language_arrow.jpg' id='showLangPicker' width='4' height='7' vspace='2' />" +
		                   			"<div id='languageOptions'></div>");
							}
							
							//we need to set up the list of languages
							if ($(this).attr("ows_LanguageAbbreviation") == currentLanguage)
							{
								// if we're on the current language we need to change the  
								// css so that we can style this row differently
								languageList += "<li class='selectedLanguage'><a href='" + $(this).attr("ows_SiteUrl") + "'><img src='" + $(this).attr("ows_FlagImage").replace(", ", "") + "' width='18' height='12' align='baseline' /></a>" +  
										"<a href='" + $(this).attr("ows_SiteUrl") + "'>" + $(this).attr("ows_Title") + "</a></li>";
							 }else
							 {
								languageList += "<li><a href='" + $(this).attr("ows_SiteUrl") + "'><img src='" + $(this).attr("ows_FlagImage").replace(", ", "") + "' width='18' height='12' align='baseline' /></a>" +  
										"<a href='" + $(this).attr("ows_SiteUrl") + "'>" + $(this).attr("ows_Title") + "</a></li>";
							 }
					});						
				} // end - completefunc: function
			 }); // end - SPServices
			 
			//add all languages in the languageList to the languageOptions div
			$("div#languageOptions").html("<ul>" + languageList + "</ul>");
			
			// language selector animation
			$('div#languageSelector').click(function(){
				$("div#languageOptions").slideToggle('slow');
			});
			
						
	// LEFT NAVIGATION ---------------------------------------------------------------------------------------------		

			var outerLevelSelected = false;
			
			// the outer selector gives me all the second level nav elements
			$("div.menu-vertical > ul > li").each(function() { 
				// bold the text if this 2nd level nav item is selected
				$(this).find("> a.selected").each(function() {
					$(this).css("font-weight", "bold");
					// show the 3rd level nav
					$(this).closest("li").children("ul").toggle();
					outerLevelSelected = true;
				});
			
				if (!outerLevelSelected)
				{
					var hasSelectedChildren = false;
					
					// loops through all 3rd level nav items
				    $(this).children("ul").children("li").each(function() { 
				         
				         // if the current 3rd level nav is selected
				         // bold the text and set the hasSelectedChildren to true
				         $(this).find("> a.selected").each(function() {
				             $(this).css("font-weight", "bold");
				             hasSelectedChildren = true;
				             
				             //show 3rd level nav
				             $(this).closest("ul").toggle();
				             
				            // the 3rd level nav is selected so we need
					    	// to show the 4th level nav                                         
					        $(this).closest("li").children("ul").toggle();
					        
					        //we've found the selected navigation so
					 		//we can stop looping through the children
				            return false;
				         }); 
				         
				        if (hasSelectedChildren == false)
						{
							// If one of the 4th level nav items is selected 
							// bold the selected item, set the hasSelectedChildren 
							// to true, and show the 3rd and 4th level nav                                           
					        $(this).children("ul").children("li").each(function(){
					        	$(this).find("> a.selected").each(function() {
				
						              $(this).css("font-weight", "bold");
				                 	  hasSelectedChildren = true;
				                 	 				        
				                 	 //show 3rd level nav
				                 	 $("div.menu-vertical > ul > li > ul").toggle();
				                 	 
				                 	 // show fourth level nav
				                 	 $(this).closest("ul").toggle();
				                 	 
				                 	 //we've found the selected navigation so
					 				 //we can stop looping through the children
				                 	 return false;
				                });
					        });
						}        
						else
						{
							//we've found the selected navigation so
							//we can stop looping through the children
							return false;
						}             
				    });
				    
				    // if any of the 2nd level nav's children elements 
				    // are selected then bold this element
				    if (hasSelectedChildren == true)
				    {
				    	$(this).find("> a").css("font-weight", "bold");
				    	//we've found the selected navigation so
						//we can stop looping through the children
			         	return false;
				    }
				} // end if (!outerLevelSelected)
			});
			
			
	// SHARETHIS
		$("#ShareThisBox").html("<span  class='st_linkedin' ></span><span  class='st_email' ></span><span  class='st_twitter' ></span><span  class='st_sharethis' ></span>" + 
				"<script type='text/javascript'>var switchTo5x=true;</script><script type='text/javascript' src='http://w.sharethis.com/button/buttons.js'></script>" + 
				"<script type='text/javascript'>stLight.options({publisher:'dc0356b6-1dbd-4f75-ad3e-a199a11c33f2'});</script> ");
				
		$("#ShareThisBlogBox").html("<span  class='st_linkedin' ></span><span  class='st_email' ></span><span  class='st_twitter' ></span><span  class='st_sharethis' ></span>" + 
				"<a href='http://www.thyssenkruppwaupaca.com/_layouts/feed.aspx?xsl=1&web=%2FEN%2FBlog&page=c5b1b44d-80b1-41b4-ae7c-45ff73479edd&" +
				"wp=f12f4a4d-fec1-4f1e-b8ef-9833bacdb496&pageurl=%2FEN%2FBlog%2FPages%2Fdefault%2Easpx' target='_blank' class='blogRSSIcon'>" +
				"<img  src='/SiteStructureImages/RSS.png' align='bottom' /></a>" +
				"<script type='text/javascript'>var switchTo5x=true;</script><script type='text/javascript' src='http://w.sharethis.com/button/buttons.js'></script>" + 
				"<script type='text/javascript'>stLight.options({publisher:'dc0356b6-1dbd-4f75-ad3e-a199a11c33f2'});</script> ");

							
		}); // end - jQuery(function()         				                     
