/*
 *  file:    Optimum global.js
 *  @author:  norman.vo@tequila.com.au
 *  started:  10.August.2011
 */

var ROOT_URL = {
  dev:  'http://optimum.2011.dev.tequilabeta.com.au/',
  stage:  'http://optimum.2011.stage.tequilabeta.com.au/',
  marsStage: 'http://Stage.OptimumPet.com.au/',
  live:  'http://www.optimumpet.com.au/'
}

// set to dev, stage or live as needed
    var CURR_HOST = 'http://'+window.location.hostname+'/';//ROOT_URL.live;

var ISOTOPE_WIDGET_SERVICE  = CURR_HOST + 'WidgetRequest.ashx';
var CAROUSEL_WIDGET_SERVICE  = CURR_HOST + 'CarouselRequest.ashx';

var LOCATION_PATH = {
  homepage : '/',
  carousel : '/Carousel',
  cat     : '/optimum-for-cats/view-all-cat-products.aspx',
  dog     : '/optimum-for-dogs/view-all-dog-products.aspx',
  forDogs   : '/optimum-for-dogs.aspx',
  forCats   : '/optimum-for-cats.aspx',
  allProducts : '/optimum-all-products.aspx',
  content   : '/Content'
}
var filterParams = {
  pet: '',
  age: '',
  size: ''
};

var COOKIE = { name: 'Optimum' };
var ANIMATION_DURATION = 500;
var ISOTOPE_ANIMATION_DURATION = 400;
var NUM_SIDE_PANELS_TO_DISPLAY = 3;

var postData;
var isFirstVisit = true;
var hasUsedSizeSlider = false;
var hasUsedSlider = false;
var carouselInit = false;

var targetURL;

var $panelDisplay = $('#panelDisplay');

var SLIDER_HANDLE = {
  increment  : 1,
  left    : 0,
  middle    : 1,
  right    : 2
}
var AGE_PARAM = { 
  young  : 'Young',
  adult  : 'Adult',
  mature  : 'Mature',
  all    : 'all'
}
var SIZE_PARAM = {
  small  : 'Small',
  medium  : 'Medium',
  large  : 'Large',
  all    : 'all'
}
var PET_PARAM = {
  cat  : 'Cat',
  both: 'Both',
  dog  : 'Dog'
}

var petDefault  = PET_PARAM.both;
var ageDefault  = 1;
var sizeDefault  = 1;

var NUM_PANELS_TO_SHOW = {
  top          :  2,
  bottom        :  2,
  six_small      :  6,
  four_small_one_wide  :  5
}
var FLAT_CAROUSEL = {
  wrap        :  "null",
  scroll_distance    :  1,
  num_items_to_show  :  8,
  width        :  70
}

//default value, gets re-written in ajaxCarousel()
var numCarouselItems = FLAT_CAROUSEL.num_items_to_show;
var CONTROLLER_CAROUSEL_ITEM_LIMIT = 9;

var splitIndex = NUM_PANELS_TO_SHOW.top;    // # of panels to display in the top-left section
var panelDisplayLimit;

var TOOLTIP_PARAM = {
  content    : 'FILTER YOUR OPTIMUM PRODUCTS',
  position  : 'topMiddle',
  target    : 'bottomMiddle',
  color    : '#000000',
  borderWidth  : 2,
  borderRadius: 4,
  padding    : 8,
  textAlign  : 'left',
  style    : 'light',
  delay    : 1000
}

var FEATURE_CAROUSEL_PARAM = {
  autoPlay        : 0,
  startingItemSeparation  : 110,
  itemSeparationFactor  : 0.8,
  startingWaveSeparation  : -20,
  waveSeparationFactor  : 0.9,
  itemDecreaseFactor    : 0.65,
  opacityDecreaseFactor  : 0.6,
  centerOffset      : 0,
  flankingItems      : 3,
  speed          : 300,  // any faster, FF & IE7 really chug
  animationEasing      : 'easeOutCubic', //'linear', //'swing', 
  quickerForFurther    : false,
  linkHandling      : 2, // 1 = any link clickable, 2 = only centered links clickthru
  startingItem      : 1,
  edgeReaction      : 'reset', //wraps but looks confusing; maybe set to 'nothing'?
  imgWidth        : 350,
  imgHeight        : 533,

  itemSeparationFactorIE7  : 1.2,
  startingWaveSeparationIE7: 0,
  waveSeparationFactor  : 1, // no height jitter
  itemDecreaseFactorIE7  : 1, // no scaling
  opacityDecreaseFactorIE7: 1, // no opac decrease
  flankingItemsIE7    : 2
}

/*
 * vars for bespoke pet slider
 */
var $scrubber = $('.scrubber');
var $scrubberBg = $('.scrubberBg');
var $invisibleScrubber = $('.invisibleScrubber');
var isFirstDrag = true;
var newPos;

var SCRUBBER_HANDLE_WIDTH = {
  normal  : '153px',
  neutral  : '316px'
}
var SCRUBBER_KEYPOINT = {
  start  : '0',
  end    : '151px',
  neutral  : '50',
  middle  : 80
}
var LABEL_BG_POS = {
  activeCat  : '0 0',
  neutral    : '0 -46px',
  activeDog  : '0 -92px'
}
var BACKGROUND_POS = {
  leftTop    : '0 4px',
  middleTop  : '107px 4px',
  neutralTop  : '107px 2px',
  rightTop  : '151px 4px',
  middleOffset: '107px -1px'
}
var SCRUBBER_TOP = {
  normal  : '0px',
  neutral  : '0px',
  offset  : '4px',
  ie    : '-43px'
}


/*
 * initialise tooltip
 * API: http://craigsworks.com/projects/qtip/docs/tutorials/
 */
function initToolTip() {
  $('.sliderContainer#petSliderContainer').hover().qtip({
    content: TOOLTIP_PARAM.content,
    position: {
      corner: {
        tooltip:  TOOLTIP_PARAM.position,
        target:    TOOLTIP_PARAM.target
      }
    },
    style: {
      color: TOOLTIP_PARAM.color,
      border: {
        width:  TOOLTIP_PARAM.borderWidth,
        radius:  TOOLTIP_PARAM.borderRadius
    },
      padding:  TOOLTIP_PARAM.padding,
      textAlign:  TOOLTIP_PARAM.textAlign,
      tip: true, // Give it a speech bubble tip with automatic corner detection
      name:  TOOLTIP_PARAM.style
    },
    show: { delay: TOOLTIP_PARAM.delay }
  });
}


