// JavaScript Document
//Basically what this script does is try to identify each page via the URL (and in some cases via some other factors) and then add a class related to that page in the body tag; depending on the page, it also add the appends and any other jQuery manipluations

jQuery.noConflict();

(function($) {
$(document).ready(function(){
						
						//********VARIABLES**********

					    //get the url and parse it to identify precise values
						var toggleVal = 0;
						var toggleVal2 = 0;
						var urlTot = window.location.href;
						var urlnoHttp = urlTot.split('//');
						var urlSec = urlnoHttp[1].split('/');
						var urlVal = urlSec[urlSec.length - 1].split('-');
						var urlValEx = urlSec[urlSec.length - 1].split('&');
						var urlValPress = "nothing";
						
						
						if ( !(urlValEx[1]))
						{
						}else
						{
						var urlValPress = urlValEx[1].split('=');
						}

						//get the page title - this is for identifying the individual artwork page from the individual artist main page (with the 16 works); both of those pages use /node/dynamic-tag, so I developed this workaround to parse the two. Basically it looks for the link to the main artist page, which exists on the individual artwork page, and doesn't exist on the individual artist main page; the individual exhibition page also uses /node/dynamic-tag, so I also had to come up with a way to identify seperately from these two pages
						
						//to see how this variable is used, see (2)
						
						var pageTitle = $("h2#page_title span.h a").attr("href");
						if (!(pageTitle))
						{
							pageVal = "nothing";
						} 
						else
						{
							pageVal = pageTitle.split('/');
						}
						
						//get the link information from the Artworks link on the artist main page to determine if it's the main artist page; the main reason I had to do this in addition to the pageTitle variable was to differentiate the individual artis main page from the individual exhibition page, as they both use /node/dynamic-tag
						
						//to see how this variable is used, see (1)
						
						var linkInfo = $("ul#artist_pagenav li#artworks_pagenav a").attr("href");
						if(!(linkInfo))
						{
							var linkInfo = $("ul#artist_pagenav li#aboutartist_pagenav a").attr("href");
							if(!(linkInfo))
							{
								linkVal = "nothing";
							}else{
								linkSplit = linkInfo.split('/');
								linkVal = linkSplit[2].split('?');
							}
							
						}
						else
						{
							linkSplit = linkInfo.split('/');
							linkVal = linkSplit[2].split('?');
						}
						
						//see if checklist is around to identify exhibitions page; same idea as the previous two variables, except now I'm looking to identify the exhibitions page; also checks for the exhbition press releases, as they don't have a checklist length but are part of the exhibitions tree; also checks for gallery press page
						
						//to see how this variable is used, see (3)
						
						var checklistCheck = $('li#checklist_pagenav a').attr("href");
						if (!(checklistCheck))
						{
							if (urlValEx[0] == "exhibitionpre" || urlValEx[0] == "exhibitionbio" || urlSec[urlSec.length - 1] == "gallerypress" || urlValPress[1] == "galleryPressPag")
							{
								exhibitVal = 1;
							}else{
								exhibitVal = 0;
							}
						}
						else
						{
							exhibitVal = 1;
						}

						 //adding special EDG class - we may not need this, but I think some of my CSS already refers to it in some places, so I'm leaving it in for now...we may be able to take this out when I clean up this code
						 $("div#page_wrapper").addClass("edg-page");
						 $("div#content_wrapper").addClass("edg-page");
						 
						 //change logo url to point to WP home page
						 $("div#page_wrapper > a").attr("href", "http://now.elizabethdee.com/");
				
				
						//****************XML RETREIVAL*****************s
						
						//XML parsing is located below the appends section
						//retrieving the XML file for the menu
						$.ajax({
							   type: "GET",
							   url: "/sites/opening_edg/xml/menu.xml",
							   dataType: "xml",
							   success: parseMenuXml
							   });
						
						//retrieving the XML file for the artists sub menu
						if ( (exhibitVal == 0 && urlSec[1] == "node") || urlVal[0] == "artists")
						{
						$.ajax({
							   type: "GET",
							   url: "/sites/opening_edg/xml/artistsSubMenu.xml",
							   dataType: "xml",
							   success: parseArtistsSubMenuXml
							   });
						}
						
						//retrieving the XML file for the artist page slideshow
						if (urlSec[urlSec.length - 1] == "artists")
						{
							$.ajax({
							   type: "GET",
							   url: "/sites/opening_edg/xml/slideshow.xml",
							   dataType: "xml",
							   success: parseSlideShowXml
							   });
						}
						
						//retrieving the XML file for the exhibition sub menu
						if ( (exhibitVal == 1 || urlSec[1] == "current-exhibitions" || urlSec[1] == "past-exhibitions" || urlSec[1] == "future-exhibitions") && urlSec[urlSec.length - 1] != "gallerypress" && urlValPress[1] != "galleryPressPag")
						{
						$.ajax({
							   type: "GET",
							   url: "/sites/opening_edg/xml/exhibitionsSubMenu.xml",
							   dataType: "xml",
							   success: parseExhibitSubMenuXml
							   });
						}
						
						//retrieving the XML file for the address sidebar
						$.ajax({
							   type: "GET",
							   url: "/sites/opening_edg/xml/addressSidebar.xml",
							   dataType: "xml",
							   success: parseAddressXml
							   });
						
						
						//************APPENDS AND OTHER MANIPULATIONS****************
						
						//**Initial appends**
						
						//wrapping the nav bar and logo in a new div
						$("ul#nav").wrap('<div id = "menuBar" />');
						
						//changing About Artist nav option to Biography
					/* elected not to change this in the end
					
						if ( (exhibitVal == 0 && urlSec[1] == "node") || urlVal[0] == "artists")
						{
							$("li#aboutartist_pagenav a").text("Biography");
						} */
						
						// changing Resume to Biography
						
							if ( (exhibitVal == 0 && urlSec[1] == "node") || urlVal[0] == "artists")
						{
							$("li#resume_pagenav a").text("Biography");
						} 
						
						// changing Artworks to Images
						
							if ( (exhibitVal == 0 && urlSec[1] == "node") || urlVal[0] == "artists")
						{
							$("li#artworks_pagenav a").text("Images");
						} 
						
						
						
						//appending right sidebar
						$("div#content_wrapper").append('<div id="sidebar-wrapper"></div>');
						$("div#content_wrapper").append('<br class="clearfloat" />');
						$("h2#page_title").wrap('<div id="page_title_wrapper" />');
						
						
						//change "back" to "view all" on individual artwork page
							$("li#back_pagenav a").text("view all");
						
						//**Specific appends**
						
						//artists page specific appends
						if (urlVal[0] == "artists"){						
						$('h3.page_title').wrap('<div id="hidden" />');
						}
						
						//(1) main individual artist page specific appends
						if (urlSec[1] == "node" && linkVal[0] == urlSec[2] && urlVal[1] != "artworks" && urlSec[3] != "artistabout" && urlSec[4] != "artistabout" && urlSec[3] != "artistcv" && urlSec[4] != "artistcv" && exhibitVal == 0 && urlValEx[0] != "artistpress" && urlValEx[0] != "artistpress" && urlValEx[0] != "artistpressrelease")
						{
							toggleVal = 1;
							$("ul#artist_pagenav").prepend('<h2 id = "artist_name_side"></h2>');
							$("h2#artist_name span.h").clone().appendTo('#artist_name_side');
						}

						//artwork page appends
						if (urlVal[1] == "artworks")
						{
							$("body").addClass('artworks');
							$("artists_nav a").addClass("currentPage");
							$("ul.artwork_details").removeAttr('style');
							$("div#sidebar-wrapper").append('<div id = "artworks_nav"></div>');
							$("h2#page_title span.h").clone().appendTo('#artworks_nav');
							var h = $("div#sidebar-wrapper div#artworks_nav").height();
							var toth = 35 + h + 'px';
							$(".artworks ul#artist_pagenav ul#artist_pagenav").css('top',toth);
							
						}
						
						//I use this alert for debugging purposes:
						//alert(urlValEx[0] + " " + urlSec[1] + " " + pageVal[2]+ " " + urlSec[2]+ " " + urlVal[1]+ " " +urlSec[3] + " " + exhibitVal + " " + toggleVal);	
						
						//(2) individual artwork appends - I've begun to restructure the code here...I realized instead of constantly adding != to differntiate this page from other /node/ based pages, I could just nest them all in else ifs; I've started to do that with the press page, and I plan on eventually moving all artist /node/ based pages into this if/then
						//pageVal[2] != urlSec[2] has been taken out for now - this delinated the main artists page from the individual artwork page, however we are now skipping the main artist page, and this condition was keeping certain individual artwork pages from getting the right appends
						if (urlSec[1] == "node" && urlVal[1] != "artworks" && urlSec[3] != "artistabout" && urlSec[4] != "artistabout" && urlSec[3] != "artistcv" && urlSec[4] != "artistcv" && exhibitVal == 0 && toggleVal != 1)
						{
							//artist press pages appends
							if (urlValEx[0] == "artistpress" || urlValEx[2] == "mode=pag" || urlValEx[1] == "mode=pag" || urlValEx[0] == "artistpressrelease")
							{	
								toggleVal2 = 1;
								$("body").addClass('artistpress');
								$("ul#artist_pagenav").prepend('<h2 id = "artist_name_side"></h2>');
								$("h2#page_title span.h").clone().appendTo('#artist_name_side');
								$("div#content.text").append('<ul id="printLocation"></ul>');
								$("li.print_link").clone().appendTo('ul#printLocation');
							} else 
							{
								$("div#image").addClass('show');
								$("body").addClass('individualArtwork');
								$(".individualArtwork #content").removeAttr('style');
								
								var backRef = $("li#back_pagenav a").attr("href");
								var prevRef = $("li#previous_pagenav a").attr("href");
								var nextRef = $("li#next_pagenav a").attr("href");
								
								//******currently deprecated - may not need but waiting to see******
								if ((!(prevRef)) && (!(nextRef)))
								{
									//$("h2#page_title span.h").wrapInner('<a></a>');
									///$("h2#page_title span.h a").attr('href',backRef);
								}
								
								//setting up Vimeo video so that user only need to enter iframe embed information
								//and ends up with an image that can be clicked to view the video
								
								//we start by checking to see if the video is there by locating the embed url
								$videoCheck = $("#artwork_description iframe").attr("src");
								
								//if that url exists, then run the video code
								if ($videoCheck)
								{
									//the following code hides the iframe, makes the cursor a pointer, and
									//adds a "click image to play video" message
									$("#artwork_description iframe").css('display','none');
									var $vid_iframe = $("#artwork_description").html();
									$("#artwork_description iframe").remove();												
									$("#single_image img").css('cursor','pointer');
									$("#artwork_info").append('<div class="video-message"><p>Click the image to play video</p></div>');
									$("#artwork_info .video-message").append('<a href="#">Close video</a>');
									//this event handler waits for a click on the image, and then shows the video
									$("#single_image img").click(function(){
																		  $("#image").append($vid_iframe);
																		  $("#image #single_image").css('display','none');
																		  $("#image iframe").css('display','block');
																		  $("#artwork_info .video-message p").css('display','none');
																		  $("#artwork_info .video-message a").css('display','block');
				 });
									$("#artwork_info .video-message a").click(function(){
												  $("#image iframe").remove();
												  $("#image #single_image").css('display','block');
												  $("#artwork_info .video-message a").css('display','none');
												  $("#artwork_info .video-message p").css('display','block');
											  });
		  					}//end $videoCheck
							}
						}
						
						//artist press pages appends; sometimes the press pages don't trip the individual artwork appends (2) if/then, not sure exactly why, but this is designed to handle that.
						if ( (urlValEx[0] == "artistpress" || urlValEx[0] == "artistpressrelease") && toggleVal2 != 1)
							{	
								$("body").addClass('artistpress');
								$("ul#artist_pagenav").prepend('<h2 id = "artist_name_side"></h2>');
								$("h2#page_title span.h").clone().appendTo('#artist_name_side');
								$("div#content.text").append('<ul id="printLocation"></ul>');
								$("p.print_link").clone().appendTo('ul#printLocation');
							}
					
						//about artist appends
						if(urlSec[4] == "artistabout" || urlSec[3] == "artistabout")
						{
							$("body").addClass('aboutArtist');
							$("ul#artist_pagenav").prepend('<h2 id = "artist_name_side"></h2>');
							$("h2#page_title span.h").clone().appendTo('#artist_name_side');
							$("div#content.text").append('<ul id="printLocation"></ul>');
							$("p.print_link").clone().appendTo('ul#printLocation');
						}
						
						//artist cv appends
						if(urlSec[3] == "artistcv" || urlSec[4] == "artistcv")
						{
							$("body").addClass('artistcv');
							$("ul#artist_pagenav").prepend('<h2 id = "artist_name_side"></h2>');
							$("h2#page_title span.h").clone().appendTo('#artist_name_side');
							$("div#content.text").append('<ul id="printLocation"></ul>');
							$("p.print_link").clone().appendTo('ul#printLocation');
						}
						
						//NOTE: the append to add the currentPage class to the Exhibitions pages menu item is located under function parseExhibitSubMenuXml(xml); this class basically makes the Exhibition pages menu item bold when a user is on any of those pages

						//(3) individual exhibition page appends
						if (urlSec[1] == "node" && exhibitVal == 1 && urlValEx[0] != "exhibition-artworks" && urlSec[urlSec.length - 1] != "gallerypress" && urlValPress[1] != "galleryPressPag")
						{
							//installation views appends
							if (urlSec[urlSec.length - 1] == "exhibition-installation")
							{
								$("body").addClass('exhibitionInstallation');
								$("ul#page_head ul").append('<li id="controls"></li>');
								$("#content").append('<div id="slideshow-container"></div>');
								$("#slideshow-container").append('<div id="loading"></div>');
								$("#slideshow-container").append('<div id="slideshow"></div>');
								$("#content").append('<div id="caption"></div>');
								$("ul#exhibition_pagenav").prepend('<h2 id = "exhibition_name_side"></h2>');
								
								//copy links from image to a tags wrappging the image to set the page up for gallerific
								$('ul#thumbnail_list li a').each(function(){
																		  //grab the link
																		  var $newLink = $(this).find('img').attr('src');
																		  //copy into the a tags
																		  $(this).attr('href',$newLink);
																		  $(this).addClass('thumb');
																		  });
								//setup captions so gallerific can grab them later
								$('ul#thumbnail_list li').each(function(){
																		var $caption = $(this).find('a').attr('title');
																		$(this).append('<div class="caption">'+$caption+'</div>');
																		});
								$('ul#thumbnail_list').wrap('<div id="thumbs" />');
								$('ul#thumbnail_list').addClass('thumbs');
								$('ul#thumbnail_list').addClass('noscript');
								
								//removing <a> tags from around the exhibition title
								$exhibitTitle = $('#page_title span.h a').text();
								$('#page_title span.h a').remove();
								$('#page_title span.h').text($exhibitTitle);
								$("h2#page_title span.h").clone().appendTo('#exhibition_name_side');
																			  
							//Exhibition press release appends
							} else if (urlValEx[0] == "exhibitionpressrelease" || urlValEx[0] == "exhibitionpre") {
								$("body").addClass('exhibitionPressRelease');
								$("ul#exhibition_pagenav").prepend('<h2 id = "exhibition_name_side"></h2>');
								$("h2#page_title span.h").clone().appendTo('#exhibition_name_side');
								
							} else if (urlValEx[0] == "exhibitionpress" || urlValEx[0] == "exhibitionbio") {
								
								$("body").addClass('exhibitionPress');
								$("ul#exhibition_pagenav").prepend('<h2 id = "exhibition_name_side"></h2>');
								$("h2#page_title span.h").clone().appendTo('#exhibition_name_side');
							} else {
								$("body").addClass('exhibitions');
								$("div#page_title_wrapper h2#page_title span.h").replaceWith('<span class="h">Exhibitions: Current</span>');
								$("div#content.display").removeAttr('style');
								$("ul#exhibition_pagenav").prepend('<h2 id = "exhibition_name_side"></h2>'); //added by jay seems not to be working
								$("h2#exhibition_title span.h").clone().appendTo('#exhibition_name_side'); //added by jay seemsnot to be working
							}
						}
						
						//exhibition artwork appends (checklist)
						if (urlValEx[0] == "exhibition-artworks")
						{
							$("body").addClass('exhibitionArtworks');
							$("ul#exhibition_pagenav").prepend('<h2 id = "exhibition_name_side"></h2>'); //added by jay seems not to be working
							$("h2#page_title span.h").clone().appendTo('#exhibition_name_side'); //added by jay seemsnot to be working
						
						}
						
						//exhibition class for styling - the current, future, and past main pages for exhibitions needs a styling class, primarily for the title styling
						if (urlSec[1] == "current-exhibitions" || urlSec[1] == "past-exhibitions" || urlSec[1] == "future-exhibitions")
						{
							$("body").addClass('exhibitionMain');
							//update individual exhibition link to go directly to installation page using each();
							$("h2.exhibition_title span.h a").each(function(){
																			//first get current url
																			var $exhibiturlOrig = $(this).attr('href');
																			//build new url to go directly to installation page
																			var $exhibiturl = $exhibiturlOrig + "?tpl=tpls/exhibition-installation";
																			//update the href
																			$(this).attr('href',$exhibiturl);
																			});
							//need the same update for the <a> tags wrapping the thumbnail image
							$(".exhibition_image li a").each(function(){
												//first get current url
												var $exhibiturlOrig = $(this).attr('href');
												//build new url to go directly to installation page
												var $exhibiturl = $exhibiturlOrig + "?tpl=tpls/exhibition-installation";
												//update the href
												$(this).attr('href',$exhibiturl);
												});
						}
						
						//gallery press page appends
						if (urlSec[urlSec.length - 1] == "gallerypress")
						{
							$("body").addClass('galleryPress');
							$("div#page_title_wrapper h2#page_title a").text("Selected Press");
						}
						
						//body class appends for news pages
						if (urlSec[urlSec.length - 1] == "news")
						{
							$("body").addClass('news');
						}
						
						if (urlValPress[1] == "galleryPressPag")
						{
							$("body").addClass('galleryPressPage');
						}
						


//***********XML PARSING***************

//parse the menu XML file and appending the contents to the page - for the main menu
function parseMenuXml(xml)
{
$(xml).find("MenuItem").each(function()
										  {
											 $("ul#nav").append('<li id = "' + $(this).find("MenuID").text() + '" ><a href="' + $(this).find("MenuLink").text() + '">' + $(this).find("MenuName").text() + '</a></li>');
											 
						var navVal = '#'+ urlVal[0] + "_nav";
						var subNavVal = "#" + urlVal[0] + "_subnav";
						
						//add a currentPage class to the link relating to the current page
						var getVal = navVal.split('#');
						var testVal = document.getElementById(getVal[1]);
	
							if (testVal == null)
							{
								$(subNavVal + " a").addClass("currentPage");
							} else
							{
								$(navVal + ">a").addClass("currentPage");
							}
											 
											 
										  });
}

//parse the menu XML file and appending the contents to the page - for the artists sub menu 
	function parseArtistsSubMenuXml(xml)
	{
	$("li#artistspage_nav").append('<ul id="artistspage_subnav"></ul>');
	$(xml).find("SubMenuItem").each(function()
										  {
											$("ul#artistspage_subnav").append('<li id = "' + $(this).find("MenuID").text() + '" ><a href="' + $(this).find("MenuLink").text() + '">' + $(this).find("MenuName").text() + '</a></li>');
											 
						var navVal = '#'+ urlVal[0] + "page_nav";
						var subNavVal = "#" + urlVal[0] + "page_subnav";
						
						//add a currentPage class to the link relating to the current page
						var getVal = navVal.split('#');
						var testVal = document.getElementById(getVal[1]);
	
							if (testVal == null)
							{
								$(subNavVal + " a").addClass("currentPage");
							} else
							{
								$(navVal + ">a").addClass("currentPage");
							}			
							
						//setup current artist class to identify current artist
						var $artistName = new String();
						var $artistMenuName = new String();
						$artistName = $('h2#page_title span.h a').text().replace(/ /g,'');
						$artistName = $artistName.replace(/[^a-zA-Z 0-9]+/g,'');
						$('li#artistssub_nav a').each(function(){
															  $artistMenuName = $(this).text().replace(/ /g,'');
															  $artistMenuName = $artistMenuName.replace(/[^a-zA-Z 0-9]+/g,'');
															  if ($artistMenuName == $artistName)
															  {
																  $(this).addClass('currentArtist');
															  }
															  });
						//grab true/false values for artist sub menu from XML file
						//start by grabbing the artist name from menu (so it matches in XML file)
						var $artistName = $("li#artistssub_nav a.currentArtist").text();
						
						//the following replaces the '&' char with an html entity so the comparison with the xml filename will be consistent (otherwise you get one variable with "name & name" and another with "name &amp; name"
						$artistName = $artistName.replace(/[^a-zA-Z 0-9]+/g,'');
																											  					
						//get artist name in the XML file
						var $artistFileName = $(this).find("MenuName").text();
						//find any special entities and convert them to make the string pure text
						var $artistConvert = document.createElement("textarea");
						$artistConvert.innerHTML = $artistFileName.replace(/</g,"&lt;").replace(/>/g,"&gt;");
						$artistFileName = $artistConvert.value;
						//eliminate these special characters to sanitize the string
						$artistFileName = $artistFileName.replace(/[^a-zA-Z 0-9]+/g,'');
						
							//compare these two variables to find the artist nest with the true/false variables
							//also, once the artist name is found in the XML file, the sidebar build process will begin
						    if ($artistFileName == $artistName)
						    {
								var $images = $(this).find("MenuLink").text();
							    var $bio = $(this).find("Bio").text();
								var $pressRelease = $(this).find("PressRelease").text();
								var $press = $(this).find("Press").text();
	
									  //setup sidemenu on artist page
									  //test to make sure it's the individual artwork page
									  var $artworkPageTest = $('#content_wrapper').hasClass('artworkcontentwrapper');
									  
									  if ($artworkPageTest == true)
									  {
										  //artist title variable
										  var $titleText = $("h2#page_title span.h a").text();
										  
										  //build out urls - the Images sub menu item does not have to be built out
										  //first get main artist page url
										  var $mainURL = $('li#back_pagenav a').attr('href');
										  //identify location variable, if any
										  var $urlFirstSplit = $mainURL.split('/');
										  var $urlSecondSplit = $urlFirstSplit[3].split('?');
										  var $numCheck = isNaN($urlSecondSplit[0]);
										  //replace the "artist-artworks" from the main url with the respective address
										  var $biourl = $mainURL.replace('artists-artworks','artistcv');
										  var $pressReleaseurl = $mainURL.replace('artists-artworks','artistpressrelease');
										  var $pressurl = $mainURL.replace('artists-artworks','artistpress');
										  //if the location variable exists, add that to the end of the press and press release urls
										  if ($numCheck == false)
										  {
											  $pressReleaseurl = $pressReleaseurl + "&location=" + $urlSecondSplit[0];
											  $pressurl = $pressurl + "&location=" + $urlSecondSplit[0];
										  }
										  
										  //remove <a> tags from the title so that the user can't access the main artist page
										  $("h2#page_title span.h a").remove();
										  $("h2#page_title span.h").text($titleText);
										  
										  //create the initial parts of the sidebar using append and clone
										  $("div#sidebar-wrapper").append('<div id = "artworks_nav"></div>');
										  
										  //check to see if artist name is two people, and concatenate to just the last names
										  var $nameCheck = $("h2#page_title span.h").text();
										  var $ampCheck = $nameCheck.search('&');
										  if ($ampCheck == -1)
										  {
											  $("h2#page_title span.h").clone().appendTo('#artworks_nav');
										  } else {
										  var $nameSplit = $nameCheck.split(" ");
										  var $nameRecombine = $nameSplit[2] + " & " + $nameSplit[5];
										  $("#artworks_nav").append('<span class="h">'+$nameRecombine+'</span>');
										  }
										  
										  $("div#sidebar-wrapper").append('<ul id="artist_pagenav" class="pagenav"></ul>');
										  //add sidebar elements but only if they are true in the XML file, with the exception of the "Images" link which will be added regardless
										  $('ul#artist_pagenav').append('<li id="artworks_pagenav"><a title="artist artowrks" href="'+$images+'">Images</a></li>');  
										  if ($bio=="True" || $bio =="true")
										  {
										   $('ul#artist_pagenav').append('<li id="resume_pagenav"><a href="'+$biourl+'">Biography</a></li>');  }
										   if ($pressRelease=="True" || $pressRelease =="true")
										  {
										   $('ul#artist_pagenav').append('<li id="pressrelease_pagenav"><a href="'+$pressReleaseurl+'">Press Release</a></li>');  
										  }
										  if ($press=="True" || $press=="true")
										  {
										    $('ul#artist_pagenav').append('<li id="press_pagenav"><a href="'+$pressurl+'">Press</a></li>');  
										  }
									  } 
						}
						
						});
	
	//all exhibition pages - give the exhibitions menu line a current class
						if ( (exhibitVal == 0 && urlSec[1] == "node") || urlVal[0] == "artists")
						{
							$("li#artistspage_nav a").addClass('currentPage');
						}
						
	//clean up artworks pages so none of the links go to the main artist page and fix sidebar when there are two artists
							if(urlSec[3] == "artistcv" || urlSec[4] == "artistcv" || urlValEx[0] == "artistpressrelease"  || urlValEx[0] == "artistpress")
							{
							var $currentLink = $("#artistspage_nav a.currentArtist").attr('href');
							$("li#artworks_pagenav a").attr('href',$currentLink);
							$("span.h a").attr('href',$currentLink);
							
										  var $nameCheck = $("h2#page_title span.h a").text();
										  
										  var $ampCheck = $nameCheck.search('&');
										  if ($ampCheck == -1)
										  {
										  } else {
										  var $nameSplit = $nameCheck.split(" ");
										  var $nameRecombine = $nameSplit[2] + " & " + $nameSplit[5];
										  $("#artist_name_side span.h a").text($nameRecombine);
										  }
							
							}
	}

//parse the menu XML file and appending the contents to the page - for the exhibitions sub menu 
	function parseExhibitSubMenuXml(xml)
	{
	$("li#exhibitionspage_nav").append('<ul id="exhibitionspage_subnav"></ul>');
	$(xml).find("SubMenuItem").each(function()
										  {
											$("ul#exhibitionspage_subnav").append('<li id = "' + $(this).find("MenuID").text() + '" ><a href="' + $(this).find("MenuLink").text() + '">' + $(this).find("MenuName").text() + '</a></li>');
											 
						var navVal = '#'+ urlVal[0] + "page_nav";
						var subNavVal = "#" + urlVal[0] + "page_subnav";
						
						//add a currentPage class to the link relating to the current page
						var getVal = navVal.split('#');
						var testVal = document.getElementById(getVal[1]);
	
							if (testVal == null)
							{
								$(subNavVal + " a").addClass("currentPage");
							} else
							{
								$(navVal + ">a").addClass("currentPage");
							}
											 
											 
										  });
	
	//all exhibition pages - give the exhibitions menu line a current class
						if (exhibitVal == 1 || urlSec[1] == "current-exhibitions" || urlSec[1] == "past-exhibitions" || urlSec[1] == "future-exhibitions")
						{
							$("li#exhibitionspage_nav a").addClass('currentPage');
						}
	}

//parsing the address sidebar XML file and appending the contents to the page
function parseAddressXml(xml)
{
	
	$(xml).find("addressItem").each(function()
											 {
												$("div#sidebar-wrapper").append('<div id="address-wrapper">' + $(this).find("addressLocation").text() +  '<br />' + $(this).find("addressCityZip").text() + '<br />' + $(this).find("addressPhone").text() + '<br />' + $(this).find("addressFax").text() + '</div>');
											 });
	
	
	if ( (urlVal[0] == "artists"  && urlSec[1] != "node") || urlSec[urlSec.length - 1] == "gallerypress"){						
						//retrieving the XML file for the gallery sidebar
						$.ajax({
							   type: "GET",
							   url: "/sites/opening_edg/xml/gallerySidebar.xml",
							   dataType: "xml",
							   success: parseGalleryXml
							   });
						}
	
}

//parsing the projects sidebar XML file and appending the contents to the page
  function parseGalleryXml(xml)
  {
	  $("div#sidebar-wrapper").append('<div id="sidebar-title">Gallery Exhibitions</div>');
	  $(xml).find("galleryItem").each(function()
											   {
												  $("div#sidebar-wrapper").append('<div id="gallery-wrapper"><h2>' + $(this).find("galleryLocation").text() +  '</h2><p>' + $(this).find("galleryName").text() + '</p><p>' + $(this).find("galleryGallery").text() + '</p><p>' + $(this).find("galleryDates").text() + '</p></div>');
											   });
	  
	  //retrieving the XML file for the gallery sidebar upcoming
						$.ajax({
							   type: "GET",
							   url: "/sites/opening_edg/xml/gallerySidebarUpcoming.xml",
							   dataType: "xml",
							   success: parseGalleryUpcomingXml
							   });
	  
  }
  
    //parsing the projects sidebar upcoming XML file and appending the contents to the page
  function parseGalleryUpcomingXml(xml)
  {
	 $("div#sidebar-wrapper").append('<div id="upcoming">upcoming</div>');
	 $(xml).find("galleryItem").each(function()
											   {
												  $("div#sidebar-wrapper").append('<div id="gallery-wrapper"><h2>' + $(this).find("galleryLocation").text() +  '</h2><p>' + $(this).find("galleryName").text() + '</p><p>' + $(this).find("galleryGallery").text() + '</p><p>' + $(this).find("galleryDates").text() + '</p></div>');
											   });
	 
	 //retrieving the XML file for the exhibition sidebar
						$.ajax({
							   type: "GET",
							   url: "/sites/opening_edg/xml/institutionalSidebar.xml",
							   dataType: "xml",
							   success: parseInstitutionalXml
							   });
	 
  }
  
  //parsing the exhibitions sidebar XML file and appending the contents to the page
  function parseInstitutionalXml(xml)
  {
	  $("div#sidebar-wrapper").append('<div id="sidebar-title">Institutional Exhibitions</div>');
	  $(xml).find("institutionalItem").each(function()
											   {
												  $("div#sidebar-wrapper").append('<div id="institutional-wrapper"><h2>' + $(this).find("institutionalLocation").text() + '</h2><p>' + $(this).find("institutionalArtist").text() + '</p><p id="italics">' + $(this).find("institutionalName").text() + '</p><p>' + $(this).find("institutionalGallery").text() + '</p><p>' + $(this).find("institutionalDates").text() + '</p></div>');
											   });
	  
	  //retrieving the XML file for the exhibition sidebar upcoming
						$.ajax({
							   type: "GET",
							   url: "/sites/opening_edg/xml/institutionalSidebarUpcoming.xml",
							   dataType: "xml",
							   success: parseInstitutionalXmlUpcoming
							   });
  }
  
    //parsing the exhibitions sidebar upcoming XML file and appending the contents to the page
  function parseInstitutionalXmlUpcoming(xml)
  {
	  $("div#sidebar-wrapper").append('<div id="upcoming">upcoming</div>');
	  $(xml).find("institutionalItem").each(function()
											   {
												  $("div#sidebar-wrapper").append('<div id="institutional-wrapper"><h2>' + $(this).find("institutionalLocation").text() + '</h2><p>' + $(this).find("institutionalArtist").text() + '</p><p id="italics">' + $(this).find("institutionalName").text() + '</p><p>' + $(this).find("institutionalGallery").text() + '</p><p>' + $(this).find("institutionalDates").text() + '</p></div>');
											   });
  }
  
  function parseSlideShowXml(xml)
  {
	  $("div#content").append('<div id="slider"></div>');
	  $(xml).find("slideshowItem").each(function()
												 {
													 $("div#slider").append('<a href="' + $(this).find("imageLink").text() + '"><img src ="/sites/opening_edg/slideshow/' + $(this).find("imageName").text() + '" title="' + $(this).find("imageCaption").text() + '" /></a>');
												 });
  }

});
	
$(window).load(function(){
							if ($('#content_wrapper').hasClass('artistlistcontent'))
																   {
																	   
										$("div#slider img").each(function(){
										
										$setHeight = $(this).height();
										$(this).attr('height',$setHeight);
										
										})		
																	   
										  $('#slider').nivoSlider({
													  effect: 'fade',
													  animSpeed:1000,
													  pauseTime:7000,
													  directionNav: false,
													  controlNav:false,
													  controlNavThumbs:false,
													  manualAdvance:false
													  });
																   }
});


$(window).bind('load', function(){			   
	  
	  							if ($('#content_wrapper').hasClass('exhibitioninstallationswrapper'))
																   {
	  								//gallerific calls
								    var gallery = $('#thumbs').galleriffic({
													  delay:                     3000, // in milliseconds
													  numThumbs:                 20, // The number of thumbnails to show page
													  preloadAhead:              40, // Set to -1 to preload all images
													  enableTopPager:            false,
													  enableBottomPager:         false,
													  maxPagesToShow:            7,  // The maximum number of pages to display in either the top or bottom pager
        											  imageContainerSel:         '#slideshow', // The CSS selector for the element within which the main slideshow image should be rendered
        											  controlsContainerSel:      '#controls', // The CSS selector for the element within which the slideshow controls should be rendered
        											  captionContainerSel:       '#caption', // The CSS selector for the element within which the captions should be rendered
        											  loadingContainerSel:       '#loading', // The CSS selector for the element within which should be shown when an image 
													  renderSSControls:          false, // Specifies whether the slideshow's Play and Pause links should be rendered
													  renderNavControls:         true, // Specifies whether the slideshow's Next and Previous links should be rendered
													  playLinkText:              'Play',
													  pauseLinkText:             'Pause',
													  prevLinkText:              '&laquo; previous',
													  nextLinkText:              'next &raquo;',
													  nextPageLinkText:          'Next &rsaquo;',
													  prevPageLinkText:          '&lsaquo; Prev',
													  enableHistory:             false, // Specifies whether the url's hash and the browser's history cache should update when the current slideshow image changes
													  enableKeyboardNavigation:  false, // Specifies whether keyboard navigation is enabled
													  autoStart:                 false, // Specifies whether the slideshow should be playing or paused when the page first loads
													  syncTransitions:           false, // Specifies whether the out and in transitions occur simultaneously or distinctly
													  defaultTransitionDuration: 1000, // If using the default transitions, specifies the duration of the transitions
													  onSlideChange:             undefined, // accepts a delegate like such: function(prevIndex, nextIndex) { ... }
													  onTransitionOut:           undefined, // accepts a delegate like such: function(slide, caption, isSync, callback) { ... }
													  onTransitionIn:            undefined, // accepts a delegate like such: function(slide, caption, isSync) { ... }
													  onPageTransitionOut:       undefined, // accepts a delegate like such: function(callback) { ... }
													  onPageTransitionIn:        undefined, // accepts a delegate like such: function() { ... }
													  onImageAdded:              undefined, // accepts a delegate like such: function(imageData, $li) { ... }
													  onImageRemoved:            undefined  // accepts a delegate like such: function(imageData, $li) { ... }
												  });
																   }
								
								});
		  })(jQuery)
