﻿$(document).ready(function(){
//Start common code

    //Caption
    jQuery("html").find("img.caption").each(function(i){
        var altText = jQuery(this).attr("alt");
        var imgWidth = jQuery(this).width();
        jQuery(this).wrap("<div class='captionBox' style='width:"+imgWidth+"px'></div>");
        jQuery(this).after("<p>"+altText+"</p>");
    });
    
    //Suckerfish class for IE6 hover on the Primary navigation
    jQuery("#primaryNavigation li").hover(
      function () {
        jQuery(this).addClass("sfhover");
      }, 
      function () {
        jQuery(this).removeClass("sfhover");
      }
    );
    
    
    //set up the Accordian menu
    
    //Hide all but the parent list items
	jQuery(".toShow").hide();
	// but the first parent
	jQuery("#pageRoomsFlash .toShow:first").show();	
		
	//Start Accordian image swapping function
	//for all "parents" (.parent) find the the first child (>) that is a link (a) . . .
	jQuery(".parent > a").each(function(i){
	
	    //Get href of the image in the list item - we'll assign this to "accordianImage" later
        var theSrc = jQuery(this).attr("href");
        //Get the text of the link and we'll use it as the alt text for the target image #accordianImage
        var theAltText = jQuery(this).text();
        
        //Start click function
        jQuery(this).click(
          function () {
            jQuery(".toShow:visible").slideUp("fast");
            jQuery(".showing:visible").slideUp("fast");
		    jQuery(this).next().slideDown("slow");
            //Chained actions for galleryImage
            jQuery("#accordianImage")
                .hide()
                .attr("src", theSrc)
                .attr("alt", theAltText)
                .fadeIn("normal")
            ;
            //stop the link working
            return false;
          }
        );
        //End click function
        
    });
    //End Accordian image swapping function
    
    
    //Add Print page link and remove the class of last from "Back to Map"
    jQuery("#BackAndPrint li:first").removeClass("last").after("<li class='last'><a href='javascript:window.print();'>Print</a></li>");
    
    
    //Gingham table function works with gingham CSS in common.css
	jQuery(".gingham thead tr#secondaryHeadings th:first-child").attr("id","firstHeading");	
	jQuery(".gingham tr").find("td:odd").each(function(i){
        jQuery(this).addClass("odd");
    }); 
    
    /*the "more information reveal function"*/
        jQuery("html").find(".moreInformation > .toClick").each(function(i){
            jQuery(this).prepend("<a class='openButton plus' href='#'></a>");
        });
        
        /*hide the paragraph of content*/
        jQuery(".moreInformation").find(".infoToShow").each(function(i){
            jQuery(this).hide();
        });
           
        /*click the "+" and reveal the paragraph, change to a minus and click to hide*/    
         jQuery(".moreInformation  a.openButton").toggle(function(e) {
            jQuery(this).parent().parent().find(".infoToShow").show('slow', function() {
                jQuery(this).parent().find("a.openButton").removeClass("plus");
                jQuery(this).parent().find("a.openButton").addClass("minus");

            });
         }, function(e) {
            jQuery(this).parent().parent().find(".infoToShow").hide('fast', function() {
               jQuery(this).parent().find("a.openButton").removeClass("minus");
                jQuery(this).parent().find("a.openButton").addClass("plus");
            });
         });
      
    //Show caption on main image on start-up
    
    /*var altText = jQuery("#galleryImage").attr("alt");
    jQuery("#galleryImage")
        //.attr("alt", altText)
        .fadeIn("normal")
        .after("<p class='caption'><span>" + altText + "</span><span class='visualEffect'></span></p>")
        ;
    */
        
    /*Chained caption animation
        jQuery("#galleryImageContainer p.caption")
            .hide()
            .animate({"height": "toggle", "opacity": "toggle"},800)
            //This acts as a delay 
            .animate({bottom:0}, 5000)
            .fadeOut("slow")
        ; 
    */
         
    //Start Gallery function
		jQuery("#galleryList").find("img").each(function(i){
		
		    //Get the alt and src of the image in the list
            var altText = jQuery(this).attr("alt");
            var theSrc = jQuery(this).parent().attr("href");
            
            //set the link title attribute using the images alt text 
            //jQuery(this).parent().attr("title",altText);
            
            //Start click function
            jQuery(this).parent().click(
              function () {
                //fade out any existing caption
                //jQuery("#galleryImageContainer p.caption").remove(); 
                                            
                //Chained actions for galleryImage (visually stacked up so you can read them)
                
                
                jQuery("#galleryImage")
                    .hide()
                    .attr("src", theSrc)
                    .fadeIn("normal")
                ;
                
               
                //Chained caption animation
                jQuery("#galleryImageContainer p.caption")
                    .hide()
                    .animate({"height": "toggle", "opacity": "toggle"},800)
                    //This acts as a delay 
                    .animate({bottom:0}, 5000)
                    .fadeOut("slow")
                ;
                
                jQuery.fn.fadeCaption = function(){
                    this.find("a").hide();
                    return this;
                };
                
                
                //stop the link working
                return false;
              }
            );
            //end click function
            
        });
        //end gallery function
        
        //map fade in function
        jQuery("#map a").find("img").each(function(i){
            jQuery(this)
            //This acts as a delay 
            .animate({bottom:0}, 500)
            .hide()
            .fadeIn("slow");
        });

//End common code       
});