/*
 * initialise filter sliders
 */
$(function() {
  $( "#sizeSlider" ).slider({
    value: sizeDefault,
    min: SLIDER_HANDLE.left,
    max: SLIDER_HANDLE.right,
    step: SLIDER_HANDLE.increment,
    animate: true,
/*
    slide: function( event, ui ) { sizeFilter(ui); }
    ,stop: function() {
*/
    stop: function() {
//      if (window.console) console.log( '** init sizeSlider slider stop' );
      getCurrentSize();
      verifyParams();
      carouselInit = false;
      filterDisplay( filterParams );
    }
  });
});

$(function() {
  $( "#ageSlider" ).slider({
    value: ageDefault,
    min: SLIDER_HANDLE.left,
    max: SLIDER_HANDLE.right,
    step: SLIDER_HANDLE.increment,
    animate: true,
/*    
    slide: function (event, ui) { ageFilter(ui); }
    ,stop: function() {
*/
    stop: function() {
//      if (window.console) console.log( '** init ageSlider slider stop' );
      getCurrentAge();
      verifyParams();
      carouselInit = false;
      filterDisplay( filterParams );
    }
    
  });
});


/*
 * show/hide homepage panels
 */
function toggleDefaultPanels( displayOption ) {
//  if (window.console) console.log( 'toggleDefaultPanels(): ' + displayOption );
  
  var $panel1 = $('#panel1');
  var $panel2 = $('#panel2');
  var $panel3 = $('#panel3');
  var $section2 = $('#standardDisplaySection2');

  switch ( displayOption ) {
    case 'SHOW': {
      $panel1.slideDown( ANIMATION_DURATION );
      $panel2.slideDown( ANIMATION_DURATION );
      $panel3.slideDown( ANIMATION_DURATION );
      $section2.slideDown( ANIMATION_DURATION );
      break;
    }
    case 'HIDE': {
      $panel1.slideUp( ANIMATION_DURATION );
      $panel2.slideUp( ANIMATION_DURATION );
      $panel3.slideUp( ANIMATION_DURATION );
      $section2.slideUp( ANIMATION_DURATION );
      break;
    }
    default: {
      $panel1.toggle( ANIMATION_DURATION );
      $panel2.toggle( ANIMATION_DURATION );
      $panel3.toggle( ANIMATION_DURATION );
      $section2.toggle( ANIMATION_DURATION );
      break;
    }
  }
}


/*
 * initialise the water wheel carousel (large, main feature carousel)
 * API:  http://www.bkosborne.com/jquery-waterwheel-carousel/options
 */
function initFeatureCarousel() {
//  if (window.console) console.log( 'initFeatureCarousel()');

    $("#featureCarousel").waterwheelCarousel({
      startingItem      : FEATURE_CAROUSEL_PARAM.startingItem,
      startingItemSeparation  : FEATURE_CAROUSEL_PARAM.startingItemSeparation,
  
      itemSeparationFactor  : FEATURE_CAROUSEL_PARAM.itemSeparationFactor,
      startingWaveSeparation  : FEATURE_CAROUSEL_PARAM.startingWaveSeparation,
      waveSeparationFactor  : FEATURE_CAROUSEL_PARAM.waveSeparationFactor,
      itemDecreaseFactor    : FEATURE_CAROUSEL_PARAM.itemDecreaseFactor,
      opacityDecreaseFactor  : FEATURE_CAROUSEL_PARAM.opacityDecreaseFactor,
  
      centerOffset      : FEATURE_CAROUSEL_PARAM.centerOffset,
      flankingItems      : FEATURE_CAROUSEL_PARAM.flankingItems,
  
      autoPlay         : FEATURE_CAROUSEL_PARAM.autoPlay,
      speed          : FEATURE_CAROUSEL_PARAM.speed,
      quickerForFurther    : FEATURE_CAROUSEL_PARAM.quickerForFurther,
  
      animationEasing      : FEATURE_CAROUSEL_PARAM.animationEasing,
      linkHandling      : FEATURE_CAROUSEL_PARAM.linkHandling,
      edgeReaction      : FEATURE_CAROUSEL_PARAM.edgeReaction
    });

  
    //bind mousewheel event
    $('#featureCarousel').live('mousewheel', function(event, delta) {
    var scrollDirection = delta > 0 ? 'Left' : 'Right'
    if ( scrollDirection == 'Left' ) {
      $(".carousel-prev").trigger('click');
      centerCallback();
    }
    else {
    // == 'Right'
    
      $(".carousel-next").trigger('click');
      centerCallback();
    }
    return false;
  });

  //init details
  clearProductDetails();
  
  //load first product
  loadProductDetails( $('#container .carousel-images img') );  
}


// handle hyperlink & load detail update
function centerCallback() {
//  if (window.console) console.log( 'centerCallback()' );
  var ACTIVE_INDEX = '5';

  $('#container .carousel-images img').each(function(index, element) {
    
    // active image (centered) always has z-index = 5;
    if ( $(this).css('z-index') == ACTIVE_INDEX ) {
      $(this).trigger('click');
    }
  });
}


/*
 * initialise the carousel controller (which is also a 'flat' carousel)
 * API: http://sorgalla.com/projects/jcarousel/
 */
function initControllerCarousel( numItems ) {
//  if (window.console) console.log( 'initControllerCarousel()');
  
  $('#optimumCarousel').jcarousel({
      wrap: FLAT_CAROUSEL.wrap,
      scroll: FLAT_CAROUSEL.scroll_distance,
      visible: numCarouselItems,
    fixedWidth: FLAT_CAROUSEL.width
  });

  if ( navigator.appName == 'Microsoft Internet Explorer' ) {
    $('#optimumCarousel').css({
      'margin-left' : '-4px'
    });
  }
    
    //bind mousewheel event
    $('#optimumCarousel').bind('mousewheel', function(event, delta) {
      var scrollDirection = delta > 0 ? 'Left' : 'Right'
    if ( scrollDirection == 'Left' ) {
      $("div.jcarousel-prev.jcarousel-prev-horizontal").trigger('click');
    }
    else {
      // == 'Right'
      $("div.jcarousel-next.jcarousel-next-horizontal").trigger('click');
    }
    return false;
  });
  
  $('#carousel1 .jcarousel-next').hide();
  $('#carousel1 .jcarousel-prev').hide();

  if ( ( window.location.pathname == LOCATION_PATH.allProducts ) ||
     ( window.location.pathname == LOCATION_PATH.dog ) ||
     ( window.location.pathname == LOCATION_PATH.cat ) )
  {
    // show scroller arrows on 'view all products page' if enough items
    if ( numItems >= CONTROLLER_CAROUSEL_ITEM_LIMIT ) {
      $('#carousel1 .jcarousel-next').show();
      $('#carousel1 .jcarousel-prev').show();
    }

  }
  
}


