Cufon.replace("h2, h3, .cufon, #home-paragraph, .bucket-title, .recipe-section-header, .subtitle, .view-more, .press-title, .press-sub");
Cufon("#menu ul li a, .small-recipe-list .view-more", { hover: { color: "#FFD4D9" } });
Cufon("#press-carousel ul li h2", { textShadow: '0px 4px #0D0103' });


$(function() {
	// IE6 Banner
	/*var ua = $.browser;
	if ( ua.msie && ua.version == "6.0" ) {
		alert( "gross" );
	}*/

  
	// make hum channel open externally from menu
	$("#nav-hum-channel a").attr("target", "_blank");


	// play button on homepage hum channel bucket
	$("#hum-channel #thumbnail img").fadeTo(0, 0.70);
  
	$("#hum-channel #thumbnail").mouseenter(function () {
		$("#hum-channel #thumbnail img").fadeTo("fast", 0.90);
	}).mouseleave(function () {
    	$("#hum-channel #thumbnail img").fadeTo("fast", 0.70);
	});


	// Expand Reatilers on Where to Find page  
	$(".retailer-state").click(function () {
		$(".two-list", this).slideToggle("slow");
	});


	// Expand small recipes on Recipe page 
	$(".small-recipe-list").click(function () {
		$(".small-recipe-container", this).slideToggle("slow");
	});
  
  
  
  ////////////////////////////////////////////////////////////////
  // PRESS SLIDE SHOW
  ////////////////////////////////////////////////////////////////
  
  var pressCounter = 0;
  var prevPress = 1;
  var pressTotal = $('#press-carousel ul li').size();
  var buttonEnabled = true;
  
  $(function() {
    if (pressTotal != 0) {
      $("#press-carousel").jCarouselLite({
          btnNext: "#press-next",
          btnPrev: "#press-prev",
          visible: 1,
          speed: 500,
          beforeStart: function(a) {
             // fade out text
              $("#press-info").fadeTo(200, 0);
              // Disable Buttons
              buttonEnabled = false;
          },
          afterEnd: function(a) {
            // update information
            $("#press-info .press-info-container:eq("+prevPress+")").css("display", "none");
            $("#press-info .press-info-container:eq("+pressCounter+")").css("display", "block");

            resizeFooter();
            
            // fade in text
            $("#press-info").fadeTo(200, 1, function() {
              buttonEnabled = true;
            });
          }
      });
      resizeFooter();
    }
  });
  
  // align within window if this is a quote
  $("#press-carousel ul li h2").each(function() {
    var parentHeight = $(this).parent().height();
    var height = $(this).height();    
    $(this).css("padding-top", (parentHeight - height) / 2);
  });

  $("#press-prev").click(function () {
    if (buttonEnabled) {
      prevPress = pressCounter;
      if (pressCounter == 0) {
        pressCounter = (pressTotal - 1);
      } else {
        pressCounter--;
      }
    }
  });
  
  $("#press-next").click(function () {
    if (buttonEnabled) {
      prevPress = pressCounter;
      if (pressCounter == (pressTotal - 1)) {
        pressCounter = 0;
      } else {
        pressCounter++;
      }
    }
  }); 
  
  
  ////////////////////////////////////////////////////////////////
  // MEDIA
  ////////////////////////////////////////////////////////////////
  
  $("#media a").click(function () {
    var id = $(this).parent().attr("id");
    if ($(this).attr("class") == "download") {
      $(this).html(" - downloaded").css("color", "#FFF");
    } else {
      if (id == "") {
        $("#media-view").html("<img src='/images/media/missing-preview.jpg' alt='' />");
      } else {
        $("#media-view").html("<img src='/images/media/"+id+"-preview.jpg' alt='' />");
      }
    }
  });
  
  
  // call resize footer
  resizeFooter();
    
});

function resizeFooter() {
  if ($('#footer-container').length > 0) {
  	var footerPos = $("#footer-container").offset();
	  var footerBot = footerPos.top + 41;
	  var windowHeight = window.innerHeight;
  
	  if (footerBot < windowHeight) {
	    var newHeight = (windowHeight - footerBot > 50) ? windowHeight - footerBot : 50;
	      $("#footer").css("height", newHeight);
	  }
  }
}



////////////////////////////////////////////////////////////////
// FEATURED RECIPE
////////////////////////////////////////////////////////////////

function slideSwitch() {
    var active = $('#featured-images img.active');
 
    // use this to pull the images in the order they appear in the markup
    var next =  active.next().length ? active.next()
        : $('#featured-images img:first'); 
 
    active.addClass('last-active');
 
    next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            active.removeClass('active last-active');
        });
        
        
        
    var activeText = $('.featured-content.active');
 
    // use this to pull the images in the order they appear in the markup
    var nextText =  activeText.next(".featured-content").length ? activeText.next()
        : $('.featured-content:first'); 
 
    activeText.addClass('last-active').fadeTo(1000, 0);
 
    nextText.addClass('active').fadeTo(1000, 1, function() {
            activeText.removeClass('active last-active');
        });
}
 
$(function() {
    setInterval( "slideSwitch()", 7000 );
});
