// ssp.js
jQuery(function($){
  //MAIN NAVIGATION (IE6 only)...
  if($.browser.msie && $.browser.version < 7){
    $('#navlist a').pngfix().hover( function(){ $(this).pngfix({path:'images/nav-head-nod.png'}); }
                                  , function(){ $(this).pngfix({path:'images/stanley-head-nav.png'}); } );
  }
  //ACCORDION...
  $('.Accordion').find('>div').css({zoom:1}).end().accordion({header:'h3', autoheight:false, active:false, alwaysOpen:false})
    .find('h3').attr({title:'Click to Expand/Collapse'});
  //JOKES...
  var jokeReveal = function(){
      var tx = $(this).removeClass('Joke_click').next()
        , p = tx.parent()
        , op = p.hasClass('Joke_left')?{paddingLeft:0}:{paddingRight:0}
        , nx = p.next(':not(.Joke_clr)');
      tx.animate(op, function(){ nx.find('img').one('click', jokeReveal).addClass('Joke_click'); });
      nx.filter(':hidden').slideDown();
    };
  $('div.Joke').each(function(){
    $(this)
      .find('>div')
        .slice(2,-1).hide().end()
        .find('.Joke_slide').addClass('Joke_hide').end()
      .end()
      .find('img:first').one('click', jokeReveal).addClass('Joke_click');
    });
  //COMPETITIONS...
  //in HTML : give toggling checkboxes a generic class of competitionToggle, and an id that identifies the
  //          relevant DIV with 'Toggle' tacked on, eg div#formEntryPoetry and checkbox toggler #formEntryPoetryToggle
  $('.competitionToggle:checkbox')
    .each(function(){
        var me = $(this)
          , fId = this.id.replace(/Toggle$/,'') //strip 'Toggle' from the end of the checkbox's id
          , fEl = $('#' + fId).hide() //hide the form DIV element relevant to the checkbox, eg #formEntryPoetry
          ;
        this.checked=false; //make sure all checkboes are unchecked to start with
        me.click(function(){ fEl.toggle(); this.blur(); });
      });
  $('#competitionForm').ajaxForm({
      target: '#response'
    , beforeSubmit: function(){ $('#response').addClass('ajax-loading'); }
    , success: function(){ $('#response').removeClass('ajax-loading'); }
    });

  //WORDSEARCH...
  if($('#WordSearch').length){
    jsWordSearch.init('WordSearch',{words:10,rows:12,cols:12,wordlists:'script/wordsearch/wordlists/'});
  }
});