/*
 * convert current values to jQuery UI slider values (integers)
 */
function ageToInt( val ) {
  switch ( val ) {
    case AGE_PARAM.young: ageDefault = SLIDER_HANDLE.left;    break;
    case AGE_PARAM.mature: ageDefault = SLIDER_HANDLE.right;  break;
    default: ageDefault = SLIDER_HANDLE.middle;         break;
  }
  return ageDefault;
}

function sizeToInt( val ) {
  switch ( val ) {
    case SIZE_PARAM.small: sizeDefault = SLIDER_HANDLE.left;  break;
    case SIZE_PARAM.large: sizeDefault = SLIDER_HANDLE.right;  break;
    default: sizeDefault = SLIDER_HANDLE.middle;        break;
  }
  return sizeDefault;
}


function getCurrentPet() {
//  if (window.console) console.log( '_  _  _  getCurrentPet(): ' + filterParams.pet );

  if (filterParams.pet == '') {
    filterParams.pet = PET_PARAM.both;
  }
  return filterParams.pet;
}


/*
 * convert current jQuery UI slider values to parameters (strings)
 */
function getCurrentAge() {
  var $ageSliderVal = $('#ageSlider').slider( "option", "value" );
  
  switch ( $ageSliderVal ) {
    case SLIDER_HANDLE.left: filterParams.age = AGE_PARAM.young;  break;
    case SLIDER_HANDLE.right: filterParams.age = AGE_PARAM.mature;  break;
    default: {
      if (window.location.pathname == LOCATION_PATH.allProducts) {
        filterParams.age = AGE_PARAM.all;
      }
      else if ( (window.location.pathname == LOCATION_PATH.cat) ||
            (window.location.pathname == LOCATION_PATH.dog) )
      {
        if (isFirstVisit == true) {
          restoreMainSlider();
          
          filterParams.age = AGE_PARAM.all;
          isFirstVisit = false;

          //disable age + size
          $('#ageSlider').hide();
          $('#sizeSlider').hide();
          
          //hide normal age slider components
          /*
          $('#ageSliderContainer .ui-state-default').css('background-image','url("/assets/images/scrollerGrey.png")');
          $('#sizeSliderContainer .ui-state-default').css('background-image','url("/assets/images/scrollerGrey.png")');
          */
          
          
          // listen for UI
          $(function() {
            $( "#ageSlider" ).slider({
              value: SLIDER_HANDLE.middle,
              min: SLIDER_HANDLE.left,
              max: SLIDER_HANDLE.right,
              step: SLIDER_HANDLE.increment,
              animate: true,
              start: function (event, ui) {
                $('#ageSliderContainer .ui-state-default').css('background-image','url("/assets/images/scroller.png")');
                $('#sizeSliderContainer .ui-state-default').css('background-image','url("/assets/images/scroller.png")');
              }
            });
          });
        }
        else {
          filterParams.age = AGE_PARAM.adult;
        }
      }
      else {
        filterParams.age = AGE_PARAM.adult;
      }
      break;
    }
  }
  
//  if (window.console) console.log( '_  _  _  getCurrentAge(): ' + filterParams.age );
  return filterParams.age;
}


function getCurrentSize() {

  var $sizeSliderVal = $('#sizeSlider').slider( "option", "value" );
  
  switch ( $sizeSliderVal ) {
    case SLIDER_HANDLE.left: filterParams.size = SIZE_PARAM.small;    break;
    case SLIDER_HANDLE.right: filterParams.size = SIZE_PARAM.large;    break;
    default: {
      if (window.location.pathname == LOCATION_PATH.allProducts) {
        filterParams.size = SIZE_PARAM.all;
      }
      else if ( (window.location.pathname == LOCATION_PATH.cat) ||
            (window.location.pathname == LOCATION_PATH.dog) )
      {
        if ( (isFirstVisit == true) || (hasUsedSizeSlider == false) ) {
          restoreMainSlider();
          
          filterParams.size = SIZE_PARAM.all;
          isFirstVisit = false;
          hasUsedSizeSlider = true;

          //disable age + size
          $('#ageSlider').hide();
          $('#sizeSlider').hide();
          
          //hide normal size slider components
          $('#ageSliderContainer .ui-state-default').css('background-image','url("/assets/images/scrollerGrey.png")');
          $('#sizeSliderContainer .ui-state-default').css('background-image','url("/assets/images/scrollerGrey.png")');
          
          // listen for UI
          $(function() {
            $( "#sizeSlider" ).slider({
              value: SLIDER_HANDLE.middle,
              min: SLIDER_HANDLE.left,
              max: SLIDER_HANDLE.right,
              step: SLIDER_HANDLE.increment,
              animate: true,
              start: function (event, ui) {
                $('#ageSliderContainer .ui-state-default').css('background-image','url("/assets/images/scroller.png")');
                $('#sizeSliderContainer .ui-state-default').css('background-image','url("/assets/images/scroller.png")');
              }
            });
          });
          
        } else {
//          if (window.console) console.log( 'Carousel page, not first visit' );
          filterParams.size = SIZE_PARAM.medium;
        }

      } else {
//        if (window.console) console.log( 'NOT Carousel page' );
        filterParams.size = SIZE_PARAM.medium;
      }
      break;
    }
  }
  
  return filterParams.size;
}


/*
 * retrieve page cookies
 */
function getCookie() {
//  if (window.console) console.log( 'getCookie()' );

  var $pageCookie = $.cookie( COOKIE.name );
  var petCookie, ageCookie, sizeCookie;
  
  if ( $pageCookie == null ) {
//    if (window.console) console.log( '$pageCookie == null' );

    // first visit
    petCookie = PET_PARAM.both;
    ageCookie = AGE_PARAM.adult;
    sizeCookie = SIZE_PARAM.medium;

    isFirstVisit = true;
  }
  else {
//    if (window.console) console.log( 'ELSE: $pageCookie != null' );

    isFirstVisit = false;
    
    petCookie  = $pageCookie.split('&')[0].split('=')[1];
    ageCookie  = $pageCookie.split('&')[1].split('=')[1];
    sizeCookie = $pageCookie.split('&')[2].split('=')[1];
    
    if ( petCookie == '' ||
       ageCookie == '' ||
       sizeCookie == '' ) {
//      if (window.console) console.log(' missing some cookie values' );
      // set missing / empty values to default
      if ( petCookie == '' )  petCookie = PET_PARAM.both;
      if ( ageCookie == '' )  ageCookie = AGE_PARAM.adult;
      if ( sizeCookie == '' )  sizeCookie = SIZE_PARAM.medium;

      filterParams = { pet: petCookie, age: ageCookie, size: sizeCookie };
      filterDisplay( filterParams );
    }
  }

  setPageDefaults(petCookie, ageCookie, sizeCookie);
}


