/* McGranahan Javascript */

/*

	All interactions have been separated into three regions on this page:
		Functions that effect change (like deploy a menu or display a slide)
		Selectors that determine what events trigger functions
		Combined components that don't apply to the functions/selectors design
	
	All functions are listed first so that any selector can trigger any function, 
	useful for triggering hide functions on some components when others expand.
	
	Nearly all components use objects named in the style 'jqXX', storing 
	pre-fetched jQuery objects (boosts performance), parameters for animations, 
	timers, counters, etc.
	
	Version: Wolken-build2
	
*/

$(document).ready(
	function(){
				
		// PRIMARY NAVIGATION FUNCTIONS
		
		jqPN = {
			ul		:	$('#primary_nav'),
			lis		:	$('#primary_nav > li'),
			lisula:	$('#primary_nav > li li > a'),
			isOpen: false,
			slide	: { down : 800, up : 600 }, // the duration to slide down and back
			pfade	: { full : 0, trans : 200 }, // the duration to fade content in (full) and out (trans)
			delay	: 100 // the delay on mouseout/exit/whatever
		}
		
		// closes any open Primary Nav LI items that are open, then closes the panel
		hidePriNav = function(){	
			// marks it's state as closed
			jqPN.isOpen = false;
			// closes any list that's open
			jqPN.lisula.stop().animate(
				{opacity:0.0},
				jqPN.pfade.trans,
				'easeInOutQuint',
				function(){
					// then closes the primary nav container
					jqPN.ul.stop().animate(
						{height:'71px'},
						jqPN.slide.up,
						'easeInOutQuint',
						function(){jqPN.ul.css({height:'40px'})
						}
					);
				}
			);
		}
		
		// displays the Primary Nav LI passed to the function, opens the primary nav container if needed
		showPriNav = function(o){
			jqPN.show = o
			jqPN.dontshow = jqPN.lis.not(o)
			// if the primary nav is already open
			if (jqPN.isOpen) {
				// find all the LI's that weren't just provided and hide them
				jqPN.dontshow.find('ul a').stop().animate(
					{opacity:0.0},
					jqPN.pfade.trans,
					'easeInOutQuint',
					function(){
						// now display the LI that was just provided
						jqPN.show.find('ul a').stop().animate(
							{opacity:1.0},
							jqPN.pfade.full,
							'easeInOutQuint'
						);
					}
				);
			} else {
				// set the state to open
				jqPN.isOpen = true;
				jqPN.lisula.css({opacity:0.0})
				// slide the container out to its full height
				jqPN.ul.css({height:'71px'}).stop().animate(
					{height:'199px'},
					jqPN.slide.down,
					'easeInOutQuint',
					function(){
						// display the LI that was just provided
						jqPN.show.find('ul a').animate(
							{opacity:1.0},
							jqPN.pfade.full,
							'easeInOutQuint'
						);
					}
				);
			}
		}
		
		// SECONDARY NAV FUNCTIONS
		
		jqSN = {
			div			: $('#secondary_nav'),
			ab			: $('#secondary_nav .alphaback'),
			h2			: $('#secondary_nav #category_title'), // not actually an h2 any longer
			h2span	: $('#secondary_nav #category_title span'),
			sc			: $('#secondary_nav .scroll_container'),
			ul			: $('#secondary_nav .scroll_container ul'),
			scup		: $('#secondary_nav #scroll_up'),
			scdwn		: $('#secondary_nav #scroll_down'),
			close		: $('#secondary_nav #close'),
			allopn	: $('#secondary_nav .scroll_container, #secondary_nav #scroll_up, #secondary_nav #scroll_down, #secondary_nav #close'),
			maxH		: $('#secondary_nav .scroll_container ul').height() - $('#secondary_nav .scroll_container').height(),
			isOpen	: false,
			slide		: {down : 500, up : 500 },	// duration for container to slide up/down
			pfade		: {full : 500, trans : 500 }, // duration for content to fade in/out
			h2fade	: {full : 500, trans : 500 }, // duration for title to fade in/out
			h2cross	: {full : 250, trans : 125 }, // duration for title to fade in/out on external navigation trigger
			delay		: 2000 // the delay on mouseout/exit/whatever
		}
		
		// update the visibility of the secondary nav up/down scroll buttons based on the scroll offset
		updateScrollButtons = function(){
			var offset = Math.abs(jqSN.ul.position().top);
			var scroll = jqSN.maxH > 0;
			if (jqSN.isOpen && scroll && offset >= jqSN.maxH ) {
				// if we're at the bottom of the list
				jqSN.scup.show();
				jqSN.scdwn.hide();
			} else if (jqSN.isOpen && scroll && offset == 0) {
				// if we're at the top of the list
				jqSN.scup.hide();
				jqSN.scdwn.show();
			} else if (jqSN.isOpen && scroll) {	
				// if we're in the middle of the list
				jqSN.scup.show();
				jqSN.scdwn.show();
			} else {
				// the list isn't even being displayed right now, so don't show scroll buttons
				jqSN.scup.hide();
				jqSN.scdwn.hide();
			}
		}
		
		// simple animation to show the Secondary Nav panel
		showSecNav = function(height){ // specify height as jQuery would want it, e.g.: '200px'
			jqSN.allopn.css({opacity:0.0});
			jqSN.ab.css({opacity:0.9});
			jqSN.h2.stop().animate(
				{opacity:0.0},
		 		jqSN.h2fade.trans,
		 		'easeInOutQuint',
		 		function(){jqSN.h2.css({display:'none'});
		 			jqSN.div.stop().animate(
		 				{height:height},
		 				jqSN.slide.down,
		 				'easeInOutQuint',
		 				function(){
		 					jqSN.isOpen = true;
		 					jqSN.close.css({display:'block'})
		 					updateScrollButtons();
		 					jqSN.allopn.stop().animate(
		 						{opacity:1.0},
		 						jqSN.pfade.full,
		 						'easeInOutQuint'
		 					);
		 				}
		 			);
		 		}
		 	);
		}
		
		// simple animation to hide the Secondary Nav panel
		hideSecNav = function(){
			jqSN.allopn.stop().animate(
				{opacity:0.0},
				jqSN.pfade.trans,
				'easeInOutQuint',
				function(){
					jqSN.isOpen = false;
					jqSN.close.css({display:'none'})
					jqSN.div.stop().animate(
						{height:'28px'},
						jqSN.slide.up,
						'easeInOutQuint',
						function(){jqSN.h2.css({display:'block'});
							updateScrollButtons();
							jqSN.ab.stop().animate(
								{opacity:1.0},
								jqSN.h2fade.full,
								'easeInOutQuint',
								function(){jqSN.ab.css({opacity:''});
								}
							);
							jqSN.h2.stop().animate(
								{opacity:1.0},
								jqSN.h2fade.full,
								'easeInOutQuint'
							);
						}
					);
				}
			);
		}
		
		        // update the secondary nav state by passing either a string id like "developing_craft", or the array position "2"
        // note that the ID's have a "sn_" prefix to reduce the risk of ID collision(auto added), easy to remove/change if needed
        // if an anchor tag isn't found as requested, no transition will happen.
        scrollToSecNav = function(where){
            var chosen; // will become the jQuery object representing where we want to scroll to
            if( typeof(where) == 'number' ) {
                // find it by position in the UL
                chosen = jqSN.ul.find('.section_title').eq(where);
            } else {
                // build the ID selector we want to find in the UL
                what_to_find = 'a#sn_'+where;
                // then find the anchor by it's selector
                chosen = jqSN.ul.find(what_to_find);
            }
            // find out if we actually found "the chosen one"
            scroll_it = chosen.length > 0
            // confirm that the text has actually changed
            animate_it = scroll_it && jqSN.h2span.text() != chosen.text()
            // if everything is good, lets change the H2, shall we?
            if (scroll_it) {
                // scroll the menu to "the chosen one" and update the button states
                jqSN.sc.scrollTo(chosen, 500, {onAfter: function(){updateScrollButtons()}} );
            }
            if (animate_it) {
                // fade out the Secondary Nav H2, change it's text, and fade it back in
                jqSN.h2span.animate(
                    {opacity:0},
                    jqSN.h2cross.trans,
                    'easeInOutQuint',
                    function(){
                        jqSN.h2span.text(chosen.text());
                        jqSN.h2span.animate(
                            {opacity:1},
                            jqSN.h2cross.full,
                            'easeInOutQuint'
                        );
                    }
                );
            }
        }
		
		// CAROUSEL-RELATED FUNCTIONS
		
		jqCA = {
			stext		:	$('#section_text'),
			bg_box	:	$('#approach_background'),
			sfade		: {full : 250, trans : 125 }, // duration for the section_text to fade in/out when a transition is called
			bgfade	:	1000 // duration for the background image to cross fade when image done loading
		}
		
		// changes content on carousel pages, pass raw text as variable
		setCarouselSectionText = function(text){ 
			// if the text displayed and the text supplied is the same... don't do anything just return
			if (text == jqCA.stext.html()){return}
			// if the text area is currently blank then instantly display it
			if (jqCA.stext.html() == "") {jqCA.stext.html(text);} else {
				// otherwise fade out text, change it with the supplied text, then fade it back in
				jqCA.stext.animate(
					{opacity:0},
					jqCA.sfade.trans,
					'easeInOutQuint',
					function(){
						jqCA.stext.html(text);
						jqCA.stext.animate(
							{opacity:1},
							jqCA.sfade.full,
							'easeInOutQuint'
						);
					}
				);
			}
		}
		
		// this function fades a new background image into the left column of the page.
		// it does this by adding an LI > IMG, fading it in, then deleting the old one
		// if there is no existing LI > IMG, then image shows immediately.
		// function expects valid img url like '/images/foo.jpg' or 'http://foo.com/image.jpg'
		setCarouselBackground = function(uri){
			// this is the image we're going to create
			var img = $("<img src='"+uri+"'/>")
			// now we're going to load it... function doesn't run until it's done loading
			$(img).load(
				function(){
					// find the old background image's LI
					old_CB_li = jqCA.bg_box.find('li');
					// create the new background image LI, set it to transparent and z-index 2, put new IMG in it
					new_CB_li = $('<li></li>').css({opacity:0.0,zIndex:2}).append(this);
					// now insert all that into the container UL
					jqCA.bg_box.append(new_CB_li)
					// we'll fade in the new LI if there's an existing one, otherwise we'll just show it quickly.
					if (old_CB_li.length > 0) {
						// now fade that new LI in...
						new_CB_li.animate(
							{opacity:1.0},
							jqCA.bgfade,
							'easeInOutQuint',
							function(){
								// and get rid of the old image's LI
								old_CB_li.remove();
								// and set the new LI to z-index 1 so others added in the future come to the top
								new_CB_li.css({zIndex:1});
							}
						)
					} else {
						// there was no existing LI, so lets show the new LI quickly
						new_CB_li.css({opacity:1.0,zIndex:1});
					}
				}
			)
		}
		
		
		
		
		// BALANCE BAR FUNCTIONS
		
		jqBB = {
			div		: $('#balancebar'),
			ab		: $('#balancebar .alphaback'),
			h2		: $('#balancebar h2'),
			p			: $('#balancebar p'),
			isOpen:	false,
			slide	: { down : 500, up : 500 }, // duration to slide open/closed
			pfade	: { full : 500, trans : 500 }, // duration for content to fade in/out
			delay	: 2000 // the delay on mouseout/exit/whatever
		}
		
		// simple animation to deploy the ballance bar
		openBalanceBar = function() {
			jqBB.div.addClass('expanded');
			jqBB.div.animate(
				{top: '74px', height: '391px'},
				jqBB.slide.down,
				'easeInOutQuint',
				function(){
					jqBB.p.animate(
						{opacity:1.0},
						jqBB.pfade.full
					);
				}
			);
			jqBB.h2.animate(
				{top: '38px'},
				jqBB.slide.down,
				'easeInOutQuint',
				function(){ 
					jqBB.isOpen = true
				}
			);
		}
		
		// simple animation to retract the ballance bar
		closeBalanceBar = function() {
			jqBB.p.animate(
				{opacity:0.0},
				jqBB.pfade.trans,
				function(){
					jqBB.div.animate(
						{top:'128px',height:'40px'}, 
						jqBB.slide.up, 
						'easeInOutQuint'
					);
					jqBB.h2.animate(
						{ top: '11px'},
						jqBB.slide.up,
						'easeInOutQuint',
						function(){ 
							jqBB.div.removeClass('expanded');
							jqBB.isOpen = false
						}
					);
				}
			);
		}
		
		// APPROACH BAR FUNCTIONS
		
		jqAB = {
			div			: $('#approach_bar'),
			pres		:	$('#approach_bar .description'),
			ab			:	$('#approach_bar .alphaback'),
			h_closed:	$('#approach_bar').height(),
			h_open	:	'56px', // height when open
			slide		: { down : 400, up : 400 }, // duration to slide open and closed
			pfade		: { full : 150, trans : 150 }, // duration to fade in and out
			delay		: 500 // delay on mouseout/exit/whatever
		}
		
		// simple animation to display the Approach Bar
		showAB = function(){jqAB.pres.css({opacity:0.0});
			jqAB.div.animate(
				{height:jqAB.h_open},
				jqAB.slide.down,
				'easeInOutQuint',
				function(){
					jqAB.pres.animate(
						{opacity:1.0},
						jqAB.pfade.full,
						'easeInOutQuint'
					);
				}
			);
		}
		
		// simple animation to hide the Approach Bar
		hideAB = function(){
			jqAB.pres.animate(
				{opacity : 0.0},
				jqAB.pfade.trans,
				'easeInOutQuint',
				function(){
					jqAB.div.animate(
						{height : jqAB.h_closed},
						jqAB.slide.up,
						'easeInOutQuint'
					);
				}
			);
		}

		// INFOBAR FUNCTIONS
		
		jqIB = {
			div			: $('#info_bar'),
			ab			: $('#info_bar .alphaback'),
			pre			: $('#info_bar .preview'),
			cntnt 	: $('#info_bar #presentation'),
			close		:	$('#info_bar #info_close'),
			slide		: {down : 500, up : 500 }, // duration to slide open/closed
			cntfade	: {full : 500, trans : 500 }, // duration to fade content in/out
			prefade	: {full : 500, trans : 500 }, // duration to fade the preview in/out
			delay		: 2000 // the delay on mouseout/exit/whatever
		}
		
		// simple animation to extend the Info Bar
		
		
		openInfoBar = function(){jqIB.cntnt.css({opacity:0.0});
			jqIB.ab.css({opacity:0.95});
			jqIB.pre.animate(
				{opacity: 0.0},
				jqIB.prefade.trans,
				'easeInOutQuint',
				function(){jqIB.pre.css({height:'0'});
					jqIB.div.animate(
						{height:'489px'},
						jqIB.slide.up,
						'easeInOutQuint',
						function(){
							jqIB.cntnt.animate(
								{opacity: 1.0},
								jqIB.cntfade.full,
								'easeInOutQuint'
							);
							jqIB.close.css({display:'block'});
							jqIB.close.animate(
								{opacity: 1.0},
								jqIB.cntfade.full,
								'easeInOutQuint'
							);
						}
					);
				}
			);
		}
		
		// simple animation to retract the Info Bar
		closeInfoBar = function(){
			jqIB.cntnt.animate(
				{opacity: 0.0},
				jqIB.cntfade.full,
				'easeInOutQuint'
			);
			jqIB.close.animate(
				{opacity: 0.0},
				jqIB.cntfade.full,
				'easeInOutQuint',
				function(){jqIB.close.css({display:'none'});
					jqIB.div.animate(
						{height:'28px'},
						jqIB.slide.up,
						'easeInOutQuint',
						function(){jqIB.pre.css({height:''});
							jqIB.pre.animate(
								{opacity: 1.0},
								jqIB.prefade.trans,
								'easeInOutQuint',
								function(){jqIB.ab.css({opacity:''});
								}
							);
						}
					);
				}
			);
		}
		
		// PROJECT SLIDE FUNCTIONS
		
		jqPS = {
			ul		: $('#project_slide'),
			lis		:	$('#project_slide li'),
			pbutt	: $('#previous'),
			nbutt	: $('#next'),
			pagec : $('#page_control'),
			phref	: $('#project_prev_and_next .prev').attr('href'), // the next-project href
			nhref	:	$('#project_prev_and_next .next').attr('href'), // the previous-project href
			vis		: 1
		}
		
		// IE Bug, wouldn't respect css first-child so fixing here
		jqPS.lis.eq(0).css({opacity:1.0})
		
		
		// when project slide next button is clicked, will show next slide OR navigate to next project if last
		showNextSlide = function(){
			if (jqPS.vis == jqPS.lis.size()) {
				window.location = jqPS.nhref;
			} else {
				jqPS.vis += 1;
				showSlide(jqPS.vis);
			}
		}
		
		// when project slide prev button is clicked, will show prev slide OR navigate to previous project if first
		showPrevSlide = function(){
			if (jqPS.vis == 1) {
				window.location = jqPS.phref;
			} else {
				jqPS.vis -= 1;
				showSlide(jqPS.vis);
			}
		}
		
		// update the classes of project slide next/prev button to reflect if first or last slide is visible
		updateNPClass = function(){
			jqPS.vis == 1 ? jqPS.pbutt.addClass('project') : jqPS.pbutt.removeClass('project');
			jqPS.vis == jqPS.lis.size() ? jqPS.nbutt.addClass('project') : jqPS.nbutt.removeClass('project');
		}
		
		// show the desired slide in the stack by flipping around opacity, stack starts with 1.
		showSlide = function(foo){
			jqPS.lis.css({'z-index': '1', 'opacity': '0.0'});
			jqPS.pagec.find('li').removeClass('active');
			jqPS.pagec.find('li').eq(foo - 1).addClass('active');
			jqPS.vis = foo;
			jqPS.lis.eq(jqPS.vis - 1).css({'z-index': '2'}).animate(
				{opacity: 1.0},
				500,
				'easeOutQuad'
			);
			updateNPClass()	;	
		}
		
		// project slide page control thumbnail images are automatically created based on slides provided
		addPageControl = function(){
			// loop through the slides in the stack
			for (i=1;i<=jqPS.lis.size();i++) {
				// if it's the first on page, we'll give it the 'active' class
				if (i == 1) { c = 'active' } else { c = '' };
				// and now insert a LI element with a link to the slide number
				jqPS.pagec.append('<li class=' + c + '><a href="#' + i + '"><span></span></a></li>');
			}
			// clunky, but now we find those LI's and bind a click event to determine the array value and show the slide
			jqPS.pagec.find('li').click(
				function(){
					sHref = $(this).find('a').attr('href');
					iHref = parseInt( sHref.substr( sHref.indexOf('#') + 1) );
					// we only trigger show slide for slides that are NOT currently active
					if (!$(this).hasClass('active')) {showSlide(iHref);}
					return false;
				}
			);
		}
		
		// lets get right to the point...
		addPageControl();

		// APPROACH SLIDESHOW FUNCTIONS AND INITIATION
		
		jqAS = {
			lis				:	$('ul#approach_slide li img'),
			start_del	:	3000, //pause before first slide
			hold			:	3000, // pause between slides
			fade			:	2000	// duration of fade transition effect
		}
		jqAS.vis = jqAS.lis.length;
		
		// slides are in array starting with 1, shows first if end reached, otherwise fades in next in stack
		showAnotherSlide = function(){
			// if we're on the last slide, and remember, it STARTS on the last slide...
			if (jqAS.vis == jqAS.lis.length) {
				// fade in the first slide if it's not already faded in
				firstslide = jqAS.lis.first().animate(
					{'opacity' : '1.0' },
					jqAS.fade,
					'easeInOutQuad'
				);
				// and fade out the rest of the slides
				jqAS.lis.not(firstslide).animate(
					{'opacity' : '0.0' },
					jqAS.fade,
					'easeInOutQuad'
				);
				// reset the counter
				jqAS.vis = 1;
			} else {
				// fade in whatever the next image in the stack is
				jqAS.lis.eq(jqAS.vis).animate(
					{'opacity' : '1.0' },
					jqAS.fade,
					'easeInOutQuad'
				);
				// update the counter
				jqAS.vis += 1;
			}
			// if there's only one slide, clear the interval because we're done
			if (jqAS.lis.length == 1) { jqAS.interval = null } 
		}
		
		// on running, will show a slide and then set an interval to keep showing the slides
		runSlideInterval = function(){ 
			showAnotherSlide(); // run it on setting
			jqAS.interval = setInterval('showAnotherSlide()',jqAS.hold + jqAS.fade); // and then at even intervals thereafter, accounting for fade duration
		}
		
		// get the slidewshow intervals running after all graphics done loading
		$(window).load(
			function(){
				setTimeout('runSlideInterval()', jqAS.start_del); // timeout before starting slideshow
			}
		);

		// DETAIL SCROLL BOX SELECTED AND SCROLL BARS APPLIED. SCROLL STYLE SET IN SCROLL CSS
		
		$('.scrollpane').jScrollPane({
			showArrows : true,
			scrollbarWidth : 14,
			arrowSize : 21
		})
		
		// PROJECT BAR BASIC SELECTORS AND EFFECTS
		
		jqPR = {
			div 	: $('body.home #project_rollover'),
			afade	: { full: 600, trans: 1000 }
		}
		
		jqPR.div.hoverIntent(
			function(){
				$(this).stop().find('a').animate(
					{opacity:1.0},
					jqPR.afade.full
				);
			},function(){
				$(this).stop().find('a').animate(
					{opacity:0.0},
					jqPR.afade.trans
				);
			}
		);
		
		// helped with IE
		jqPR.div.find('a').css({opacity:0})

		
		// PRIMARY NAVIGATION TRIGGERS
		
		// used hoverIntent to slow down mouseover event, reduce false triggering events.
                  $('#primary_nav > li').hoverIntent(
	      //    $('#primary_nav > li').mouseenter(
			function(){
				clearTimeout(jqPN.timeout);
				showPriNav($(this));
				closeBalanceBar(); // close the balance bar if it's on this page
				hideSecNav(); // close the secondary nav if there's one open
			},function(){
				return false;
			}
		);
		
		// only start the hide event when the whole container has been exited
		jqPN.ul.mouseleave(
			function(){
				if (jqPN.isOpen) {
					jqPN.timeout = setTimeout('hidePriNav();', jqPN.delay);
				} 
			}
		);
		
		// SECONDARY NAV TRIGGERS
		
		jqSN.h2.click(
			function(){
				closeInfoBar();	// close the infobar if there's one on this page
				hidePriNav(); // hide the secondary nav if there's one open
				height = (jqSN.div.hasClass('detail')) ? '489px' : '322px'; // detail is full height, otherwise short/carousel
				showSecNav(height);
				return false;
			}
		);
		
		// use mouseenter/leave to trigger Secondary Nav display / delayed exit
		jqSN.div.mouseenter(
			function(){clearTimeout(jqSN.timeout);}
		).mouseleave(
			function(){
				jqSN.timeout = setTimeout('hideSecNav();',jqSN.delay);
			}
		);
			
		// scroll handling in Secondary Nav is very simple, interval triggers animation
		// scup is for scrolling UP
		jqSN.scup.mousedown(
			function(){
				clearInterval(jqSN.timer);
				jqSN.timer = setInterval( "jqSN.sc.scrollTo('-=4px'); updateScrollButtons();", 20);
			}
		);
		// scdwn is for scrolling DOWN
		jqSN.scdwn.mousedown(
			function(){
				clearInterval(jqSN.timer);
				jqSN.timer = setInterval( "jqSN.sc.scrollTo('+=4px'); updateScrollButtons();", 20);
			}
		);
		
		// for either Secondary Nav scroll button, lifting the mouse button kills the animation interval
		jqSN.scup.add(jqSN.scdwn).mouseup(
			function(){clearInterval(jqSN.timer);}
		).mouseout(
			function(){clearInterval(jqSN.timer);}
		);
		
		// a click on the gui X button will close the Secondary Nav immediately.
		jqSN.close.click(
			function(){
				hideSecNav();
				return false;
			}
		);
		
		// INFO BAR TRIGGERS
		
		jqIB.pre.click(
			function(){
				// we only want to trigger events if there's content in this Info Bar
				if (jqIB.cntnt.length > 0) {
					hidePriNav();
					hideSecNav();
					openInfoBar();
				}
				return false;
			}
		);
		
		// close button to close the Info Bar
		jqIB.close.click(
			function(){
				closeInfoBar();	
				return false;
			}
		);
		
		// mouseing over the Info Bar will reset the close timer if it's running
		jqIB.div.mouseenter(
			function(){clearTimeout(jqIB.timeout);}
		).mouseleave(
			function(){
				// on mouseleave set the Info Bar's close timer, then trigger the close function
				jqIB.timeout = setTimeout('closeInfoBar();', jqIB.delay);
			}
		);
		
		// BALANCE BAR TRIGGERS
		
		jqBB.div.hoverIntent(
			function(){clearTimeout(jqBB.timeout);}, function(){ 
				if (jqBB.isOpen) {
					jqBB.timeout = setTimeout('closeBalanceBar();', jqBB.delay);
				} 
			}
		).click(
			function(){if(jqBB.isOpen){closeBalanceBar();} else {
					hidePriNav();
					openBalanceBar();
				}
				return false;
			}
		);
		
		// APPROACH BAR TRIGGERS
		
		jqAB.div.hoverIntent(
			function(){
				// mouseover shows the Approach Bar
				showAB();
			},function(){
				// mouseout hides the Approach Bar
				hideAB();
			}
		);
		
		// PROJECT SLIDE TRIGGERS
		
		// when clicked, show the next Project Slide
		jqPS.nbutt.click(
			function(){
				showNextSlide();
				return false;
			}
		);
		
		// when clicked, show the previous Project Slide
		jqPS.pbutt.click(
			function(){
				showPrevSlide();
				return false;
			}
		);
		
	}
);