function handlejquery(galleries, galleryPlaceHolder, initialGallery){ 

    handleWindowScrollbars();
    /*********************************************************
        Slideshow 
    *********************************************************/    

	function initializeGallery(thumbsContainerSel) {
	    return $(thumbsContainerSel).galleriffic(thumbsContainerSel, {
	        delay:                     2000,
	        numThumbs:                 9999,
	        preloadAhead:              -1,
	        enableTopPager:            false,
	        enableBottomPager:         false,
	        imageContainerSel:         '.slideshow',
	        loadingContainerSel:       '#loading',
	        renderSSControls:          false,
	        renderNavControls:         false,
	        enableHistory:             true,
	        autoStart:                 false,
			syncTransitions:           true,
			defaultTransitionDuration: 1000
	        });
	}
	
        
        
        
    /*********************************************************
        Nav Links
    *********************************************************/

	// Fade In of Nav on Hover
	var onMouseOutOpacity = 0.5;
	$('#clients img').css('opacity', onMouseOutOpacity)
		.hover(
			function () {
				var $img = $(this);
				if ($img.parents('#clients li').not('.current').length > 0)
					$img.fadeTo('fast', 1.0);
			}, 
			function () {
				var $img = $(this);
				if ($img.parents('#clients li').not('.current').length > 0)
					$img.fadeTo('fast', onMouseOutOpacity);
			}
		);

    /*
    
    This is required but is specified page for page.
    
	var initialGallery = '#commercial-1';
	var galleryPlaceHolder = 'notloaded';
	
	// We will specify the galleries that will available here, but load them lazily
	var galleries = {
		'#commercial-1' : galleryPlaceHolder,
		'#commercial-2' : galleryPlaceHolder
	};
	
	*/
	
	function isGalleryInitialized(key) {
		return galleries[key] != galleryPlaceHolder;
	}
	
	function loadGallery(key) {
		if (galleries[key]) {
			if (!isGalleryInitialized(key)) {
				var found = false;
				$('div.thumbs-container').each(function() {
					if (!found) {
						var relGallery = $(this).attr('rel');
						var galleryId = '#' + relGallery;
						if (galleries[galleryId] && !isGalleryInitialized(galleryId))
							galleries[galleryId] = initializeGallery('div.thumbs-container[rel="'+relGallery+'"]');
						
						if (galleryId == key)
							found = true;
					}
				});
			}

			var gallery = galleries[key];

			// Hide thumb navigation for all galleries
			$('div.thumbs-container').hide();
			
			// Show thumbs for just the current gallery
			gallery.$thumbsContainer.show();

			// Remove selected client nav style from all nav items
			// and then re-add to selected item
			$('#clients li').removeClass('current')
				.find("a[href='" + key + "']")
				.parent()
				.addClass('current')
				.find('img')
				.fadeTo('fast', 1.0);

			$('#clients li').not('.current').find('img').fadeTo('fast', onMouseOutOpacity);

			return gallery;
		}

		return undefined;
	}

	function syncGallery(hash) {
		if (hash) {
			var gallery = loadGallery('#' + hash);
			if (gallery) {
				$.galleriffic.goto(gallery.offset);
				return;
			} else if (!isNaN(hash)) {
				var $thumbsContainer = $('ul.thumbs a.thumb').eq(+hash).parents('div.thumbs-container');
				if ($thumbsContainer.length > 0) {
					var galleryId = $thumbsContainer.attr('rel');
					if (galleryId) {
						galleryId = '#' + galleryId;
						gallery = loadGallery(galleryId);
						if (gallery) {
							$.galleriffic.goto(hash);
							return;
						}
					}
				}
			}
		}

		// Load initial gallery if needed
		if (!isGalleryInitialized(initialGallery)) {
			loadGallery(initialGallery).goto(0);
		}
	}
	
	
	// PageLoad function
	// This function is called when:
	// 1. after calling $.historyInit();
	// 2. after calling $.historyLoad();
	// 3. after pushing "Go Back" button of a browser
	function pageload(hash) {
		// alert("pageload: " + hash);
		// hash doesn't contain the first # character.
		
		syncGallery(hash);
		
		if(hash) {
			
		} else {
			
		}
	}

    /*********************************************************
        Resize
    *********************************************************/   
	$("#MySplitter").splitter({
		type: "v",
		outline: true,
		minLeft: 0, sizeRight: 0, minRight: 0,
		resizeToWidth: true,
		anchorToWindow: true,
		/* cookie: "vsplitter", */
		accessKey: 'I'
	});

    /*********************************************************
        Animation
    *********************************************************/   
    $("#black").animate({ 
        right: "0"
    }, 1 );  
      
    
    $("#zlarge").click(function(){
        $("#zlarge").animate({ 
            top: "20px",
            left: "10%",
            height: "129px",
            width: "132px",
            opacity: "hide"
        }, 500 );    
      
        $("#z").animate({ 
            opacity: "show"
        }, 1000 );      
    
        $("#black").animate({ 
            width: "2000px",
            right: "0px"
        }, 1000 );

        $("#MySplitter").trigger("resize", [ 321 ]);        
        
        $("#nav").animate({ 
            opacity: "show"
        }, 4500 );

        $("#home-images").animate({ 
            opacity: "show"
        }, 8500 );

        $("#home-building").animate({ 
            opacity: "show"
        }, 500 );

        $("#portfolio").animate({ 
            opacity: "show"
        }, 4500 );
        
        $("#white-block").animate({ 
            opacity: "hide"
        }, 4200 );  
        
        $("#home-building").animate({ 
            opacity: "hide"
        }, 6600 );
      
    });
        
    
    
    $("a[rel='fadeout']").click(function(){ 
        var hrefLoc = $(this).attr('href'); 
        
        
        //trans_black_bg_to_white_bg();
        
        
        $('body').fadeOut("slow",function(){ 
            window.location = hrefLoc; 
        }); 
        return false; 
    }); 
    
    
    $(".black-to-white").click(function(){
        trans_black_bg_to_white_bg();
    });
    
    
    function trans_black_bg_to_white_bg(){
        /* Hide the portfolio */
        hide_portfolio();
        
        $("#MySplitter").trigger("resize", [ 210 ]);   

        $("#black").css("width","2000px");
        $("#black").css("right","0");
        
        $("#blackleft").css("width","210px");
        $("#blackleft").css("left","210px");

        $("#white-block").css("display","none");
        $("#z").css("width","130px");

        $('#nav').css("display","none");        
        $('#nav a').css("background-position","0 -14px");

        /* Pan black boxes */
        $("#black").animate({ 
            width: "0px",
            left: "0px"
        }, 800 );
        
        $("#blackleft").animate({ 
            left: "0px"
        }, 800 );
        
        $("#nav").animate({ 
            opacity: "show"
        }, 2800 ); 

        $("#text").animate({ 
            opacity: "show"
        }, 2800 );      
    }
    
    function hide_portfolio(){
        
        $("ul.thumbs").css("display","none");
        $("ul.thumbs").css("visibility","hidden");
        
        $("#portfolio").animate({ 
            opacity: "hide"
        }, 200 );

        $("#home-images").animate({ 
            opacity: "hide"
        }, 200 );
        
        $("#slideshow-adv").animate({ 
            opacity: "hide"
        }, 200 );    

        $("ul.thumbs").animate({ 
            opacity: "hide"
        }, 200 ); 
        
        $("#clients").animate({ 
            opacity: "hide"
        }, 200 );        

        $("#thumbs-adv").animate({ 
            opacity: "hide"
        }, 200 );
    }


    /*********************************************************
        Slideshowcross
    *********************************************************/
    $("a[rel='fadeslideshow']").click(function(){ 
        var hrefLoc = $(this).attr('href'); 
        
        $('#LeftPane h1').fadeOut("fast");
        $('#LeftPane #nav').fadeOut("fast");
        $('#LeftPane .caption').fadeOut("fast");
        
        $('#RightPane').fadeOut("fast",function(){ 
            
            window.location = hrefLoc; 
        }); 
        return false; 
    }); 
    
    
    
    /*********************************************************
        Highslide
    *********************************************************/    
    hs.graphicsDir = '/wp-content/themes/z/js/highslide-4/graphics/';
    hs.outlineType = 'rounded-white';
    hs.align = 'center';
    hs.showCredits = false;


    /*********************************************************
        Drawings Cycle Plugin
    *********************************************************/    
    $('.drawings').cycle({
		fx: 'shuffle',
		pause: true
	});
	
    /*********************************************************
        Menu
    *********************************************************/
    $("ul.sf-menu").superfish();
    
	// Initialize history plugin.
	// The callback is called at once by present location.hash.
	// Make sure this gets called after galleriffic has been initialized 
	$.historyInit(pageload);
	
};