// proxy method of writing to cookie before redirect home
// directly writing to cookie gets overwritten by the server
function writeCookieByProxyAndRedirect() {
//  if (window.console) console.log( 'writeCookieByProxyAndRedirect() ');

  filterDisplay( filterParams );
  revealPanels();
}



/*
 * set page defaults according to cookies
 */
function setPageDefaults(petParam, ageParam, sizeParam) {
//  if (window.console) console.log( 'setPageDefaults() ');
/*
//  if (window.console) console.log( '  petParam: ' + petParam );
//  if (window.console) console.log( '  ageParam: ' + ageParam );
//  if (window.console) console.log( '  sizeParam ' + sizeParam );
*/
  
  petDefault = petParam;
  
  // update sliders to match cookies
  $( "#ageSlider" ).slider({  value: ageToInt( ageParam ) });
  $( "#sizeSlider" ).slider({ value: sizeToInt( sizeParam ) });

  // update pet slider
  snapToPet( petParam );

  // update display to match cookies
  if ( petDefault == PET_PARAM.both ) {
    if  ( ( ageParam == AGE_PARAM.all ) && ( sizeParam == SIZE_PARAM.all ) ) {
//      if (window.console) console.log( '- - -  view all products carousel page' );

      // special case: view all products carousel page
      filterParams = { pet: petParam, age: ageParam, size: sizeParam };
      filterDisplay( filterParams );
    }
    else {
      // special case: homepage, show main panels
      toggleDefaultPanels( 'SHOW' );
          
      isFirstVisit = false;
      splitIndex = 0;
    }
  }
  else {
//    if (window.console) console.log( '- - -  petDefault != PET_PARAM.both' );

    filterParams = { pet: petParam, age: ageParam, size: sizeParam };
    filterDisplay( filterParams );
  }
}


/*
 * show/hide sub-navigation
 */
function toggleSubNav( nav ) {
  switch ( nav ) {
    case PET_PARAM.dog: {
      //show dog subnav
      $('#catNav').hide();
      $('#dogNav').slideDown( ANIMATION_DURATION );
      break;
    }
    case PET_PARAM.cat: {
      //show cat subnav
      $('#dogNav').hide();
      $('#catNav').slideDown( ANIMATION_DURATION );
      break;
    }
    default: {
      //hide subnavs
      $('#catNav').hide();
      $('#dogNav').hide();
      break;
    }
  }
}


/*
 * filter slider scripts
 */
function petFilter( pet ) {
//  if (window.console) console.log( 'petFilter()' );
  
  var $ageYoung = $('#ageYoung');
  var $ageSliderContainer = $('#ageSliderContainer');

  switch ( pet ) {
    case PET_PARAM.cat: {
      filterParams.pet = PET_PARAM.cat;

      //change filter label
      $ageYoung.html('kitten');
      $ageSliderContainer.css('background', 'url(\'/assets/images/bg_slider_age_kitten.png\')');
      break;
    }
    case PET_PARAM.dog: {
      filterParams.pet = PET_PARAM.dog;

      //change filter label
      $ageYoung.html('puppy');
      $ageSliderContainer.css('background', 'url(\'/assets/images/bg_slider_age_puppy.png\')');
      break;
    }
    default: {
      // all
      filterParams.pet = PET_PARAM.both;

      //change filter label
      $ageYoung.html('young');
      $ageSliderContainer.css('background', 'url(\'/assets/images/bg_slider_age.png\')');
      break;
    }
  } //end switch
  
  verifyParams();
  filterDisplay( filterParams );
  toggleSubNav( filterParams.pet );
}


function ageFilter(ui) {
//  if (window.console) console.log( 'agefilter(): ui: ' + ui.value );

  switch ( ui.value ) {
    case SLIDER_HANDLE.left: {  
      // young
      filterParams.age = AGE_PARAM.young;
      break;
    }
    case SLIDER_HANDLE.right: {
      // mature
      filterParams.age = AGE_PARAM.mature;
      break;
    }
    default: {
      // all
      filterParams.age = AGE_PARAM.adult;
      break;
    }
  } //end switch

  // allow carousel to be re-initialised
  carouselInit = false;

  verifyParams();
  filterDisplay( filterParams );
}


function sizeFilter(ui) {
//  if (window.console) console.log( 'sizefilter(): ui: ' + ui.value );

  switch ( ui.value ) {
    case SLIDER_HANDLE.left: {  
      // small
      filterParams.size = SIZE_PARAM.small;
      break;
    }
    case SLIDER_HANDLE.right: {
      // large
      filterParams.size = SIZE_PARAM.large;
      break;
    }
    default: {
      // all
      filterParams.size = SIZE_PARAM.medium;
      break;
    }
  } //end switch

  // allow carousel to be re-initialised
  carouselInit = false;

  verifyParams();
  filterDisplay( filterParams );
}


/*
 * load product details into carousel detail display
 */
function loadProductDetails( product ) {
//  if (window.console) console.log( 'loadProductDetails() ' );
  
  targetURL = product[0].name;
  
  //load details
  $(".headerContainer").html('<h4 class="' + product[0].id +'" id="title-text">' + product[0].title + '</h4>');

  //display alt
  $("#alt-text").html( product[0].alt );

  //add 'more' button
  $('.btnMore').html('<a href="' + targetURL + '">More</a>');

  // bug fix for IE layering/positioning
  if ( navigator.appName == 'Microsoft Internet Explorer' ) $('#targetDetails').slideDown( ANIMATION_DURATION );

  return targetURL;
}

function clearProductDetails() {
//if (window.console) console.log( '    clearProductDetails() ');
  // clear details
  $(".headerContainer").html('');

  //display alt
  $("#alt-text").html( '' );

  //add 'more' button
  $('.btnMore').html('');
}



