$(function() {
    $(".ratingSourceAbbr").tipTip();
});

(function($){
	$.fn.clearDefault = function(){
		return this.each(function(){
			var default_value = $(this).val();
			$(this).addClass("placeholder");
			$(this).focus(function(){
				if ($(this).val() == default_value) $(this).val("").removeClass("placeholder");
			});
			$(this).blur(function(){
				if ($(this).val() == "") $(this).val(default_value).addClass("placeholder");
			});
		});
	};
})(jQuery);


$(document).ready(function() {
// Form placeholders
$('.search input[type=text], .emailSignup input[type=email], .newsletterSignup input[type=email]').each(function(i) {
	$(this).clearDefault();
});


// Footer rotation
    $('.industryExperts').cycle({
        fx: 'fade'
    });
    
    
// For home page rotation

    $("body.home div.homeFeaturedProduct").each(function(i) {
        if (i < 2) {
            $(this).find("p").removeAttr("style");
            if ($(this).find(".retailPrice .price").text() != $(this).find(".mainPrice .price").text()) {
            	$(this).find(".retailPrice").removeAttr("style");
            	$(this).find(".mainPrice").removeClass("mainPrice").addClass("salePrice");
            }
            $(this).find(".featuredDescription").removeAttr("style");
            $(this).find(".ratingSourceAbbr").hide();
            $("div.featuredItem").append($(this));
        }
        else {
            $("div.nlitemlist").append($(this));
            $(this).find(".pricingContainer").addClass("homeSalePrice");
        }

        if (i == 1) {
            $(this).addClass("secondFeature");
        }

        if ($(this).find(".points").text() == "") {
            $(this).find(".rating").hide();
            $(this).find(".ratingSourceAbbr").hide();
        }
    });
    $("body.home div.nlitemlist table").remove();
    
   
    $('.featuredItem').before('<div id="featuredNav">').cycle({
        fx: 'fade',
        speed: 'slow',
        timeout: 5500,
        pager: '#featuredNav',
        fit: 1,
        height: 218,
        width: 721,
        containerResize: 0
    });

// For sticky header login links
    var isLogInInfo = $("#isLogInInfo a").html();
    if (isLogInInfo == 'Sign&nbsp;Out') {
        $('#myAccountLink').css('display', 'inline');
        $('#logOutLink').css('display', 'inline');
        $('.cart').css('min-width','375px');
        $('#registerLink').css('display', 'none');
        $('#loginLink').css('display', 'none');
    }
    
// Fixes styling issues on Sales Orders and Case pages (my account)
	var header = $(".whyWotW").html();
	if (header == null) {
		$("#innerwrapper").css("background","#fffdf1");
	}
    
// Removes ".00" from pricing
    $(".pricing .price").each(function(i) {
        var price = $(this).html();
        cents = price.substr(price.length - 3);
        if (cents == ".00") {
            price = price.substr(0, price.length - 3);
        }
        $(this).html(price);
    });

// Stylizing shopping cart 

    $("#carttable tr[id^='carttablerow']:even").addClass("even");
    $(".Checkout table table table table table table table tr:even").addClass("even");

    $("#carttable tr[id^='carttablerow']").addClass("checkoutItem");
   	
// Stylizing left nav

    $(".allWinesNav td[colspan='10']").addClass("mainTab");

    $(".allWinesNav table td").each(function(i) {
        var siblings = $(this).siblings().length;
        var colspan = $(this).attr("colspan");
        if (siblings == 1) {
            $(this).addClass("mainTab");
        }
    });
    
   
//Testimonials Randomization

	var items = $(".testimonial li");
	var item = Math.floor(Math.random() * items.length);
	$(items[item]).addClass("active");
	
// Search Results

$("body.home table.productListing").parent().prepend("<h1 class='searchHeader'>Search Results</h1>");

//Read More Popups
$("#readMoreContent").hide();
$("a#seoReadMore").click(function() {
	$("#readMoreContent").slideToggle();
});

});