function homeToPortfolio(hash){
    $("#MySplitter").trigger("resize", [ 270 ]);        
}

function pageWhiteBackground(){

    handleWindowScrollbars();
    
    /*********************************************************
        Resize
    *********************************************************/   
	$("#MySplitter").splitter({
		type: "v",
		outline: true,
		minLeft: 0, sizeRight: 0, minRight: 0,
		resizeToWidth: true,
		anchorToWindow: true,
		/* cookie: "vsplitter", */
		accessKey: 'I'
	});

    /*********************************************************
        Animation
    *********************************************************/         
    $("a[rel='fadeout']").click(function(){ 
        var hrefLoc = $(this).attr('href'); 

        $('body').fadeOut("fast",function(){ 
            window.location = hrefLoc; 
        }); 
        return false; 
    }); 
    
    $("ul.sf-menu").superfish();

    $("#MySplitter").trigger("resize", [ 210 ]);   
    
    $("#black").css("width","0");
    $("#black").css("right","1");
    $("#blackleft").css("width","210px");
    $("#blackleft").css("left","-210px");
    
    $("#white-block").css("display","none");
    $("#z").css("width","130px");
    
    
    $('#nav').css("display","none");        
    
    /*
    $(function() {
       $('#nav a').hover( function(){
          $(this).css("background-position","0 -24px");
       },
       function(){
          $(this).css("background-position","0 -16px");
       });
    });
    

    $('.contact #nav #nav-contact-us a').css("background-position","0 -24px");
    $('.in-the-press #nav #nav-in-the-press a').css("background-position","0 -24px");
    $('.opportunities #nav #nav-opportunities a').css("background-position","0 -24px");
    $('.about #nav #nav-about-us a').css("background-position","0 -24px");
    */
    
    /* Pan black boxes */
    $("#black").animate({ 
        width: "0px",
        left: "0px"
    }, 800 );

    $("#z").animate({ 
        opacity: "show"
    }, 1600 );      
    
    $("#blackleft").animate({ 
        left: "0px"
    }, 800 );
    
    $("#nav").animate({ 
        opacity: "show"
    }, 2800 ); 
    
    $("#text").animate({ 
        opacity: "show"
    }, 1800 );     
    
    $("#portfolio").animate({ 
        opacity: "show"
    }, 1800 );     
}