/*
 * dynamically center controller carousel & evenly space items out
 */
function setControllerCarouselDisplay( numItems ) {
//  if (window.console) console.log( 'setControllerCarouselDisplay(): '  + numItems );

  if (numItems < CONTROLLER_CAROUSEL_ITEM_LIMIT ) {
    numCarouselItems = numItems;
  }
  else {
    numCarouselItems = FLAT_CAROUSEL.num_items_to_show;
  }
}


/*
 * initialise and populate carousels (feature and controller) after AJAX call
 */
function ajaxCarousel( postData ) {
//  if (window.console) console.log( 'ajaxCarousel() ' );

  $.post(CAROUSEL_WIDGET_SERVICE, postData,
    function(data) {
      try{
      // clear current carousel
      $('#carousel1').html('');
      $('.carousel-images').html('');
      
      // open controller carousel
      $('#carousel1').html('<ul id="optimumCarousel" class="jcarousel-skin-tango">');
      
      setControllerCarouselDisplay( data.Items.length );
      
      for (var i=0; i < data.Items.length; i++) {
        // add feature carousel items
        // pass colour into id & link into name
        $('.carousel-images').append('<img src="' + data.Items[i].Src + '" alt="' + data.Items[i].Alt + '" title="' + data.Items[i].Title + '" id="' + data.Items[i].Colour + '" name="' + data.Items[i].Href + '" width="'+ FEATURE_CAROUSEL_PARAM.imgWidth +'" height="'+ FEATURE_CAROUSEL_PARAM.imgHeight +'" />');

        // add controller carousel items
        // pass colour into id & link into name
        $('#optimumCarousel').append('<li><img class="optimumCarousel" src="' + data.Items[i].Thumb + '" alt="' + data.Items[i].Alt + '" title="' + data.Items[i].Title + '" id="' + data.Items[i].Colour + '" name="' + data.Items[i].Href + '" /></li>');
      }

      // close controller carousel
      $('#carousel1').append('</ul>');


      // carousel items added, init carousels
      initControllerCarousel( data.Items.length );
      initFeatureCarousel();


      // feature carousel UI click events
      $('.carousel-images img').live('click', function() {
//        if (window.console) console.log( '    handle mouse event' );

        // carousel center image will have class 'active'
        if ( $(this).hasClass('active') ) {
          //follow hyperlink
          if ( targetURL == undefined ) {
            loadProductDetails( $('img.active') );
            return false;
          }
          else {
            window.location.href = targetURL;
          }
        }
        else {
          // load details
          loadProductDetails( $(this) );
        }
      });


      // controller carousel UI event click
      $('img.optimumCarousel').live('click', function() {
        loadProductDetails( $(this) );

        // display product in main area on click
        $('#featureCarousel .carousel-images img[name="' +  $(this)[0].name + '"]').trigger('click');
      });


      // handle carousel UI event swipe
      // functional, but far from perfect

      // swipe plugin bugs IE
      if ( navigator.appName != 'Microsoft Internet Explorer' ) {
        $('.carousel-images').swipe({
          swipeLeft: function() { $(".carousel-next").trigger('click'); },
          swipeRight: function() { $(".carousel-prev").trigger('click'); }
        });
        $('#optimumCarousel').swipe({
          swipeLeft: function() { $("div.jcarousel-next.jcarousel-next-horizontal").trigger('click'); },
          swipeRight: function() { $("div.jcarousel-prev.jcarousel-prev-horizontal").trigger('click'); }
        });
      }
}catch(err){}
    });
}




/*
 * split homepage panels depending on filters
 */
function setPanelLimits( filterParams, numPanels ) {
  switch( filterParams.pet ) {
    case PET_PARAM.cat: {
      splitIndex      =  NUM_PANELS_TO_SHOW.six_small;//NUM_PANELS_TO_SHOW.four_small_one_wide;
      panelDisplayLimit  = NUM_PANELS_TO_SHOW.bottom;
      break;
    }
    case PET_PARAM.dog: {
      if ( filterParams.age == AGE_PARAM.adult ) splitIndex = NUM_PANELS_TO_SHOW.six_small;
      else splitIndex = NUM_PANELS_TO_SHOW.four_small_one_wide;

      panelDisplayLimit = NUM_PANELS_TO_SHOW.bottom;
      break;
    }
    default: {
      //both
      if ( isFirstVisit == true ) {
        // a default 2x2 panel, and two 1x1 panels
        splitIndex = NUM_PANELS_TO_SHOW.top;
      }
      else if ( filterParams.pet == PET_PARAM.both ) {
        // not first visit, special case, show main panels: a default 2x2 panel, and two 1x1 panels
        splitIndex = NUM_PANELS_TO_SHOW.top;
      }
      else {
        splitIndex = NUM_PANELS_TO_SHOW.six_small;
      }

      panelDisplayLimit = numPanels;
      break;
    }
  }

}


/*
 * create panels from AJAX service response data
 */
function constructPanel( data, index ) {
//  if (window.console) console.log( 'constructPanel() ');

    //var panelHTML = '<div id="' + data.Widgets[index].Id + '" class="' + data.Widgets[index].Class + ' movable"><div class="panelDescriptionContainer" style="background-image:url(\'' + data.Widgets[index].ImgSrc + '\');"><div class="panelDescription"><h4>' + data.Widgets[index].H4 + '</h4><h2 class="' + data.Widgets[index].Colour + '">' + data.Widgets[index].H2 + '</h2><p>' + data.Widgets[index].P + '</p></div><div class="panelLinkContainer"><a class="button" href="' + data.Widgets[index].Href + '">More</a></div></div><div class="bottomBorder ' + data.Widgets[index].Colour + '"></div></div>';

    
  var panelHTML = '<div id="' + data.Widgets[index].Id 
      + '" class="' + data.Widgets[index].Class 
      + ' movable"><div class="panelDescriptionContainer" onclick="location.href=\'' 
      + data.Widgets[index].Href + '\';" style="background-image:url(\'' 
      + data.Widgets[index].ImgSrc + '\');cursor:pointer;"><div class="panelDescription"><h4>&nbsp;</h4><h2 class="' 
      + data.Widgets[index].Colour + '">' + data.Widgets[index].H2 + '</h2><p>' 
      + data.Widgets[index].P + '</p></div><div class="panelLinkContainer"><a class="button" href="' 
      + data.Widgets[index].Href + '">More</a></div></div><div class="bottomBorder ' 
      + data.Widgets[index].Colour + '"></div></div>';

  return panelHTML;
 
}


