			$(document).ready( function() {
				
				window.site_url = 'http://etpnorthwest.org/';
				window.template_path = '/wp-content/themes/etpnw';
				
				var $j = jQuery.noConflict();
				
				$j(document).pngFix();
				
				var search_text = "search";
				$j("#s").val(search_text);
				$j("#s").livequery("blur", function() { if ($j(this).val() == "") { $j(this).val(search_text); }; });
				$j("#s").livequery("focus", function() { if ($j(this).val() == search_text) { $j(this).val(""); }; });
				
				$j("#searchsubmit").val(' ');
				
				$j('a[rel*=popup],a.popup').facebox({
					 opacity: 0.8,
     				 overlay: true
				});
				
				$j('#book_a_performance_form').submit( function() {
					the_production = $j('select.production').val();
					$j.get(window.site_url+'/booking/index.php?production='+the_production, function(data) {
						$j.facebox(data)
					})				
					return false;
				});
				
				
				$j('#facebox .content a').live('click', function() {
					$j('#facebox .content').load( $j(this).attr('href') );
					return false;
				});
			 
			    // bind form using 'ajaxForm' 
			    $j('#facebox .content form').livequery( function() { 
			    	
			    	var options = { 
				        target:        '#facebox .content',   // target element(s) to be updated with server response 
				        beforeSubmit:  showRequest,  // pre-submit callback 
				        success:       showResponse  // post-submit callback 
				 
				        // other available options: 
				        //url:       url         // override for form's 'action' attribute 
				        //type:      type        // 'get' or 'post', override for form's 'method' attribute 
				        //dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
				        //clearForm: true        // clear all form fields after successful submit 
				        //resetForm: true        // reset the form after successful submit 
				 
				        // $j.ajax options can be used here too, for example: 
				        //timeout:   3000 
				    }; 
				    
				    // pre-submit callback 
					function showRequest(formData, jqForm, options) { 
					    // formData is an array; here we use $j.param to convert it to a string to display it 
					    // but the form plugin does this for you automatically when it submits the data 
					    var queryString = $j.param(formData); 
					 
					    // jqForm is a jQuery object encapsulating the form element.  To access the 
					    // DOM element for the form do this: 
					    // var formElement = jqForm[0]; 
					 
					    // ** alert('About to submit: \n\n' + queryString); 
					 
					    // here we could return false to prevent the form from being submitted; 
					    // returning anything other than false will allow the form submit to continue 
					    return true; 
					} 
					 
					// post-submit callback 
					function showResponse(responseText, statusText, xhr, $form)  { 
					    // for normal html responses, the first argument to the success callback 
					    // is the XMLHttpRequest object's responseText property 
					 
					    // if the ajaxForm method was passed an Options Object with the dataType 
					    // property set to 'xml' then the first argument to the success callback 
					    // is the XMLHttpRequest object's responseXML property 
					 
					    // if the ajaxForm method was passed an Options Object with the dataType 
					    // property set to 'json' then the first argument to the success callback 
					    // is the json data object returned by the server 
					 
					    // ** alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + '\n\nThe output div should have already been updated with the responseText.'); 
					} 
			    
			    	$j('#facebox .content form').ajaxForm(options); 
			    	
			    	return false;
			    	
			    }); 
			    
			    
								
				$j('#slideshow ul').bxSlider({
					alignment: 'horizontal',        // 'horizontal', 'vertical' - direction in which slides will move
					controls: true,                 // determines if default 'next'/'prev' controls are displayed
					speed: 500,                     // amount of time slide transition lasts (in milliseconds)
					pager: true,                    // determines if a numeric pager is displayed (1 2 3 4...)
					pager_short: false,             // determines if a 'short' numeric pager is displayed (1/4)
					pager_short_separator: ' / ',   // text to be used to separate the short pager
					margin: 0,                      // if 'horizontal', applies a right margin to each slide, if 'vertical' a
					                                // bottom margin is applied. example: margin: 50
					next_text: 'next',              // text to be displayed for the 'next' control
					next_image: '',                 // image to be used for the 'next' control
					prev_text: 'prev',              // text to be displayed for the 'prev' control
					prev_image: '',                 // image to be used for the 'prev' control
					auto: true,                    // determines if slides will move automatically
					pause: 10000,                    // time between each slide transition (auto mode only) 
					auto_direction: 'next',         // order in which slides will transition (auto mode only)
					auto_hover: true,               // determines if slideshow will pause while mouse is hovering over slideshow
					auto_controls: false,           // determines if 'start'/'stop' controls are displayed (auto mode only)
					ticker: false,                  // determines if slideshow will behave as a constant ticker
					ticker_controls: false,         // determines if 'start'/'stop' ticker controls are displayed (ticker mode only)
					ticker_direction: 'next',       // order in which slides will transition (ticker mode only)
					ticker_hover: true,             // determines if slideshow will pause while mouse is hovering over slideshow
					stop_text: 'stop',              // text to be displayed for the 'stop' control
					start_text: 'start',            // text to be displayed for the 'start' control
					wrapper_class: 'slide'  // class name to be used for the outer wrapper of the slideshow
				});
				
				$j('#slideshow .prev').css('left','-60px');
				$j('#slideshow .next').css('right','-60px');
				$j('#slideshow .caption').hide();
				
				$j('#slideshow').hover(function() {
					$j('#slideshow .prev').animate({ left: 0 },{queue: false, duration: 500 });
					$j('#slideshow .next').animate({ right: 0 },{queue: false, duration: 500 });
					$j('#slideshow .caption').slideDown();
				}, function() {
					$j('#slideshow .prev').animate({ left: -60 },{queue: false, duration: 500 });
					$j('#slideshow .next').animate({ right: -60 },{queue: false, duration: 500 });
					$j('#slideshow .caption').slideUp();
				})
				
				$j.fn.exists = function(){ return $j(this).length>0; } // exists function
				
				// sizes the background image
				$j(document).bgStretcher({
					images: [window.template_path+window.background_image],
					resizeProportionally: true
				});
				
				//$j.event.add(window, "load", resize_sides); // resize on load
				//$j.event.add(window, "resize", resize_sides); // resize on width
				
				$j(window).resize(resize_sides).resize(); // combining the two functions above
				
				function resize_sides() {
					var window_width =  $j(window).width(); // get the width of the chrome
					var margin_width = (window_width - 940) / 2; // determine the left/right margin space
					var neg_margin_width = (margin_width - margin_width - margin_width); // get the negative version - there's gotta be a more efficient way to do this
					
					if (neg_margin_width >= 0) { $j(".extender").hide(); } // if the negative margin is zero or less then hide it.
					else { $j(".extender").show(); } // else, show it
					
					
					// header
					var logo_height = $j(".title").outerHeight();
					var nav_height = $j("#navigation a").outerHeight();
					
					var extend_hdr_left = $j(".extend_hdr_left");
					$j(extend_hdr_left).width(margin_width).css('margin-left',neg_margin_width);
					if ($j(extend_hdr_left).height() <= 0) { $j(extend_hdr_left).height(logo_height); } // only resize if size isn't set.
					
					
					var extend_hdr_right = $j(".extend_hdr_right");
					$j(extend_hdr_right).width(margin_width - 4).css('margin-right',neg_margin_width);
					if ($j(extend_hdr_right).height() <= 0) { $j(extend_hdr_right).height(86); } // only resize if size isn't set.
					
					
					// banner - HOMEPAGE ONLY
					if ($j("#banner").exists()) {
						var banner_height = $j("#banner").outerHeight(); 
						var extend_banner_left = $j(".extend_banner_left");
						$j(extend_banner_left).width(margin_width).css('margin-left',neg_margin_width);
						if ($j(extend_banner_left).height() <= 0) { $j(extend_banner_left).height(banner_height); }  // only resize if size isn't set.
					}
										
					
					// footer
					var foot_height = $j("#footer").outerHeight();
					
					var extend_footer_left = $j(".extend_footer_left");
					$j(extend_footer_left).width(margin_width).css('margin-left',neg_margin_width);
					if ($j(extend_footer_left).height() <= 0) { $j(extend_footer_left).height(foot_height); } // only resize if size isn't set.
					
					var extend_footer_right = $j(".extend_footer_right");
					$j(extend_footer_right).width(margin_width).css('margin-right',neg_margin_width);
					if ($j(extend_footer_right).height() <= 0) { $j(extend_footer_right).height(foot_height); } // only resize if size isn't set.
					
					
					
					// homepage height 
					
					var sub_height = 0;
					if (sub_height == 0) {
						// get a bunch of heights to calculate where to place the banner and items below it
						var hdr_height = $j("#header").outerHeight(true); // get height of header
						//alert('header height: '+hdr_height);
						var banner_height = $j("#banner").outerHeight(); // get height of the banner
						//alert('banner height: '+banner_height);
						var sliders_height = $j(".sliders").outerHeight(true); // get height of the sliders
						//alert('sliders height: '+sliders_height);
						var ftr_height = $j("#footer").outerHeight(true); // get height of the footer
						//alert('footer height: '+ftr_height);
						var sub_height = hdr_height + banner_height + sliders_height + ftr_height + 3;  // calculate space used by existing elements
						//alert('sub height: '+hdr_height+' + '+banner_height+' + '+sliders_height+' + '+ftr_height+' = '+sub_height);
					}
					
					var viewport_height_orig = $j(window).height(); // get height of viewport
					// this needs to be used for opera (http://dev.jquery.com/ticket/3046)
					//var viewportHeight = window.innerHeight ? window.innerHeight : $(window).height();
					
					var viewport_height_new = viewport_height_orig - sub_height; // height to use for banner top margin, plus 50px to account for extra margin
					
					if (viewport_height_new < 40) {  var viewport_height_new = 40; } // if the gap is too small, give it padding
					else if (viewport_height_new > 550) { var viewport_height_new = 550; } // if it's to big, default to a set height
					else { var viewport_height_new = viewport_height_new; } // otherwise, resize as needed.
					
					$j("#banner").css("margin-top",viewport_height_new); // do the margin adjustment
					//alert('new banner top margin: '+viewport_height_new);
				}
				
				$j("#navigation a").each( function() {
					$j(this).html('<span>'+$j(this).text()+'</span>');
				});
				
				
					$j("#navigation a").hover( function() {
						if (!$j(this).parent("li").is('.current_page_item')) {
							$j(this).animate({ marginTop: '19px', height: '106px' },{ queue: false, duration: 200 });
						}
					}, function() {
						if (!$j(this).parent("li").is('.current_page_item')) {
							$j(this).animate({ marginTop: '39px', height: '86px' },{ queue: false, duration: 200 });
						}
					})	
								
				$j(".foot_nav li:not(:last)").append(" | "); // insert bars between nav items, except the last one
				
				
				if ($j(".sliders").exists) {
					function hide_sliders() {
						$j(".slider").animate({ bottom: '-'+orig_slide_height },{ queue: false, duration: 500 } )
					}
					setTimeout( hide_sliders, 1000); // make these slide out 1 second after load
					window.orig_slide_height = $j(".slider .content").outerHeight();
					
					
					// sliders
					$j(".slider").hover( function() {
						$j(this).animate({ bottom: '0px' },{ queue: false, duration: 500 } );
						
					}, function() {
						$j(this).animate({ bottom: '-'+orig_slide_height },{ queue: false, duration: 500 } );
					})
				}
				
				// homepage banner
				
				$j("#banner .post").css('display','none');
				$j("#banner .post:first").addClass('active_banner_item').fadeIn();
				$j("#banner #banner_nav li:first a").addClass('active_banner_tab').hide();
				
				$j("#banner_nav a").live("click", function() {
					var post2load = $j(this).attr("id");
					var post2load = '#post-'+post2load.substr(5);
					
					$j(".active_banner_tab").removeClass('active_banner_tab').show();
					$j(this).addClass('active_banner_tab').hide();
					
					$j("#banner #banner_content").fadeOut( function() {
						$j(".active_banner_item").removeClass('active_banner_item').hide();
						$j(post2load).addClass('active_banner_item').show();
						
						
						//alert(post2load);
					}).fadeIn();
					return false;
				})	
				
				
				function set_active_prod_tab(hash) {
					
					// hash: not required. will use first tab, if not set.
					
					if (hash == '' || hash == false) { // if there's no hash, show the first tab's content
						$j('.tab_cont:not(:first)').hide(); // hide all tab_content, but the first
						$j('.tab_cont:first, .tabs a:first').addClass('active'); // give first tab_content active class
					}
					else { // if there is a hash...
						var tab_hash = '#tab_'+hash.substr(1); // remove hash from url, add a "#tab_" prefix to the hash (this is to prevent scrolling on click)
						var cont_hash = '#tab_cont_'+hash.substr(1); // remove hash from url, add a "#tab_" prefix to the hash (this is to prevent scrolling on click)
						
						
						$j('.tabs a.active, .tab_cont.active').removeClass('active'); // remove active class from old active item
						$j('.tabs a'+tab_hash).addClass('active');
						
						$j('.tab_content').hide(); // hide the inactive tab_content
						$j(cont_hash).addClass('active').show(); // all active class to proper tab_content
					}
				
				}
				
				
				// production tabs
				$j('.tab_content:not(:first)').hide();
				$j('.tab_content:first').show();
				set_active_prod_tab(window.location.hash);
				
				
				$j(".tabs a").click( function() {
					set_active_prod_tab($j(this).attr('href'));
				});
				
				
				
				$j(".twitter .content").getTwitter({
					userName: "ETPNW",
					numTweets: 3,
					loaderText: "Loading tweets...",
					slideIn: false,
					slideDuration: 750,
					showHeading: false,
					headingText: "Latest Tweets",
					showProfileLink: false,
					showTimestamp: true
				});
				
				$j(".news .content .hentry:last").css("border-bottom","0");
				
				
				
		
			});