function pageTour(){
    handleWindowScrollbars();

    /*********************************************************
        Highslide
    *********************************************************/    
    hs.graphicsDir = '/wp-content/themes/z/js/highslide-4/graphics/';
    hs.outlineType = 'rounded-white';
    hs.align = 'center';
    hs.showCredits = false;
    
    /*********************************************************
        Resize
    *********************************************************/   
	$("#MySplitter").splitter({
		type: "v",
		outline: true,
		minLeft: 0, sizeRight: 0, minRight: 0,
		resizeToWidth: true,
		anchorToWindow: true,
		/* cookie: "vsplitter", */
		accessKey: 'I'
	});

    /*********************************************************
        Animation
    *********************************************************/         
    $("a[rel='fadeout']").click(function(){ 
        var hrefLoc = $(this).attr('href'); 

        $('body').fadeOut("slow",function(){ 
            window.location = hrefLoc; 
        }); 
        return false; 
    }); 
    
    $("ul.sf-menu").superfish();

    $("#MySplitter").trigger("resize", [ 210 ]);   

  
    $("#black").css("right","1");
  
    $("#blackleft").css("width","210px");
    $("#blackleft").css("left","-210px");
    
    $("#white-block").css("display","none");
    $("#z").css("width","130px");
    
    
    $('#nav').css("display","none");        
    
    $("#black").css("width","2000px");
    $("#black").css("height","1px");
    $("#black").css("right","0px");
        
    $("#black").animate({ 
        height: "100%",
        top: "0px"
    }, 500 );

    $("#z").animate({ 
        opacity: "show"
    }, 1600 );      
    
    $("#nav").animate({ 
        opacity: "show"
    }, 2800 ); 
    
    $("#text").animate({ 
        opacity: "show"
    }, 1800 );     
    
    $("#portfolio").animate({ 
        opacity: "show"
    }, 1800 );    
    
    /*********************************************************
       Slideshow 
    *********************************************************/
    var slideshowSpeed = 800;
    var slideshowTimeout = 4000;    
    
    $('.gallery').cycle({ 
        fx:      'fade', 
        speed:    slideshowSpeed, 
        timeout:  0,
        continuous: 0, // set this to 0 so timeout will work
        slideExpr: 'li.gallery-item',
        cleartype: '1',
        next: '.slideshow-next',
        prev: '.slideshow-prev',
        pager: '#pane-target',
        pagerEvent: 'mouseover',

        pagerAnchorBuilder: function(idx, slide) { 
            // return selector string for existing anchor 
            return '#pane-target li:eq(' + idx + ') a'; 
        }
    });

	// by default, the scroll is only done vertically ('y')
	$.scrollTo.defaults.axis = 'x'; 			
	// this one is important, many browsers don't reset scroll on refreshes
	$('div.pane').scrollTo( 0 ); // reset all scrollable panes to (0,0)
	$.scrollTo( 0 ); // reset the screen to (0,0)
		
	// Target examples bindings
	var $paneTarget = $('#pane-target');			
	
	$('#right-arrow').click(function(){
		$paneTarget.stop().scrollTo( '+=375px', 400 );
		
		//$paneTarget.css('position');
		//alert('hey ' + );
	});

	$('#left-arrow').click(function(){
		$paneTarget.stop().scrollTo( '-=375px', 400 );
	});
 
}



