jQuery(document).ready(function(){
	
	//Assign drop-down widths in main menu
	$('header#primary ul ul').each(function(){
		parentWidth = $(this).closest('li').width();
		submenuWidth = ( parseInt( parentWidth ) - 30 ) + 'px';
		$(this).width( submenuWidth );
	});
	
	//Enable external links
	$('a[href^="http://"]').attr('_target','blank');

	//Drop-down menus for IE6
	if( $.browser.msie && parseFloat( $.browser.version ) < 7.0 ){	
		$('header#primary li').hover(
			function(){
				$('ul:first',this).show();
			},
			function(){
				$('ul:first',this).hide();
			}
		)
	}
	
	//Homepage slideshow
	if( app == 'home' ){
		
		//Add pagination markup
				
		//Start slideshow
		$('#slideshow .slides').cycle({
			pager : '#slideshow .pagination',
			pagerAnchorBuilder : function(index,element){
				// return '<li><a href="#">' + (index+1) + '</a></li>';
			}
		});
	
	}
	
	//Auto clear search box
	$('#search input[type="text"]').autoClear();
	
	//Creates captions
	// $('#content p img, #content ul img').each(function(){
		// var caption = $(this).attr('alt');
		// if( caption != ''){
			// var imageWidth = $(this).attr('width');
			// if($(this).hasClass('right')){
                // $(this).wrap('<div class="photo-caption right" />').parent('div').css('width',imageWidth);
			// } else {
    			// $(this).wrap('<div class="photo-caption" />').parent('div').css('width',imageWidth);
			// }
			// $(this).parent('div').append('<p>'+caption+'</p>');
		// }
	// });
	
	//Calendar Events colorbox
	//$('a[rel^="event"]').colorbox({iframe:true, width:"500px", height:"350px"});
	
	//FAQs
	$('#faqs').each(function(){
		$faqs = $(this);
		$faqs.find('.hidden').hide().removeClass('hidden');
		$faqs.find('a').click(function(){
			$this = $(this).parent().next();
			if(!$this.is(':visible')){
				$faqs.find('div').slideUp();
				$this.slideDown();
			}
		});
	
	});
	
});

// Clears the default text when an input receives
// focus and reinstates it if it is left blank
(function($) {
 
    $.fn.autoClear = function() {	
        return this.each(function() {
            $(this).focus(function() {
                if( this.value == this.defaultValue ) {
                    this.value = "";
                }
            })
            .blur(function() {
                if( !this.value.length ) {
                    this.value = this.defaultValue;
                }
            });
        });
    };
	
})(jQuery);
