﻿var currentNavOn = null;

function deactivate() {
    // turn off highlighted bottles
    $("a.bottle-active").css({'background-position' : ''});
    $("a.bottle-active").removeClass("bottle-active").addClass("bottle");
    // turn off gray background of bottles
    $(".wine-landing-bottle-back-active").removeClass("wine-landing-bottle-back-active").addClass("wine-landing-bottle-back");
}

function activate(obj) {
    // turn on highlighted bottles
    $(obj).removeClass("bottle").addClass("bottle-active");
    $($(obj).parent()).removeClass("wine-landing-bottle-back").addClass("wine-landing-bottle-back-active");

    if (currentNavOn != null) {
        $(currentNavOn).removeClass("active");
    }
    var brandId = $(obj).attr('rel');
    $("#brand-" + brandId + " a").addClass("active");
    currentNavOn = $("#brand-" + brandId + " a");
    
 }

 function setRollovers() {
     $(".lrg-bottles a").each(function() {
         $(this).hover(
                function() {
                    $(this).stop(true);
                    $(this).animate({ top: '-=8' }, 300);
                },
                function() {
                    $(this).stop(true);
                    $(this).animate({ top: "0px" }, 300);
                }
            );
     });
 }

 $(document).ready(function() {
     // init first item
     activate($("#win_0 a.[class*=bottle]"));
        
    

     $("a.[class*=bottle]").each(function() {
         $(this).click(function() {
             deactivate();
             activate(this);

             var brandId = $(this).attr('rel');
             
             $.get("/wine/get/" + brandId, function(data) {
                 $('#landing-content-top').animate({
                     opacity: 0.0
                 }, 300, function() {
                     $("#landing-content-top").empty().append(data);
                     setRollovers();
                     $('#wine-landing-about h3').animate({
                         opacity: 0.0
                     }, 300, function() {
                         $("#wine-landing-about h3").empty().append($("#wine-landing-about2 h3").html());
                         $('#wine-landing-about h3').animate({
                             opacity: 1.0
                         }, 300);
                     });

                     $('#wine-landing-about #content').animate({
                         opacity: 0.0
                     }, 300, function() {
                         $("#wine-landing-about #content").empty().append($("#wine-landing-about2 #content").html());
                         $('#wine-landing-about #content').animate({
                             opacity: 1.0
                         }, 300);
                     });                     

                     $('#large-bottles').jcarousel({
                         scroll: 4,
                         animation: 1000
                     });
                     $('#landing-content-top').animate({
                         opacity: 1.0
                     }, 300);
                 });
             });

             return false;
         });
     });


     setRollovers();

     $('.wine-landing-bottles-container a').each(function() {
         $(this).hover(
            function() {
                $(this).css("background-position", "-74px 0");
                $($(this).parent()).removeClass("wine-landing-bottle-back").addClass("wine-landing-bottle-back-active");
            },
            function() {
                if ($(this).attr('class') != "bottle-active") {
                    $(this).css("background-position", "0 0");
                    $($(this).parent()).removeClass("wine-landing-bottle-back-active").addClass("wine-landing-bottle-back");
                }
            }
        );
     });


     $('#large-bottles').jcarousel({
         scroll: 4,
         animation: 1000
     });
     $('#small-bottles').jcarousel({
         scroll: 9,
         animation: 1000
     });

 });
