$(document).ready(function(){

$('#promo').cycle({
        fx:     'fade',
        speed:   2000,
        timeout: 6000,
        pager:  '#ssnav',
        pagerAnchorBuilder: function(idx, slide) {
        return '#ssnav li:eq(' + (idx) + ') a';
        }
});

$('#ssnav').append("<li><a id='pbtn' class='pause'>&nbsp;</a></li>");
	var bplplay = true;
	$('#pbtn').click(function() {
			
	if (bplplay) {
	   $('#promo').cycle('pause');
	   $('#pbtn').removeClass('pause').addClass('play')
	   bplplay = false;
	} else {
	   $('#promo').cycle('resume');
	   $('#pbtn').removeClass('play').addClass('pause')
	   bplplay = true;
	}
});

//** TABS and TOGGLE
$("a.tab").click(function () {
	$(".active").removeClass("active");
	$(this).addClass("active");
	$(".tabcontent").hide();
	var content_show = $(this).attr("title");
	$("#"+content_show).fadeIn();
});

$('a#toggle').click(function() {
        $('#togglebox').toggle(400);
        return false;
 });

//** CAROUSEL and TOOLTIP

$('#rackslider').tinycarousel({ display: 9 });

$("#rackslider a").easyTooltip();

//** INJECT TAGS INTO HTML
$('<div class="cart_add_label">Flavors:</div>').insertBefore('select.shoppingFormQuantity');
$('<p><span class="yellow">Please Allow 2-3 Days For Shipping.</span><br/>Please complete the information below. Fields marked as <b>BOLD</b> are required fields.<br/>*Shipping to addresses within the 50 United States only. We cannot ship to PO Boxes, APO, Military Base addresses or Internationally.</p>').insertAfter('h1.shoppingHeading');

$('.newssignup input[name=formField_First_Name]')
      .val('First name is')
      .click(function() {
        if ($(this).val() == 'First name is')
          $(this).val('')
      }).blur(function() {
        if ($(this).val() == '')
          $(this).val('First name is')
});

$('.newssignup input[name=formField_Last_Name]')
      .val('Last name is')
      .click(function() {
        if ($(this).val() == 'Last name is')
          $(this).val('')
      }).blur(function() {
        if ($(this).val() == '')
          $(this).val('Last name is')
});

$('.newssignup input[name=formField_Email]')
      .val('My email address is')
      .click(function() {
        if ($(this).val() == 'My email address is')
          $(this).val('')
      }).blur(function() {
        if ($(this).val() == '')
          $(this).val('My email address is')
});


$('#searchwrapper input[name=search_this]')
      .val('Search...')
      .click(function() {
        if ($(this).val() == 'Search...')
          $(this).val('')
      }).blur(function() {
        if ($(this).val() == '')
          $(this).val('Search...')
});


//** MISC

$('.desctext').truncate({max_length: 700});


$("a.switch_thumb").toggle(function(){
	  $(this).addClass("swap"); 
	  $("ul.display").fadeOut("fast", function() {
	  	$(this).fadeIn("fast").addClass("thumb_view"); 
		 });
	  }, function () {
$(this).removeClass("swap");
	  $("ul.display").fadeOut("fast", function() {
	  	$(this).fadeIn("fast").removeClass("thumb_view");
		});
          });

// Youtube 

$("a.yt-video").click(function() {
	$.fancybox({
		'padding'	: 10,
		'autoScale'	: false,
		'width'		: 640,
		'height'	: 385,
                'href'          : this.href = this.href.replace(new RegExp("watch\\?v=", "i"), 'v/') + '&autoplay=1',
		'type'		: 'swf',
		overlayOpacity  :  0.9, 
		overlayColor 	:  '#0e193a'
	});
				
	return false;
});


$("ul.yt-list").ytplaylist({addThumbs: true, autoPlay: false, holderId: 'ytvideo'});
$("ul.yt-commlist").ytplaylist({playerHeight: '258', playerWidth: '425', addThumbs: true, autoPlay: false, holderId: 'ytcommvideo'});


$("ul.specialsthum li").hover(function() {
	$(this).css({'z-index' : '1800'});
	$(this).find('img').addClass("hover").stop()
		.animate({
			marginTop: '-14px',
			marginLeft: '-25px',
			top: '0',
			left: '0',
			width: '275px',
			height: '152px'
		}, 200);

	} , function() {
	$(this).css({'z-index' : '0'});
	$(this).find('img').removeClass("hover").stop()
		.animate({
			marginTop: '0',
			marginLeft: '0',
			top: '0',
			left: '0',
			width: '225px',
			height: '124px'
		}, 400);
      });

});