function handleWindowScrollbars(){
    /*********************************************************
        Window Height Resize
    *********************************************************/ 
    var WindowHeight = $(window).height();
    
    if (WindowHeight < 700){
        $("#RightPane").css("overflow-y", 'auto' );
        $("body").css("overflow-y", 'auto' );        
    } else {
        $("#RightPane").css("overflow-y", 'hidden' );        
        $("body").css("overflow-y", 'hidden' );        
    }
      
    $(window).bind("resize", resizeWindow);
    function resizeWindow( e ) {
        var newWindowHeight = $(window).height();
        
        if (newWindowHeight < 700){
            $("#RightPane").css("overflow-y", 'auto' );
            $("body").css("overflow-y", 'auto' );  
        } else {
            $("#RightPane").css("overflow-y", 'hidden' );   
            $("body").css("overflow-y", 'hidden' );         
        }
        
        var newWindowWidth = $(window).width();
        
        if (newWindowWidth < 960){
            $("body").css("overflow-x", 'auto' );  
        } else {
            $("body").css("overflow-x", 'hidden' );         
        }
    }
    
    /*********************************************************
        Window Width Resize
    *********************************************************/ 
    var WindowWidth = $(window).width();
    
    if (WindowWidth < 960){
        $("body").css("overflow-x", 'auto' );        
    } else {     
        $("body").css("overflow-x", 'hidden' );        
    }
    
    return false;
}  