/*
 * if params are empty, get current slider vals
 */
function verifyParams( filterParams ) {
//  if (window.console) console.log( 'verifyParams()' );

  getCurrentPet();
  getCurrentAge();
  getCurrentSize();
}


/*
 * perform AJAX calls
 */
function filterDisplay(filterParams) {
//  if (window.console) console.log('\n  filterDisplay() \n\n' );

//  verifyParams( filterParams );

  postData = '{"Size":"' + filterParams.size + '", "Age":"' + filterParams.age + '", "Animal": "' + filterParams.pet + '"}'; 

  if ( $('#mainDisplay').hasClass('carousel') ) {
    if (carouselInit == false) {
      ajaxCarousel( postData );
      carouselInit = true;
      
//      if (window.console) { console.log(' allow slider to filter'); }
      hasUsedSlider = false;
    }
  }
  else {
    /*
     * display html from ajax
     */
    $.post(ISOTOPE_WIDGET_SERVICE, postData,
      function(data) {

        
        
      /* new AJAX service */
      setPanelLimits( filterParams, data.Widgets.length );

      if ( isFirstVisit == true ) {
        // show main panel, don't append any panels to #topLeftSection
        toggleDefaultPanels( 'SHOW' );
        
        isFirstVisit = false;
        splitIndex = 0;
      }
      else if ( filterParams.pet == PET_PARAM.both ) {
        //empty previous dynamic HTML
        $('#topLeftSectionPanels').html('');
        $('#panelDisplay').html('');

        // show default panels
        toggleDefaultPanels( 'SHOW' );

        splitIndex = 0;
      }
      else {
        // hide default panels
        toggleDefaultPanels( 'HIDE' );

        //empty previous dynamic HTML
        $('#topLeftSectionPanels').html('');
        $('#panelDisplay').html('');
      }


      // populate #topLeftSection
      if ( filterParams.pet != PET_PARAM.both ) {
        $.each(data.Widgets, function( num ) {
         
        
          
          var newhtml = constructPanel(data, num);
  
          if ( num < splitIndex ) {
            // splitting panel output on homepage
            if ( window.location.pathname == LOCATION_PATH.homepage ) {
              $('#topLeftSectionPanels').append(newhtml);
            }
            else {
              // not homepage, append all to same section
              $('#panelDisplay').append(newhtml);
            }
          }
          else {
            // append remaining items
            if ( ( window.location.pathname == LOCATION_PATH.homepage ) &&
               ( filterParams.pet == PET_PARAM.both) )
            {
              // do nothing
            }
            else {
              // not homepage, append all to same section
              $('#panelDisplay').append(newhtml);
            }
          }
          
          
          
           if ( $('.sideDisplay') ) {
        var $sideDisplay = $('.sideDisplay');
      
        // clear previous
        $sideDisplay.html('');
    
        for (var i=0; i < NUM_SIDE_PANELS_TO_DISPLAY; i++) {
         
        
          var sidehtml = constructPanel(data, i);
          
          //alert(sidehtml);
          $sideDisplay.append( sidehtml );
          }
        }
          
        }); // $.each()
      }
      // END populate #topLeftSection
      
      
      // if on content page
         
          if ( filterParams.pet == PET_PARAM.both ) {
           if ( $('.sideDisplay') ) {
        var $sideDisplay = $('.sideDisplay');
      
        // clear previous
        $sideDisplay.html('');
    
        for (var i=0; i < NUM_SIDE_PANELS_TO_DISPLAY; i++) {
          
        
          var sidehtml = constructPanel(data, i);
          
          //alert(sidehtml);
          $sideDisplay.append( sidehtml );
          }
        }
      }
    });
  }

} //filterDisplay 


/*
 * function to handle slider changes on non-carousel, non-homepage scenarios
 * rather than reconstruct homepage, just return user to homepage
 */
function revealPanels() {
//  if (window.console) console.log( 'revealPanels()' );

  filterDisplay( filterParams );

  $('#sideRight').slideUp( ANIMATION_DURATION );
  
  $('#content').slideUp( ANIMATION_DURATION, function() {
    getCurrentPet();
    getCurrentAge();
    getCurrentSize();

    //redirect home
    window.location.href = LOCATION_PATH.homepage;
  });

} //revealPanels



/*
 * Bespoke pet slider scripts
 */
