jQuery.noConflict();

jQuery(function($) {
  
  //place default text in search field
  $('#q').defaulttext(); 
  

  //product list and "available sizes" expandable elements
  $('div.expander > a')
    .next().hide()
    .end()
    .show().click(function() {

      var $this = $(this);
      var bgp = $this.css('backgroundPosition') || $this.css('backgroundPositionY');
      if ($this.css('backgroundPosition')) {
        $this.css('backgroundPosition', (bgp.indexOf('-18px') == -1) ? '0 -18px' : '0 2px');
      } else {
        $this.css('backgroundPositionY', (bgp != '-18px') ? '-18px' : '2px');
      }
      $this.next().slideToggle(400, function() {
        if ($this[0].parentNode.id == 'product-full-list') {
          $this.text( (bgp.indexOf('-18px') == -1) ? 'Hide All Products' : 'List All Products' );
        }  
      });
      return false;
  });
  
  // cycle profile images
  var cycleProduct = function() {
    if (!document.getElementById('profile-images')) { return; }
    var $profileImages = $('#profile-images');
    if ($profileImages.find('a').length > 1) {
    $profileImages.height(170);
    $profileImages.cycle({
      timeout: 7000
    });
    }
  };
  cycleProduct();
  
  // cycle related products
  var $rProducts = $('#related-products');
  if ($.fn.cycle && $rProducts.length && $rProducts.children().length > 1) {
    $rProducts.before('<div id="ctrls"><a href="#" class="ctrl" id="rp-next">next</a><a href="#" class="ctrl" id="rp-prev">previous</a></div>');
    $rProducts.cycle({
      fx: 'scrollVert',
      timeout: 10000,
      delay: 2000,
      pause: 1,
      // autostop: true, /* for debugging */
      // autostopCount: 5, 
      next: '#rp-next',
      prev: '#rp-prev',
      easing: 'easeOutBounce'
    });
  }
  
});

// shadowbox initialization
jQuery(window).bind('load', function(event) {
  if (jQuery.fn.shadowbox != undefined) {
    Shadowbox.init();
  }
});
/***************************************
   Default Text Plugin for inputs
   @author Karl Swedberg
   @version 0.5 (07/08/2008)
   @requires jQuery v1.2.6+
   
 ************************************** */
 
(function($) {
  $.fn.defaulttext = function(options) {
    var elText = { 
      title: function(input) {
        return $(input).attr('title');
      },
      label: function(input) {
        var $lbl = $('label[for=' + input.id +']').hide();
        return $lbl.text();
      }
    };
    var defText;

    return this.each(function() {
      var $input = $(this);
      if (this.type === 'text' || this.nodeName.toLowerCase() === 'textarea') {
        var opts = $.extend({}, $.fn.defaulttext.defaults, options || {}, $.metadata ? $input.metadata() : $.meta ? $input.data() : {});
        if (opts.dtText.constructor === Function) {
          defText = opts.dtText(this);
        } else if (opts.dtText && opts.dtText.constructor === String){
          defText = (/(title|label)/).test(opts.dtText) ? elText[opts.dtText](this) : opts.dtText;
        } 
        if (!defText) {return;}

        if ($input.parent().css('position') == 'static') {
          $input.parent().css({position: 'relative'});
        }
        $(opts.dtTag).html(defText)
          .addClass(opts.dtClass)
          .css({
            position: 'absolute',
            top: $input.position().top,
            left: $input.position().left,
            display: 'none'
          })
          .insertBefore($input);

        // hide default text on focus
        $input.focus(function() {
          dtHide($input);
        });
        $input.prev('.' + opts.dtClass).click(function() {
          dtHide($input);
          $input.focus();
        });

        // conditionally show default text on ready and input blur
        dtShow($input);
        $input.blur(function() {
          dtShow($input);
        });
      }
    });


    function dtHide(el) {
      el.prev().hide();
    }
    function dtShow(el) {
      if ($.trim(el.val()) == '') {
        el.prev().show();
      }
    }
  };
  $.fn.defaulttext.defaults = {
    dtTag: '<span></span>', 
    dtClass: 'default-text',
    dtText: 'label'            // 'label' uses text of input's label; 'title' uses input's title attribute. 
                                //  otherwise, use some other string or function
  };
})(jQuery);