function handle_home_rollovers(){
    // AW 
    $('#portfolio-woodwork a.replace').hover(function() {
        $('#home-image-1').attr("src","/wp-content/themes/z/i/ze-aw-commercial.jpg");
    }, function() {
        $('#home-image-1').attr("src","/wp-content/i/ze-homepage-1.jpg");
    });  

    // AW - Commercial
    $('#portfolio-woodwork-commercial a').hover(function() {
        $('#home-image-1').attr("src","/wp-content/themes/z/i/ze-aw-commercial-2.jpg");
    }, function() {
        $('#home-image-1').attr("src","/wp-content/i/ze-homepage-1.jpg");
    });  

    // AW - Residential
    $('#portfolio-woodwork-residential a').hover(function() {
        $('#home-image-1').attr("src","/wp-content/themes/z/i/ze-aw-residential.jpg");
    }, function() {
        $('#home-image-1').attr("src","/wp-content/i/ze-homepage-1.jpg");
    });  

    // AW - Residential - Doors
    $('#portfolio-woodwork-doors a').hover(function() {
        $('#home-image-1').attr("src","/wp-content/themes/z/i/ze-aw-doors.jpg");
    }, function() {
        $('#home-image-1').attr("src","/wp-content/i/ze-homepage-1.jpg");
    });

    // AW - Residential - Interiors
    $('#portfolio-woodwork-interiors a').hover(function() {
	   $('#home-image-1').attr("src","/wp-content/themes/z/i/ze-aw-interiors.jpg");
    }, function() {
	   $('#home-image-1').attr("src","/wp-content/i/ze-homepage-1.jpg");
    });  

    // AW - Residential - Kitchens
    $('#portfolio-woodwork-kitchens a').hover(function() {
        $('#home-image-1').attr("src","/wp-content/themes/z/i/ze-aw-kitchens.jpg");
    }, function() {
        $('#home-image-1').attr("src","/wp-content/i/ze-homepage-1.jpg");
    });  

    // Marine
    $('#portfolio-marine a.replace').hover(function() {
        $('#home-image-2').attr("src","/wp-content/themes/z/i/ze-marine-2.jpg");
    }, function() {
        $('#home-image-2').attr("src","/wp-content/i/ze-homepage-3.jpg");
    });  

    // Marine - Stairs
    $('#portfolio-marine-stairs a').hover(function() {
        $('#home-image-2').attr("src","/wp-content/themes/z/i/ze-marine-stairs-2.jpg");
    }, function() {
        $('#home-image-2').attr("src","/wp-content/i/ze-homepage-3.jpg");
    });  
    
    // Marine - Yachts
    $('#portfolio-marine-yachts a').hover(function() {
        $('#home-image-2').attr("src","/wp-content/themes/z/i/ze-marine-yachts-2.jpg");
    }, function() {
        $('#home-image-2').attr("src","/wp-content/i/ze-homepage-3.jpg");
    });  

    // Stairs
    $('#portfolio-stairs a.replace').hover(function() {
        $('#home-image-3').attr("src","/wp-content/themes/z/i/ze-ms-stairs.jpg");
    }, function() {
        $('#home-image-3').attr("src","/wp-content/i/ze-homepage-2.jpg");
    });  
    
    // Stairs - Commercial
    $('#portfolio-stairs-commercial a').hover(function() {
        $('#home-image-3').attr("src","/wp-content/themes/z/i/ze-ms-commercial.jpg");
    }, function() {
        $('#home-image-3').attr("src","/wp-content/i/ze-homepage-2.jpg");
    });  

    // Stairs - Marine
    $('#portfolio-stairs-marine a').hover(function() {
        $('#home-image-3').attr("src","/wp-content/themes/z/i/ze-ms-marine.jpg");
    }, function() {
        $('#home-image-3').attr("src","/wp-content/i/ze-homepage-2.jpg");
    });  

    // Stairs - Residential
    $('#portfolio-stairs-residential a').hover(function() {
        $('#home-image-3').attr("src","/wp-content/themes/z/i/ze-ms-residential-2.jpg");
    }, function() {
        $('#home-image-3').attr("src","/wp-content/i/ze-homepage-2.jpg");
    });  
        
} // end function
