jQuery(document).ready(function() {

    if (jQuery('#homepageSlideshow')) {
        var slideshowDiv = jQuery('#homepageSlideshow').parent().parent().next();
        
        slideshowDiv.wrap('<div style="height: 300px;"></div>');
        
        
		slideshowDiv.cycle({
			                 /* 
							 uncomment one of the fx lines below to activate an effect 
							  if no line is uncommented, the default effect is 'fade' which has anti-alias problems in IE 
							  */
							  fx:      'turnUp', 
							  //fx:      'turnDown', 
							  //fx:      'zoom', 
							  timeout: 14000 
	                      });
    }
    
    if (jQuery('#edit-search-block-form-1')) {
    	var search = jQuery('#edit-search-block-form-1');

    	search.focus(function(){
            if (search.val() == 'Search this site') {
                search.val("");
            }
        }).blur(function(){
            if (jQuery.trim(search.val()) == "") {
                search.val('Search this site');
            }
        });
    	
    	search.val('Search this site');
    }
    
    
    // make the menus accessible by keyboard and wrap them in h4 tags for screen-readers
    jQuery("ul.nice-menu > li > a").wrap('<h4></h4>');
        
    var lastParent = null;
    jQuery("ul.nice-menu > li > h4 > a").focus(
        function () {
           
           if (jQuery(this).parent().parent() != lastParent) {
               if (lastParent != null) {
                  jQuery("ul.nice-menu li").removeClass("over");
               }
               jQuery(this).parent().parent().addClass("over");
           }
           
           lastParent = jQuery(this).parent().parent(); 
        }
    );
    
    var menuItems = jQuery("ul.nice-menu a");
    
    jQuery(document).keyup(function (e) {
       if (e.keyCode == 9) {
       
           var found = false;
           for (var i=0; i < menuItems.length; i++) {
               if (menuItems[i] == e.target) {
                   found = true;
                   break;
               }
           }
           
           if (found == false) {
               jQuery("ul.nice-menu li").removeClass("over");
           }
       }
    });
    // keyboard accessible stuff
});

