$(function(){
  var hashes;
  
  // Keep a mapping of url-to-container for caching purposes.
  var cache = {
    // If url is '' (no fragment), display this div's content.
    '': $('.page-default')
  };
  
  	var loaded;
  // Bind an event to window.onhashchange that, when the history state changes,
  // gets the url from the hash and displays either our cached content or fetches
  // new content to be displayed.
  $(window).bind( 'hashchange', function(e) {
    loaded = false;
    // Get the hash (fragment) as a string, with any leading # removed. Note that
    // in jQuery 1.4, you should use e.fragment instead of $.param.fragment().
    var url = $.param.fragment();
    hashes = url.split("?");
    url = hashes[0];
    //url = url.replace(".html","");
    //alert(url);
    // Remove .page-current class from any previously "current" link(s).
    $( 'a.page-current' ).removeClass( 'page-current' );
    
    document.title = "Reed College Arts Week - Alchemy";
    
    // Hide any visible ajax content.
    
    $( '.page-content' ).children( ':visible' ).hide();
    
    // Add .page-current class to "current" nav link(s), only if url isn't empty.
    url && $( 'a[href="index.html#' + url + '"]' ).addClass( 'page-current' );
    
    if ( cache[ url ] ) {
      // Since the element is already in the cache, it doesn't need to be
      // created, so instead of creating it again, let's just show it!
      cache[ url ].show();
      loaded = true;
    } else 
	{
      // Show "loading" content while AJAX content loads.
      $( '.page-loading' ).show();
      
      // Create container for this url's content and store a reference to it in
      // the cache.
      cache[ url ] = $( '<div class="page-item"/>' )
        
        // Append the content container to the parent container.
        .appendTo( '.page-content' )
        
        // Load external content via AJAX. Note that in order to keep this
        // example streamlined, only the content in .infobox is shown. You'll
        // want to change this based on your needs.
        .load( url, function(){
			  // Content loaded, hide "loading" content.
			  $( '.page-loading' ).hide();
			  
			  var urlAnchors = hashes;
			//checks for anchor and scolls if so.
			if (urlAnchors[1]) {
				var anchor = '#' + urlAnchors[1] + "_anchor"
				$.scrollTo(anchor);
				//alert(anchor);
				// = hashValue;
				highlight(anchor);
			}	
			
			//alert("1");
		 
        });
    }
	  if (url == "") {
  		$('#imgbar').animate({ height: 361}, 300);
		$('.boxcontent').animate({ height: 351 }, 300);
  
	  }else
	  {	
			$('#imgbar').animate({ height: 65}, 350);
			$('.boxcontent').animate({ height: 55 }, 350);
		
		//color the navigation links
			
	    	
		
		}
		//alert("1.5");
		var urlAnchors = hashes;
		//checks for anchor and scolls if so.
		if (urlAnchors[1] && loaded) {
			//alert(urlAnchors[1]);
			var anchor = '#' + urlAnchors[1] + "_anchor"
			$.scrollTo(anchor);
			//alert(anchor);
			// = hashValue;
			highlight(anchor);
		}	
		
		//alert("2");
		//alert(window.location.hash);
			
			var myNavs=new Array("schedule", "visiting", "student", "professor", "catalogue","press", "info", "contact");
			//go through nav links to check if current, color if so.
			jQuery.each(myNavs, function(i){
				var base = myNavs[ i];
				if ( $('#'+base+'_n').parent().hasClass('page-current') ){
						$('#'+base+'_n').css("background-image", "url(images/"+ base + "_current.png)");
						document.title = "Reed College Arts Week - Alchemy: " + base;
						
				}else
				{
				$('#'+base+'_n').css("background-image", "url(images/"+ base + ".png)");
				}
				
			})
	
  
 });
 
  // Since the event is only triggered when the hash changes, we need to trigger
  // the event now, to handle the hash the page may have loaded with.
  $(window).trigger( 'hashchange' );
  
});

function highlight(name) {
//$(name).animate( { backgroundColor: '#DFD249' }, 0);
$(name).css('background-color', '#cc9966').animate( { backgroundColor: '#878787' }, 700);
//$(name).css('background-color', '#cc9966').css('background-color', '#878787', 500);

}