function initPetSlider() {
//  if (window.console) console.log( '    initPetSlider() ');

  // if homepage or cat/dog carousel, normal petslider behaviour
  if ( ( window.location.pathname == LOCATION_PATH.homepage ) ||
     ( window.location.pathname == LOCATION_PATH.cat ) ||
     ( window.location.pathname == LOCATION_PATH.dog ) )
  {
//    if (window.console) console.log( '    Homepage or carousel');

    if ( isFirstDrag == true ) $('.invisibleScrubber').css('visibility', 'hidden');
    
    $('.invisibleScrubber').draggable({
      axis: 'x',
      containment: 'parent',
      cursor: 'pointer',
      start: function(event, ui)  { startDrag(); },
      drag: function(event, ui)  { updatePos(); },
      stop: function(event, ui)  { snapToPet(); }
    });

    $('.scrubberBgLeft').click(function() {
//      if (window.console) console.log( '\n\n ! ! ! scrubberBgLeft click, if carousel page, redirect to DOG' );
      snapToPet( PET_PARAM.dog );
      restoreMainSlider();
    });
    $('.scrubberBgRight').click(function() {
//      if (window.console) console.log( '\n\n ! ! ! scrubberBgRight click, if carousel page, redirect to CAT' );
      snapToPet( PET_PARAM.cat );
      restoreMainSlider();  
    });

    //toggle current pet
    $('.scrubberBg').click(function() {
//      if (window.console) console.log( '\n\n ! ! !  TOGGLE ' + filterParams.pet);
      
      if ( window.location.pathname == LOCATION_PATH.homepage ) {
//        if (window.console) console.log('\n\nhomepage, petSliderClickHandler() ');
        petSliderClickHandler();
      }


      if ( window.location.pathname == LOCATION_PATH.cat ) {
        if ( filterParams.pet == PET_PARAM.cat ) {
//          if (window.console) console.log( '-------------on CAT, redirect to DOG');
          window.location.href = LOCATION_PATH.dog;
        }
        else {
//          if (window.console) console.log( '-------------on CAT, stay on CAT');
          // do nothing
        }
      }
      else if ( window.location.pathname == LOCATION_PATH.dog ) {
        if ( filterParams.pet == PET_PARAM.dog ) {
//          if (window.console) console.log( '-------------on DOG, redirect to CAT');
          window.location.href = LOCATION_PATH.cat;
        }
        else {
//          if (window.console) console.log( '-------------on DOG, stay on DOG');
          // do nothing
        }
      }
      else {
        // do nothing
      }
    });
  }

  // if all products page, redirect on mousedown in petslider
  else if ( window.location.pathname == LOCATION_PATH.allProducts ) {
//    if (window.console) console.log( '      allProducts');

    // hide scrubber, inactive under current conditions
    $('.invisibleScrubber').css('visibility','hidden');
    
    $('.scrubberBgLeft').click(function() {
//      if (window.console) console.log( '      scrubberBgLeft click, redir to dog carousel' );
      window.location.href = LOCATION_PATH.dog;
    });
    $('.scrubberBgRight').click(function() {
//      if (window.console) console.log( '      scrubberBgRight click, redir to cat carousel' );
      window.location.href = LOCATION_PATH.cat;
    });
  }
  // if product page, redirect on mousedown in petslider
  else {
//    if (window.console) console.log( '      initPetSlider() product page');
    getCurrentPet();

    if ( filterParams.pet == PET_PARAM.both ) {
      // hide scrubber, inactive under current conditions
      $('.invisibleScrubber').css('visibility','hidden');

      $('.scrubberBgLeft').mousedown(function() {
        filterParams.pet = PET_PARAM.dog;
        writeCookieByProxyAndRedirect();
      });
      $('.scrubberBgRight').mousedown(function() {
        filterParams.pet = PET_PARAM.cat;
        writeCookieByProxyAndRedirect();
      });
    }
    else {
//      if (window.console) console.log( '      PET_PARAM != both, ' + filterParams.pet );

      $('.invisibleScrubber').css('visibility','visible');

      $('.invisibleScrubber').draggable({
        axis: 'x',
        containment: 'parent',
        cursor: 'pointer',
        start: function(event, ui)  { startDrag(); },
        drag: function(event, ui)  { updatePos(); },
        stop: function(event, ui)  {
          snapToPet();
          writeCookieByProxyAndRedirect();
        }
      });
    
      $('.scrubberBgLeft').click(function() {
//        if (window.console) console.log( '      scrubberBgLeft click, redir home' );
  
        if ( filterParams.pet == PET_PARAM.cat ) {
          //set pet = dog, write to cookie by proxy, redirect home
          filterParams.pet = PET_PARAM.dog;
          writeCookieByProxyAndRedirect();
        }
      });
      $('.scrubberBgRight').click(function() {
//        if (window.console) console.log( '      scrubberBgRight click, redir home' );

        if ( filterParams.pet == PET_PARAM.dog ) {
          //set pet = cat, write to cookie by proxy, redirect home
          filterParams.pet = PET_PARAM.cat;
          writeCookieByProxyAndRedirect();
        }
      });
    }
  }

}// END initPetSlider()


function restoreMainSlider() {
  $('.invisibleScrubber').css('visibility','visible');
  $('.scrubberBg').show();
  $('.scrubberBgLeft').hide();
  $('.scrubberBgRight').hide();
}


//handle start/first drag
function startDrag() {
//  if (window.console) console.log( 'startDrag() ');

  if ( isFirstDrag == true ) {
    // switch to wide scrubber after first drag, resize handler
    $('.invisibleScrubber').css({
      'width': SCRUBBER_HANDLE_WIDTH.normal
    });

    // change background scrubber asset
    $('.scrubber').css({
      'background-image'  : 'url("/assets/images/scrubber.png")',
      'background-repeat'  : 'no-repeat',
      'background-position': BACKGROUND_POS.middleOffset,
      'margin-top'    : SCRUBBER_TOP.normal
    });
    
    // ie needs margin fix
    if ( navigator.appName == 'Microsoft Internet Explorer' ) {
      $('.scrubber').css({ 'margin-top' : SCRUBBER_TOP.ie } );
    }
    
    isFirstDrag = false;
  }
}


//handle UI click, toggle pets
function petSliderClickHandler() {
//  if (window.console) console.log('petSliderClickHandler()');

  if ( filterParams.pet == PET_PARAM.cat ) {
//    if (window.console) console.log('toggle pet to DOG');
    filterParams.pet = PET_PARAM.dog;
  }
  else if ( filterParams.pet == PET_PARAM.dog ) {
//    if (window.console) console.log('toggle pet to CAT');
    filterParams.pet = PET_PARAM.cat;
  }
  else {
    // do nothing
  }
  snapToPet( filterParams.pet );
}



