/**
* Search Form options
**/

$(document).ready(function(){


  if ($('a[rel=tipsy]').length>=1) {
    $('a[rel=tipsy]').tipsy({fade: true, gravity: 'n'});
  }



  $('#srch-keyword-reset').click(function(){
    $('#srch-keyword-field').val('');
    $('#srch-keyword-field').focus();
    return false;
  });

  $('#btn-find-your-art').mouseover(function(){
    $(this).addClass('over')
  }).mouseout(function(){
    $(this).removeClass('over')
  });


  $('#adv-toggle').click(function(){
    if ($('#adv-search:hidden').length==1) {
      //$('#adv-search:hidden').slideDown();
      $('#adv-search:hidden').animate({
        opacity:1,
        height:'toggle',
        duration:1000
      });
      $('#adv-find-button-container').animate({
        opacity:1,
        duration:500
      });
    } else {
      //$('#adv-search:visible').slideUp();
      $('#adv-find-button-container').animate({
        opacity:0,
        duration:20
      });
      $('#adv-search:visible').animate({
        opacity:0,
        height:'toggle',
        duration:1000
      });

    }
    return false;


  });//end adv-toggle


  $('.catchk').change(function(){
    $(this).parent().toggleClass('selected');
  })//end category checkbox onchange


  // Token Regeneration
  function regenerateToken(tokenName) {
    $.getJSON('/newtok.php',{tik:tokenName},function (oData){ updateTok(oData,tokenName);});
  }
  // regen via ajx with a delay to allow the server time to set the sessions
  if ($('#spartsignuptok').length>=1) {
    //spartsignup_to = window.setTimeout(regenerateToken,333,'spartsignup');
    var spartsignup_to = window.setTimeout( function() {regenerateToken('spartsignup'); },333);
  }
  if ($('#spartconttok').length>=1) {
    //spartcontact_to = window.setTimeout(regenerateToken,333,'spartcont');
    var spartcont_to = window.setTimeout( function() {regenerateToken('spartcont'); },333);
  }
  if ($('#spartsignintok').length>=1) {
    //spartsignin_to = window.setTimeout(regenerateToken,333,'spartsignin');
    var spartsignin_to = window.setTimeout( function() {regenerateToken('spartsignin'); },333);
  }
  if ($('#spartchkouttok').length>=1) {
    //spartchkout_to = window.setTimeout(regenerateToken,333,'spartchkout');
    var spartchkout_to = window.setTimeout( function() {regenerateToken('spartchkout'); },333);
  }
  if ($('#spartaccdeletetok').length>=1) {
    //spartchkout_to = window.setTimeout(regenerateToken,333,'spartaccdelete');
    var spartaccdelete_to = window.setTimeout( function() {regenerateToken('spartaccdelete'); },333);
  }
  if ($('#sparteditacctok').length>=1) {
    //spartchkout_to = window.setTimeout(regenerateToken,333,'sparteditacc');
    var sparteditacc_to = window.setTimeout( function() {regenerateToken('sparteditacc'); },333);
  }


  function updateTok(oData,st) {
    var tokf = '#'+st+'tok';
    var oldt = $(tokf).val();
    $('#'+st+'tok').val(oData.newtoken);
    var tokto = st+'_to';
    window.clearTimeout(tokto);
  }


 //image enlargements in wysiwyg content
 //$('a.enlarge').colorbox({initialWidth:'400',initialHeight:'400'}) ;
 if ( $('a.enlarge').length>=1 ) {
   $('a.enlarge').colorbox();
 }



});//end doc ready


