//Speshardt-klein Javascript created by Devin Hartman using jQuery
//and various plugins 
//mr.devin@gmail.com
//2007      


//this function is called by the OnClick for artist nav
//the switch case statements determine what page is going to be loaded. 
function Switch(loadpage){        
	$("div#artistContent").hide();
	$("#artistRemove").fadeOut("fast");
	$.ajax({
		type: "GET",
		timeout: 1000,
		url: loadpage,
		dataType: "html",
		success: function(responseText){ 
			$('#artistContent').html(responseText); 
			$('#artistContent').fadeIn("slow");
			return false;
			},
		error:function(){
			return true;
		}
			
			});

};     


     
$(document).ready(function(){
      		 
//*********************************************************************************************************
//*********************************************************************************************************
//***********************************This Section controls the LeftNav3************************************
//*******************************************the three level nav on the left*******************************
//*********************************************************************************************************  
//*********************************************************************************************************
        //We Want to load the appropriate Nav on the Appropriate page
		//Set the contecnt of the title attribute to currentTtile var
		//We will also add the selected class to the correct li item in the topnav
		var currentTitle = $("title").html();
		//depending on title we choose which file to load
	    switch(currentTitle){
			case "Spesshardt &amp; Klein ~ Archive" :
			$("div#leftNav3").load("archive_leftNav3.html","",function(){leftNav3();});
			$('ul#topNav>li>a[href=\"archive.html\"]').parent().addClass("selected");
			break; 
			
			case "Spesshardt & Klein ~ Archive" :
			$("div#leftNav3").load("archive_leftNav3.html","",function(){leftNav3();});
			$('ul#topNav>li>a[href=\"archive.html\"]').parent().addClass("selected");
			break;
			
			case "Spesshardt &amp; Klein ~ Press" :
			$("div#leftNav3").load("press_leftNav3.html","",function(){leftNav3();});
			$('ul#topNav>li>a[href=\"press.html\"]').parent().addClass("selected");
			break;
			
			case "Spesshardt & Klein ~ Press" :
			$("div#leftNav3").load("press_leftNav3.html","",function(){leftNav3();});
			$('ul#topNav>li>a[href=\"press.html\"]').parent().addClass("selected");
			break;
			
			case "Spesshardt &amp; Klein ~ Artists" :
			$("dl#artistNav").load("artistNav.html","",function(){artistNav();});      
			$('ul#topNav>li>a[href=\"artists.html\"]').parent().addClass("selected");
			break;
			
			case "Spesshardt & Klein ~ Artists" :
			$("dl#artistNav").load("artistNav.html","",function(){artistNav();});      
			$('ul#topNav>li>a[href=\"artists.html\"]').parent().addClass("selected");
			break;
	        
			
			case "Spesshardt &amp; Klein ~ News"  :
			scrollNow(); 
			$('ul#topNav>li>a[href=\"index.html\"]').parent().addClass("selected");
			break;
			
			case "Spesshardt & Klein ~ News"  :
			scrollNow(); 
			$('ul#topNav>li>a[href=\"index.html\"]').parent().addClass("selected");
			break;
			
			case "Spesshardt &amp; Klein ~ Contact" :
			$('ul#topNav>li>a[href=\"contact.html\"]').parent().addClass("selected");
			break;  
			
			default:
			break;
		}        
		
		//Here IS the JS for a there level leftNav3 and artistNav
		//get the path name 
		var path = location.pathname;  
		// split up the path name and assign to new_array
		new_array = path.split("/"); 
		//reverse array
		new_array.reverse(); 
		//parssedPath is now asiigned to the last element in the url string
		var parsedPath = new_array[0]; 
		//chech for sring_eng att the end of pathname and remove
		parsedPath = parsedPath.replace("_eng.html", ".html");
		
		function leftNav3(){
		    //now find an <a> that has the same path and then add class current
	        $('#leftNav3 ul li dl dd a[href=\"' + parsedPath + '\"]').parents(['dl'],['dd']).addClass("current");
			$('#leftNav3 ul li dl dt a[href=\"' + parsedPath + '\"]').parents(['dl'],['dt']).addClass("current");
			//Hide everythhing but the link to the surrent page
		 	$("#leftNav3 ul li dl:not(.current)").hide();
			//establish click listener on first level and on click show second level element and hide oter similar open elements
			$("div#leftNav3>ul>li>a").click(
				function(){
		   		$("div#leftNav3 dl:visible").slideUp("slow");
				$(this).next().slideDown("slow"); 

		    return false;
			}
			);
			//this hides every second level element except the ones set to current
			$("#leftNav3 li dl dd:not(.current)").hide();
			//establish click listener on secon level and on click show third level element and hide oter similar open elements 
			$("div#leftNav3>ul>li>dl>dt>a").click(
				function(){
				var dtPath = $(this).attr("href")
				new_array = dtPath.split("/");
				new_array.reverse(); 
				var parsedPath = new_array[0]; 
				//chech for sring_eng att the end of pathname and remove
				parsedPath = parsedPath.replace("press.html", " ");
			    var myExp = new RegExp("#" );
			    $("div#leftNav3 ul li dl dd:visible").slideUp("slow");  
				if(myExp.test(parsedPath) === true){
					$(this).parent().next().slideDown("slow"); 
			    	return false;
				}
				else{ return true; }

			}
			);
		 }
		
		
					                                         
	  	
		
//*********************************************************************************************************
//*********************************************************************************************************
//***********************************This Section controls the artistNav***********************************
//****************************************the nav in the artist section************************************
//*********************************************************************************************************
//*********************************************************************************************************      
		
		function artistNav(){  
		//now find an <a> that has the same path and then add class current
        $('#artistNav dd ul li a[href=\"' + parsedPath + '\"]').parents('dd').addClass("current");  
	    //if the class is set to current do nothing otherwise hide other dd tags  
		$("#artistNav dd:not(.current)").hide(); 
		//On the click event set other dd tags to hide 
		//and show the dd that is next to the dt that has been clicked
		$("#artistNav dt a ").click(function(){ 
			var artName = $(this).html(); 
			
		    $("#artistNav dd:visible").slideUp("slow");
		    $(this).parent().next().slideDown("slow");
			switch(artName)
				{   
					case "Carmen Brucic" :
						Switch("CarmenBrucic_Info.html");
						break;
					case "Matthew Burbidge" :
						Switch("MatthewBurbidge_Info.html");
						break;
                    case "Franziska Holstein" :
				  		Switch("FranziskzHolstein_Info.html");
				   		break;
				    case "Alexandra Hopf" :
				   		Switch("AlexandraHopf_Info.html");
				   		break;
				 	case "Bettina Krieg" :
			      		Switch("BettinaKrieg_Info.html");
			 	   		break;
	   				case "Markus Krieger" :
			  	   		Switch("MarkusKrieger_Info.html");
			     		break;
			  		case "Stefanie Schneider" :
			       		Switch("StefanieSchneider_Info.html");
	  			   		break;
	   				case "Jaro Straub" :
	    	   			Switch("JaroStraub_Info.html");
						break;
					default:
					  break;
				};              
				
			   
            
			});
			
			 //this is for the images and links in the main cContent section o artist.html
			$("dl#artistColumn1 dt a, dl#artistColumn2 dt a").click(function(){ 
				var artName = $(this).attr("href");
				switch(artName)
					{
					    
						case "MatthewBurbidgeGallery.html" :
							Switch("MatthewBurbidge_Info.html");
							$("#artistNav dt a:contains(Matthew Burbidge)").parent().next().slideDown("slow");
							break;
	                    case "FranziskaHolsteinGallery.html" :
					  		Switch("FranziskzHolstein_Info.html");
							$("#artistNav dt a:contains(Franziska Holstein)").parent().next().slideDown("slow");
					   		break;
					    case "AlexandraHopfGallery.html" :
					   		Switch("AlexandraHopf_Info.html");
							$("#artistNav dt a:contains(Alexandra Hopf)").parent().next().slideDown("slow");
					   		break;
					 	case "BettinaKriegGallery.html" :
				      		Switch("BettinaKrieg_Info.html");
							$("#artistNav dt a:contains(Bettina Krieg)").parent().next().slideDown("slow");
				 	   		break;
		   				case "MarkusKriegerGallery.html" :
				  	   		Switch("MarkusKrieger_Info.html");
							$("#artistNav dt a:contains(Markus Krieger)").parent().next().slideDown("slow");
				     		break;
				  		case "StefanieSchneiderGallery.html" :
				       		Switch("StefanieSchneider_Info.html");
							$("#artistNav dt a:contains(Stefanie Schneider)").parent().next().slideDown("slow");
		  			   		break;
		   				case "JaroStraubGallery.html" :
		    	   			Switch("JaroStraub_Info.html");
							$("#artistNav dt a:contains(Jaro Straub)").parent().next().slideDown("slow");
							break;
							
						
						default:
						  break;
			   	   };//end switch
			return false;
			}); 
		}
		

//*********************************************************************************************************
//*********************************************************************************************************
//***********************************This Section controls the LeftNav Scroller****************************
//******************************this scroller that appears on the left in the NEWS section*****************
//*********************************************************************************************************
//*********************************************************************************************************		
	 
		function scrollNow(){//Load the file Called scroller_text.html and insert into 
		//the DIV with an id of leftNav 
		$("div#leftNav").load("scroller_text.html",  "", function(){
		//use the callback to make aninstance of the cycle plug-in 	
			$('#scrollup').cycle({ 
		    		fx:     'scrollUp', 
					speed:   1000,
		            delay: -4000,
				    timeout: 5000, 
				    next:   '#scrollUp', 
				    pause:   1  
				});
							
		});
		} 
		
	   
			// here we start two new lightBox instances by finding all links where the rel tag is set to...
			$('a[@rel*=LightboxImg]').lightBox(); // Select all links that contains lightbox in the attribute rel
			$('a[@rel*=LightboxText]').lightBox(); // Select all links that contains lightbox in the attribute rel
		   
		
});  

