$(document).ready(function(){

if($('ul#slideshow').length) {

                    	$('ul#slideshow').innerfade({
                        speed: 500,
                        timeout: 10000,
                        type: 'sequence',
                        containerheight: 	'324px',
                        containerwidth: 	'732px',
                        slide_timer_on: 	'yes',
                        slide_ui_parent: 	'slideshow',
                       	slide_nav_id:		'slide_nav'
                    	});
                    	$.setOptionsButtonEvent();
} // End if slideshow            

        $("ul.sf-menu").superfish({
         autoArrows:    false 
        }); 

// Hide value of signup form on focus
$('input#search').focus(function() {
var theValue = $(this).val();
if(theValue == 'Search the site') {
$(this).val('');
}
});
$('input#search').blur(function() {
var theValue = $(this).val();
if(theValue == '') {
$(this).val('Search the site');
}
});

// Hide value of signup form on focus

$('input#mailing-list').focus(function() {
var theValue = $(this).val();
if(theValue == 'Email address') {
$(this).val('');
}
});
$('input#mailing-list').blur(function() {
var theValue = $(this).val();
if(theValue == '') {
$(this).val('Email address');
}
});



    // Fix the sidepanel when it gets tot he bottom
 var menuHeight = $('#sidebar .container').height();
 var contentHeight = $('#main').height();
 
 $('#sidebar').css('height',contentHeight);
$('#main .container').after('<div id="bottom"></div>');
 
if($('#sidebar .container').length) {
  var top = ($('#sidebar .container').offset().top - 40 ) - parseFloat($('#sidebar .container').css('marginTop').replace(/auto/, 0));
  $(window).scroll(function (event) {
  
    // what the y position of the scroll is
    var y = $(this).scrollTop();
 var bottomOffset = $('#bottom').offset().top - menuHeight -42;    
 var x = $('#sidebar .container').offset().top;
    // whether that's below the form
    if (y >= top && y < bottomOffset) {
      // if so, add the fixed class
      $('#sidebar .container').addClass('fixed').removeClass('fixed-bottom').css('margin-top','0px');
    } else if( x>=bottomOffset && y>=top   ) {
      // otherwise remove it
      var relativeMargin = (bottomOffset + menuHeight);
      $('#sidebar .container').removeClass('fixed').addClass('fixed-bottom').css({
      'height':menuHeight,
      'margin-top':relativeMargin      
      });
    
    } else if (y < top) {
    $('#sidebar .container').removeClass('fixed').removeClass('fixed-bottom').css('margin-top','0px');
    
    
    }
    

    
    
    
  }); // END window.scroll
  
 } 
  
  $('#slideshow-wrap').fadeIn();
//  $('header#top .outer').slideDown();
          
}); // End Doc ready