// snap scrubber pos to dog or cat
function snapToPet( petDefault ) {
//  if (window.console) console.log( 'snapToPet() ');
//  if (window.console) console.log( '  petDefault: ' + petDefault );

  var newPosVal;

  if ( petDefault ) {
    switch ( petDefault ) {
      case PET_PARAM.cat: {  
        newPosVal = SCRUBBER_KEYPOINT.end.split('px')[0];
        startDrag();
        break;
      }
      case PET_PARAM.dog: {  
        newPosVal = SCRUBBER_KEYPOINT.start;
        startDrag();
        break;
      }
      default: {
        newPosVal = SCRUBBER_KEYPOINT.neutral;
        break;
      }
    }//end switch
  } else {
    newPosVal = newPos.split('px')[0];
  }
  

  if ( newPosVal > SCRUBBER_KEYPOINT.middle ) {
    // snap to cat

//    if (window.console) console.log( '- - - handler past middle, snap to CAT' );
    
    $('.scrubber').css('background-position', BACKGROUND_POS.rightTop );
    $('.invisibleScrubber').css('left', SCRUBBER_KEYPOINT.end);
    
    //swap bg
    $('.scrubberBg').css( 'background-position', LABEL_BG_POS.activeCat );

    carouselInit = false;
//    petFilter( PET_PARAM.cat );

    if ( hasUsedSlider == false ) {
      petFilter( PET_PARAM.cat );
      hasUsedSlider = true;

    } else {
      // do nothing
    }

    if ( window.location.pathname == LOCATION_PATH.homepage ) {
      petFilter( PET_PARAM.cat );
    }

    if ( window.location.pathname == LOCATION_PATH.dog ) {
//      if (window.console) console.log( '------------- REDIRECT TO CAT');
      window.location.href = LOCATION_PATH.cat;
    }

  }
  else if ( newPosVal == SCRUBBER_KEYPOINT.neutral ) {
//    if (window.console) console.log( '  scrubber is NEUTRAL' );

    //special case
    if ( ( filterParams.age == AGE_PARAM.all ) && ( filterParams.size == SIZE_PARAM.all ) ) {
      filterDisplay( filterParams );
      toggleSubNav( filterParams.pet );
    }
    else {
      $('.scrubber').css({
        'background-image'  : 'url("/assets/images/scrubber_middle.png")',
        'background-repeat'  : 'no-repeat',
        'background-position': BACKGROUND_POS.middleTop,
        'margin-top'    : SCRUBBER_TOP.neutral
      });
  
      //swap bg
      $('.scrubberBg').css( 'background-position', LABEL_BG_POS.neutral );
  
      // move handlers to middle
      $('.scrubber').css({'background-position' : BACKGROUND_POS.neutralTop });
      $('.invisibleScrubber').css('left', SCRUBBER_KEYPOINT.start);
      
      // set to full width to 'listen' for start drag event
      $('.invisibleScrubber').css({ 'width': SCRUBBER_HANDLE_WIDTH.neutral });
      isFirstDrag = true;

      carouselInit = false;
    }//else
    
  }
  else {
  // snap to dog
  
//    if (window.console) console.log( '- - - handler past middle, snap to DOG' );
    
    $('.scrubber').css('background-position', BACKGROUND_POS.leftTop );
    $('.invisibleScrubber').css('left', SCRUBBER_KEYPOINT.start );

    //swap bg
    $('.scrubberBg').css( 'background-position', LABEL_BG_POS.activeDog );

    carouselInit = false;
//    petFilter( PET_PARAM.dog );
    
    if ( hasUsedSlider == false ) {
      petFilter( PET_PARAM.dog );
      hasUsedSlider = true;
    }
    else {
      // do nothing
    }
    
    if ( window.location.pathname == LOCATION_PATH.homepage ) {
      petFilter( PET_PARAM.dog );
    }

    if ( window.location.pathname == LOCATION_PATH.cat ) {
//      if (window.console) console.log( '------------- REDIRECT TO DOG');
      window.location.href = LOCATION_PATH.dog;
    }


  }

} // END snapToPet


function updatePos() {
//  if (window.console) console.log( 'updatePos() ');

  newPos = $('.invisibleScrubber').draggable( "option", "x" ).css("left");
  var newBackgroundPos = newPos + ' ' + SCRUBBER_TOP.offset;
  $('.scrubber').css('background-position', newBackgroundPos );
  
//  filterDisplay( filterParams );
}

/*
 * END Custom pet slider scripts
 */


/* Rob's code to clear input areas on focus */  
function toggleDefaultText() {
  var default_values = new Array();
  $("input.default-value").focus(function() {
    if (!default_values[this.id]) {
    default_values[this.id] = this.value;
    }
    if (this.value == default_values[this.id]) {
    this.value = '';
    }
    $(this).blur(function() {
    if (this.value == '') {
      this.value = default_values[this.id];
    }
    });
  });
  
}


$(document).ready(function () {

  initToolTip();
  initPetSlider();
  
  var $pageCookie = $.cookie( COOKIE.name );
  var REDIRECT_TIMEOUT = 1000;
  
  var petCookie = null;
  if ($pageCookie != null) { petCookie = $pageCookie.split('&')[0].split('=')[1];  }

  // homepage link on Optimum logo
  $('#topNavContainer #navLogo').live('click', function() {
    $.cookie( COOKIE.name, null );
    setPageDefaults( PET_PARAM.both, AGE_PARAM.adult, SIZE_PARAM.medium );
    filterParams = { pet: PET_PARAM.both, age: AGE_PARAM.adult, size: SIZE_PARAM.medium };
    filterDisplay( filterParams );

    // delay needed otherwise cookie is overwritten
    var redirectHome = window.setTimeout(function() {
      window.location.href = LOCATION_PATH.homepage
    }, REDIRECT_TIMEOUT);
    
  });


  switch ( window.location.pathname ) {
    case LOCATION_PATH.homepage: {
      // HOMEPAGE: load cookies. If no cookies, set to show main panel
      getCookie();
      break;
    }
    case LOCATION_PATH.cat:  {
      //cat carousel
      isFirstVisit = true;

      // set carousel to show only cat products
      setPageDefaults( PET_PARAM.cat, AGE_PARAM.adult, SIZE_PARAM.medium );
      filterParams = { pet: PET_PARAM.cat, age: AGE_PARAM.adult, size: SIZE_PARAM.medium };

      break;
    }
    case LOCATION_PATH.dog: {
      //dog carousel
      isFirstVisit = true;

      // set carousel to show only dog products
      setPageDefaults( PET_PARAM.dog, AGE_PARAM.adult, SIZE_PARAM.medium );
      filterParams = { pet: PET_PARAM.dog, age: AGE_PARAM.adult, size: SIZE_PARAM.medium };
      
      break;
    }
    case LOCATION_PATH.forDogs: {
      //send to dog carousel
      window.location.href = LOCATION_PATH.dog;
      break;
    }
    case LOCATION_PATH.forCats: {
      //send to cat carousel
      window.location.href = LOCATION_PATH.cat;
      break;
    }
    case LOCATION_PATH.allProducts: {
      //special case
      isFirstVisit = false;
      
      // disable age & size controls in this case
      $('#ageSlider').hide();
      $('#sizeSlider').hide();

      // set carousel to show ALL products
      setPageDefaults( PET_PARAM.both, AGE_PARAM.all, SIZE_PARAM.all );
      filterParams = { pet: PET_PARAM.both, age: AGE_PARAM.all, size: SIZE_PARAM.all };
    
      break;
    }
    default: {
      // all other pages
      isFirstVisit = false;
      getCookie();

      // init: hide tile display
      $('#panelDisplay').slideUp( ANIMATION_DURATION );
      
      // show main panels, restore normal slider functionality
      $( "#sizeSlider" ).slider({
        stop: function() {
//          if (window.console) console.log( '** sizeSlider slider stop' );
          getCurrentSize();
          writeCookieByProxyAndRedirect();
        }
      });
      $( "#ageSlider" ).slider({
        stop: function() {
          getCurrentAge();
          writeCookieByProxyAndRedirect();
        }
      });
      
      filterDisplay( filterParams );
      break;
    }
  }

  toggleSubNav( filterParams.pet );
  toggleDefaultText();

});
