/*  ------------------------------------------------------------------
    Browsers --------------------------------------------------------- */
    var isIE6 = false;
    var isIE7 = false;
    var isIE8 = false;
    if($.browser.msie && $.browser.version < 7){ var isIE6 = true; }
    if($.browser.msie && $.browser.version == 7){ var isIE7 = true; }
    if($.browser.msie && $.browser.version == 8){ var isIE8 = true; }
    
    
/*  ------------------------------------------------------------------
    Cookie Plugin ---------------------------------------------------- */
    jQuery.cookie = function(name, value, options) {
        if (typeof value != 'undefined') { // name and value given, set cookie
            options = options || {};
            if (value === null) {
                value = '';
                options.expires = -1;
            }
            var expires = '';
            if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
                var date;
                if (typeof options.expires == 'number') {
                    date = new Date();
                    date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
                } else {
                    date = options.expires;
                }
                expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
            }
            // CAUTION: Needed to parenthesize options.path and options.domain
            // in the following expressions, otherwise they evaluate to undefined
            // in the packed version for some reason...
            var path = options.path ? '; path=' + (options.path) : '';
            var domain = options.domain ? '; domain=' + (options.domain) : '';
            var secure = options.secure ? '; secure' : '';
            document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
        } else { // only name given, get cookie
            var cookieValue = null;
            if (document.cookie && document.cookie != '') {
                var cookies = document.cookie.split(';');
                for (var i = 0; i < cookies.length; i++) {
                    var cookie = jQuery.trim(cookies[i]);
                    // Does this cookie string begin with the name we want?
                    if (cookie.substring(0, name.length + 1) == (name + '=')) {
                        cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                        break;
                    }
                }
            }
            return cookieValue;
        }
    };
    
    
$(document).ready(function(){

/*  ------------------------------------------------------------------
    Tracking --------------------------------------------------------- */
    $('.b_save-cp').click(function(e){
        e.preventDefault();
        trackOutboudLinks(this, 'Quiz Results Page', 'Save Profile', null);
    });
    
    $('.b_shoponline', '.result-content-blends').click(function(e){
        e.preventDefault();
        trackOutboudLinks(this, 'Quiz Results Page', 'Shop button', null);
    });
    
    
/*  ------------------------------------------------------------------
    External Link ---------------------------------------------------- */
    var allowedDomains = [location.hostname];
    $("a[href^=http]:not(.internal)")
    .filter(function(el){
        for ( var i=0; i < allowedDomains.length; i++ ) {
            if ( this.href.indexOf(allowedDomains[i])>-1 ) return false;
        }
        return true;
    })
    .bind("click", function(){ $(this).attr("target", "_blank"); });


/*  ------------------------------------------------------------------
    Placeholder (dont forget clearPlaceholder fct) ------------------- */
    if(!Modernizr.input.placeholder){
        $("input[placeholder]")
        .each(function(){
            if(this.value=="" || this.value==$(this).attr("placeholder")){
                $(this).val($(this).attr("placeholder")).addClass("placeholder");
            }
        })
        .bind("focus",function(){ if(this.value==$(this).attr("placeholder")){ $(this).val("").removeClass("placeholder"); } })
        .bind("blur",function(){ if(this.value==""){ $(this).val($(this).attr("placeholder")).addClass("placeholder"); } });
    }


/*  ------------------------------------------------------------------
    Autofocus -------------------------------------------------------- */
    if(!Modernizr.input.autofocus){
        $("input[autofocus]").focus();
    }
    

/*  ------------------------------------------------------------------
    Textarea Maxlength ----------------------------------------------- */
    $obj = document.createElement("textarea");
    supportTextareaMaxlength = (!!($obj.maxLength === -1) || !!($obj.maxLength === 524288)) && !!($obj.maxLength !== undefined); //webkit sets default maxlength to 524288, gecko and presto to -1
    
    if(!supportTextareaMaxlength){
        $("textarea[maxlength]").keyup(function(){
            var maxLength     = $(this).attr("maxlength");
            var currentLength = this.value.length;
            if(currentLength >= maxLength) {
                 this.value = this.value.substring(0, maxLength);
            }
        });
    }
    

/*  ------------------------------------------------------------------
    Coffee Nav ------------------------------------------------------- */
    if(!isIE6){
        $(".m1", "header.main")
        .bind("mouseenter", function(e){
            var x = e.pageX - this.offsetLeft;
            var y = e.pageY - this.offsetTop;
            y = y - 15;
            x = y * 2 * -1;    
            position = x + 'px '+ y + 'px';
            $(this).stop().animate({backgroundPosition: position}, 300, 'easeOutExpo', function(){                                             
                $(this).bind("mousemove", function(e){
                    x = e.pageX - this.offsetLeft;
                    y = e.pageY - this.offsetTop;
                    y = y - 15;
                    x = y * 2 * -1;    
                    position = x + 'px '+ y + 'px';
                    $(this).stop().css("background-position", x + 'px '+ y + 'px');
                });    
            });
        }).bind("mouseleave", function(e){
            y = e.pageY - this.offsetTop;
            y = y - 15;
            position = y + 'px';
            
            if(y > 50){ speed=500; }else{ speed=750; }
            
            $(this).unbind("mousemove");
            $(this).animate({backgroundPosition: '-200px 135px'}, speed, 'easeInOutQuad');
        });
    }


/*  ------------------------------------------------------------------
    Language Dropdown ------------------------------------------------ */
    $.fn.dropdown = function(options) {
        return this.each(function() {
            var $btn = $(this);
            
            $btn.bind("click", function(e){ /* Open/Close the dropdown */
                $btn.toggleClass("selected");
                $btn.siblings(".dd_options:first").toggle();
                e.stopPropagation();
                return false;
            });
            $(document).bind("click", function(){ /* Close the dropdown when clicking outside */
                $btn.removeClass("selected");
                $btn.siblings(".dd_options:first").hide();
            });
            $btn.siblings(".dd_options:first").bind("click", function(e){ /* Stop propagation of click in dropdown */
                e.stopPropagation();
            });
        });  
    };
    $("#b_changelanguage").dropdown();
    
    
/*  ------------------------------------------------------------------
    Popins ----------------------------------------------------------- */
    $.extend($.modal.defaults, {
        opacity: 50,
        overlayClose: true,
        focus: false,
        onOpen: function (dialog) {
            dialog.overlay.fadeIn('fast', function () {
                dialog.data.hide();
                dialog.container.fadeIn('fast');
                dialog.data.fadeIn('fast');
            });
        },
        onClose: function (dialog) {
            dialog.data.fadeOut('fast');
            dialog.container.fadeOut('fast', function () {
                dialog.overlay.fadeOut('fast', function(){$.modal.close(); });
            });
        }
    });
    
    
/*  ------------------------------------------------------------------
    Youtube ---------------------------------------------------------- */
    $("a[href^='http://www.youtube.com/watch']").bind("click", function(){
        yt_url     = $(this).attr("href");
        yt_id      = gup('v', yt_url);    
        yt_size    = $(this).attr("rel");
        if(yt_size){
            yt_size    = yt_size.split(":");
            yt_width   = yt_size[0];
            yt_height  = yt_size[1];
        }else{
            yt_width   = 640;
            yt_height  = 385;    
        }
        
        marginleft = "-" + (yt_width/2);
        yt_embed   = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+yt_width+'" height="'+yt_height+'"><param name="wmode" value="opaque" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://www.youtube.com/v/'+ yt_id +'" /><embed src="http://www.youtube.com/v/'+ yt_id +'" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="'+yt_width+'" height="'+yt_height+'" wmode="opaque"></embed></object>';

        popin_start = createPopin("auto", "generic", "start", marginleft);    
        popin_end   = createPopin("auto", "generic", "end", "");

        $.modal(popin_start + yt_embed + popin_end);
        
        return false;
    });
    
    
/*  ------------------------------------------------------------------
    Popup ------------------------------------------------------------ */
    $("a[rel^='popup']").unbind("click").bind("click", function(){
        size = $(this).attr("rel");
        size = size.split("-");
        size = size[1].split("x");
        w    = size[0];
        h    = size[1];
        window.open(this.href, "", "width="+w+", height="+h+", resizable=yes, scrollbars=yes, titlebar=yes, toolbar=no, menubar=no");
        return false;
    });


/*  ------------------------------------------------------------------
    Quick Cart ------------------------------------------------------- */
    $('#quick-cart-container').hide();
    
        $('#quick-cart a.quick-cart-button').bind({
          click: function() {
            if(!$('.quick-cart-button').hasClass('expanded')){
            
                if(!$('#quick-cart-container').hasClass('loaded'))
                {
                    $('#quick-cart-container').load("/" + _siteAccess + "/checkout/cart-quickview", function() {
                        $('#quick-cart-container').addClass('loaded');
                        $('#quick-cart-close').bind({
                              click: function() {
                                $('#quick-cart-container').fadeOut();
                                $('#quick-cart a.quick-cart-button').removeClass('expanded');
                                return false;
                                }
                            });
                        if(!isIE8){
                            $('#quick-cart-container').fadeIn();
                        }
                        else
                        {
                            $('#quick-cart-container').show();
                        }
                        $('#quick-cart a.quick-cart-button').addClass('expanded');
                        
                        $('.quick-cart-delete').bind({
                              click: function() {
                                    $.get($(this).attr('href') + "/(no_return)/true", function(data) {
                                        $('#quick-cart-container').removeClass('loaded');
                                        $('#quick-cart a.quick-cart-button').click();
                                    });
                                return false;
                                }
                            });
                    });
                }else{
                    if(!isIE8){
                        $('#quick-cart-container').fadeIn();
                    }
                    else
                    {
                        $('#quick-cart-container').show();
                    }
                    $('#quick-cart a.quick-cart-button').addClass('expanded');
                }
            }else{
                $(this).removeClass('expanded')
                    if(!isIE8){
                        $('#quick-cart-container').fadeOut();
                    }
                    else
                    {
                        $('#quick-cart-container').hide();
                    }
                return false;
            }
            return false;
            }
        });
        
        $('html').click(function() {
            $('#quick-cart a.quick-cart-button').removeClass('expanded')
            if(!isIE8){
                        $('#quick-cart-container').fadeOut();
                    }
                    else
                    {
                        $('#quick-cart-container').hide();
                    }
        });
        $('#quick-cart-container').click(function(event){
            event.stopPropagation();
        });
        
        
/*  ------------------------------------------------------------------
    Toggle Content beginning ----------------------------------------- */
    $('li.product_group').parents('li').addClass('hasSubmenu');
    
    var cookieValue = $.cookie("menu_expanded");
    $('a.toggle').bind('click', toggleContent);
    $('ul.itemContent li a').bind('click', setCookie);
    $("ul.itemContent").css('display','none');
    if(cookieValue == null){
        $("ul.itemContent").css('display','none');
    } else {
        $("li#"+cookieValue).children("ul.itemContent").css('display','block');
        $("li#"+cookieValue).attr("id", cookieValue).find("a.toggle").addClass('expanded');
    }

    /*2.4 carousel*/
    $('#car_1').jcarousel({     
        animation:400,
        auto: 6.5,
        vertical: true,
        wrap:'last',
        scroll: 1,
        initCallback: car1_initCallback,
        buttonNextHTML: null,
        buttonPrevHTML: null,
        itemVisibleInCallback:  highlight,
        itemVisibleOutCallback: removehighlight
    });

    $('.b2b section').equalizer();
    
    
    /* MMR - Quiz Results - Email Coffee Profile */
    if($('#frm_emailCP').length > 0) {
        $('#frm_emailCP').validate({
            submitHandler: function(form) {
                if(!Modernizr.input.placeholder){
                    clearPlaceholder($(form));
                }
                
                if(!$('input[type="submit"]').attr('disabled')) { // Prevent submitting the form multiple times
                    $.ajax({
                        url: $(form).attr('action'),
                        data: $(form).serialize() + '&ajax=1',
                        dataType: 'json',
                        type: 'post',
                        success: function(data){
                            $(form).fadeOut('fast', function(){ $('#emailCP_success').fadeIn(); });
                            if($('input[name="optin"]:checked').length > 0) {
                                _gaq.push(['_trackEvent', 'Quiz Results Page', 'Email Coffee Profile', 'Subscribed']);
                            }else {
                                _gaq.push(['_trackEvent', 'Quiz Results Page', 'Email Coffee Profile', 'Not subscribed']);
                            }
                        },
                        error: function(jqXHR, textStatus, errorThrown){
                            $('input[type="submit"]').attr('disabled', false);
                            //console.log('jqXHR:' + jqXHR + ' | ' + 'textStatus: ' + textStatus +' | ' + 'errorThrown: ' + errorThrown);
                        }
                    });
                }
                $('input[type="submit"]').attr('disabled', true); // Prevent submitting the form multiple times
            }
        });
    }
    
});/*End Ready function*/


/*  -------------------------------------------------------------------
    Toggle Content end ------------------------------------------------ */

    var setCookie = function(){
        var menuId = $(this).parents("li.product_group").attr("id");
        var index = menuId;
        $.cookie("menu_expanded", index, { path: '/' });
        console.log($.cookie("menu_expanded"));
    };

    var toggleContent = function(e) {
        var targetContent = $('ul.itemContent', this.parentNode.parentNode);
        if (targetContent.css('display') == 'none') {
            targetContent.slideDown(300);
            $(this).addClass('expanded');
        } else {
            targetContent.slideUp(300);
            $(this).removeClass('expanded');
        }
        return false;
    };
    
    
/*  ------------------------------------------------------------------
    Carousels -------------------------------------------------------- */
    function car1_initCallback(carousel) {
        jQuery('.slider_tabs6 a').bind('click', function() {
            carousel.scroll(jQuery.jcarousel.intval(jQuery(this).attr('rel')));
            return false;
        });
    };
    
    function highlight(carousel, item, idx, state){
             jQuery('.slider_tabs ul li:nth-child('+ idx +')').attr("class","active");
             jQuery('.slider_tabs6 ul li:nth-child('+ idx +')').attr("class","active");
        };
    function removehighlight(carousel, item, idx, state){
             jQuery('.slider_tabs ul li:nth-child('+ idx +')').removeAttr("class","active");
             jQuery('.slider_tabs6 ul li:nth-child('+ idx +')').removeAttr("class","active");
    };
    function highlight2(carousel, item, idx, state){
             jQuery('.slider_tabs7 ul li:nth-child('+ idx +')').attr("class","active");
        };
    function removehighlight2(carousel, item, idx, state){
             jQuery('.slider_tabs7 ul li:nth-child('+ idx +')').removeAttr("class","active");
    };
    function slider1_initCallback(carousel) {
        jQuery('.slider_tabs1 ul li a').bind('click', function() {
            carousel.scroll(jQuery.jcarousel.intval(jQuery(this).attr('rel')));
            return false;
        });
        jQuery('.slider_tabs1 a.b_next').bind('click', function() {
            carousel.next();
            return false;
        });
        jQuery('.slider_tabs1 a.b_prev').bind('click', function() {
            carousel.prev();
                return false;
        });    
        
    };
    function slider2_initCallback(carousel) {
        jQuery('.slider_tabs2 ul li a').bind('click', function() {
            carousel.scroll(jQuery.jcarousel.intval(jQuery(this).attr('rel')));
            return false;
        });
        jQuery('.slider_tabs2 a.b_next').bind('click', function() {
            carousel.next();
            return false;
        });
        jQuery('.slider_tabs2 a.b_prev').bind('click', function() {
            carousel.prev();
            return false;
        });    
    };
    function slider3_initCallback(carousel) {
        jQuery('.slider_tabs3 ul li a').bind('click', function() {
            carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
            return false;
        });
        jQuery('.slider_tabs3 a.b_next1').bind('click', function() {
            carousel.next();
            return false;
        });
        jQuery('.slider_tabs3 a.b_prev1').bind('click', function() {
            carousel.prev();
            return false;
        });
    };
    function slider4_initCallback(carousel) {
        jQuery('.slider_tabs4 ul li a').bind('click', function() {
            carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
            return false;
        });
        jQuery('.slider_tabs4 a.b_next1').bind('click', function() {
            carousel.next();
            return false;
        });
        jQuery('.slider_tabs4 a.b_prev1').bind('click', function() {
            carousel.prev();
            return false;
        });
        
        jQuery('.product_format a').bind('click', function() {
            
            var obj_id = $(".sizes_" + $(this).attr('rel') + " input:radio:first").val();
            carousel.scroll( parseInt($('li .img_' + obj_id).parent().attr('jcarouselindex')) );
        
            return false;
        });        
    };
    function slider5_initCallback(carousel) {
        jQuery('.slider_tabs5 ul li a').bind('click', function() {
            carousel.scroll(jQuery.jcarousel.intval(jQuery(this).attr('rel')));
            return false;
        });
        jQuery('.slider_tabs5 a.b_next').bind('click', function() {
            carousel.next();
            return false;
        });
        jQuery('.slider_tabs5 a.b_prev').bind('click', function() {
            carousel.prev();
                return false;
        }); 
    };
    function slider7_initCallback(carousel) {
        jQuery('.slider_tabs7 ul li a').bind('click', function() {
            carousel.scroll(jQuery.jcarousel.intval(jQuery(this).attr('rel')));
            return false;
        });
        jQuery('.slider_tabs7 a.b_next').bind('click', function() {
            carousel.next();
            return false;
        });
        jQuery('.slider_tabs7 a.b_prev').bind('click', function() {
            carousel.prev();
            return false;
        }); 
    };
/*  ------------------------------------------------------------------
    eMagazine -------------------------------------------------------- */
    function eMagazine(){
        $('.emag-breadcrumb ul li:last-child').addClass('last');
        $('.social-container li:last-child').addClass('last');
        $('.emagazine .posts-category-listing-container .post-listing article:nth-child(3n)').addClass('last');
        /*Category nav*/
        $('.emagazine-category ul li:even').addClass('even');
        
        /*Image Gallery*/
        var fullHtml = $('#block-01').html();
        var thumbHtml = $('#block-02').html();
        
        $('#block-01').find('.i_play').hide();
        $('#block-02, #block-03').find('iframe').hide();
        $('#block-02, #block-03').find('img.hide').addClass('yt-thumb').removeClass('hide');
        
        $('#block-02, #block-03').bind('click', function(){
            fullHtml = $('#block-01').html();
            thumbHtml = $(this).html();
            $(this).html(fullHtml);
            $(this).find('iframe').hide();
            $(this).find('img.hide').addClass('yt-thumb').removeClass('hide');
            $(this).find('.i_play').show();
            $('#block-01').html(thumbHtml);
            swapYt();
            return false;
        });
        /*Show/hide the thumbnail of a youtube video*/
        function swapYt(){
            $('#block-01').find('img.yt-thumb').addClass('hide').removeClass('yt-thumb');
            $('#block-01').find('.i_play').hide();
            $('#block-01').find('iframe').show();
        }

    }

/*  ------------------------------------------------------------------
    Create Popins ---------------------------------------------------- */
    function createPopin(size, style, portion, marginleft){
        size  = size  ? size  : "medium"; /* options: tiny, small, medium, large, xlarge, full */
        style = style ? style : "generic"; /* options:  */
        if(marginleft!=""){ marginleft = "margin-left:"+ marginleft + "px"; }
        else{ marginleft =""; }
        
        popin = '';
        if(portion=="start"){
            popin += '<div class="pi pi_'+style+' pi_'+size+'" style="'+marginleft+';">';
            popin += '    <a href="javascript:;" onclick="$.modal.close();" class="b1 b_close">X</a>';
            popin += '    <div class="pi_content">';
        }else{
            popin += '    </div>';
            popin += '</div>';
        }
        return popin;
    }


/*  ------------------------------------------------------------------
    Clear All Placeholder that are Value ----------------------------- */
    function clearPlaceholder(form){
        $("input[placeholder]", $(form)).each(function(){
            if(this.value==$(this).attr("placeholder")){
                $(this).val("");
            }                                                
        });
    }
    
    
/*  ------------------------------------------------------------------
    Google Map ------------------------------------------------------- */
    function eZGmapLocation_MapView( attributeId, latitude, longitude ){
        if (GBrowserIsCompatible()) {
            if(latitude && longitude){
                var startPoint = new GLatLng( latitude, longitude ), zoom = 13;
            }else{
                var startPoint = new GLatLng( 0, 0 ), zoom = 0;
            }
            var map = new GMap2( document.getElementById('gmap' + attributeId));
            map.addControl(new GSmallMapControl());
            map.setCenter(startPoint, zoom );
            map.addOverlay(new GMarker(startPoint));
        }
    }


/*  ------------------------------------------------------------------
    Get parameter from URL ------------------------------------------- */
    function gup(name, url){
        name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
        var regexS  = "[\\?&]"+name+"=([^&#]*)";
        var regex   = new RegExp(regexS);
        var results = regex.exec(url);
        return (results==null ) ? "" : results[1];
    }


/*  ------------------------------------------------------------------
    MY MASTER ROSTER FUNCTIONS --------------------------------------- */
    $(function vhCofProf(){
        /*Background stretcher/slider*/
        $('.bg_discovery_quiz #content').bgStretcher({
            images: ['/extension/vanhoutte/design/vanhoutte/images/mmr/bg_fs_quiz-1.jpg',
            '/extension/vanhoutte/design/vanhoutte/images/mmr/bg_fs_quiz-2.jpg',
            '/extension/vanhoutte/design/vanhoutte/images/mmr/bg_fs_quiz-3.jpg',
            '/extension/vanhoutte/design/vanhoutte/images/mmr/bg_fs_quiz-4.jpg',
            '/extension/vanhoutte/design/vanhoutte/images/mmr/bg_fs_quiz-5.jpg',
            '/extension/vanhoutte/design/vanhoutte/images/mmr/bg_fs_quiz-6.jpg'],
            imageWidth: 1600,
            imageHeight: 1000,
            slideShow: false,
            nextSlideDelay: 1000,
            buttonPrev: "#b_previous",
            buttonNext: "#b_next"
        });
        $('.bg_mmr_landing_page #content').bgStretcher({
            images: ['/extension/vanhoutte/design/vanhoutte/images/mmr/bg_fs_home.jpg'],
            imageWidth: 1600,
            imageHeight: 1000,
            slideShow: false
        });
        $('.bg_discovery_quiz_intro #content').bgStretcher({
            images: ['/extension/vanhoutte/design/vanhoutte/images/mmr/bg_fs_quiz-intro.jpg'],
            imageWidth: 1600,
            imageHeight: 1000,
            slideShow: false
        });
        $('.bg_discovery_quiz_result #content').bgStretcher({
            images: ['/extension/vanhoutte/design/vanhoutte/images/mmr/bg_fs_quiz-result.jpg'],
            imageWidth: 1600,
            imageHeight: 1000,
            slideShow: false
        });
        $('.bg_collections_page #content').bgStretcher({
            images: ['/extension/vanhoutte/design/vanhoutte/images/mmr/collection.jpg'],
            imageWidth: 1500,
            imageHeight: 1000,
            slideShow: false
        });
        $('.bg_mmr_expertise_page #content').bgStretcher({
            images: ['/extension/vanhoutte/design/vanhoutte/images/mmr/bg_wood_01.jpg'],
            slideShow: false
        });
        
        /*2.2 MRE & Collection*/
        if (typeof(imgPath) != "undefined"){
            $('.bg_collections_page_detail #content').bgStretcher({
                images: [imgPath],
                imageWidth: 1500,
                imageHeight: 1500,
                slideShow: false
            });
        }else{
            $('.bg_collections_page_detail #content').bgStretcher({
                images: ['/extension/vanhoutte/design/vanhoutte/images/mmr/collection.jpg'],
                slideShow: false
            });
        };
        
        $(".mmr-container-02 .columns-container").columnize({ columns: 2 });;
        /*/2.2 MRE & Collection*/
    
        $('#container').bgStretcher.pause();
        /*Slider du questionnaire*/
        $('#slider6').jcarousel({
            animation:400,
            scroll: 1,
            setupCallback: showSliderItem(),
            initCallback: slider6_initCallback,
            buttonNextHTML: null,
            buttonPrevHTML: null,
            size:6,
            itemLastOutCallback: {
               onAfterAnimation: disableCustomButtons
            },
            itemLastInCallback: {
               onAfterAnimation: disableCustomButtons
            }
        });
        
        $('.quiz-container').prepend('<span class="quiz-container-top"></span>').append('<span class="quiz-container-bot"></span>');
        $('.quiz-result-container').prepend('<span class="quiz-container-top"></span>').append('<span class="quiz-container-bot"></span>');
        $('.ctas-container').prepend('<span class="ctas-container-top"></span>').append('<span class="ctas-container-bot"></span>');
        $('.quiz-intro-container').prepend('<span class="quiz-intro-container-top"></span>').append('<span class="quiz-intro-container-bot"></span>');
        
        $('.mmr-container-01').prepend('<span class="container-top"></span>').append('<span class="container-bot"></span>');
        $('.mmr-container-02').prepend('<span class="container-top"></span>').append('<span class="container-bot"></span>');
        $('.mmr-container-03').prepend('<span class="container-top"></span>').append('<span class="container-bot"></span>');
        
        
        $('.b_mmr-b').prepend('<span class="b_mmr-left"></span>').append('<span class="b_mmr-right"></span>');
        $('.b_mmr-w').prepend('<span class="b_mmr-left"></span>').append('<span class="b_mmr-right"></span>');
        $('.b_mmr-w-s').prepend('<span class="b_mmr-left"></span>').append('<span class="b_mmr-right"></span>');
        $('.b_mmr-be').prepend('<span class="b_mmr-left"></span>').append('<span class="b_mmr-right"></span>');
        
        $('.blog-related-container .blog-article:last-child').addClass('last');
        $('.cof_prof-container .ctas-container .mmr-cta:last-child').addClass('last');
        $('.other_coffee_collections ul li:last-child').addClass('last');
        
        
        var pageH = $(".bgstretcher-page").height();
        $("#bgstretcher").delay(3000).height(pageH+60);
        $('#frm-coffee-quiz label').click(function(){
            var currentValue = $(this).find('input:radio').attr('value');
            $(this).find('input:radio').attr("checked", "checked");/*Check the radio button*/
            $(this).removeClass("down").addClass("up");/*Add opacity class*/
            $(this).parents('.quiz-question').find('input:radio').not('[value="'+currentValue+'"]').parents("label").removeClass("up").addClass("down");/*Check for not clicked and add opacity class*/
            $(this).parents('.quiz-question').find('.log').html( $(this).find(":checked").val() + " is checked!" );/*Log the answer*/
    
            carousel = $('#slider6').data('jcarousel');
            if (carousel.last == carousel.size()) {
                $('#b_final').fadeIn(300);
            } else {
                $('#b_next').fadeIn(300);
            }
        });
        $('#frm-coffee-quiz label').find('input:radio').removeAttr("checked");
        $('.quiz-container').find('input:radio').addClass('visuallyhidden');
        
        $('#frm-coffee-quiz label').mouseover(function() {
            $(this).addClass("mid");
        }).mouseout(function(){
            $(this).removeClass("mid");
        });
    
    
        $('#slider-blends').jcarousel({
            animation:400,
            scroll: 1,
            wrap: "both",
            initCallback: sliderBlends_initCallBack,
            setupCallback: showSliderItem(),
            // This tells jCarousel NOT to autobuild prev/next buttons
            buttonNextHTML: null,
            buttonPrevHTML: null
        });
        $('#slider-profiles').jcarousel({
            animation:400,
            scroll: 1,
            wrap: "both",
            initCallback: sliderOthers_initCallBack,
            setupCallback: showSliderItem(),
            // This tells jCarousel NOT to autobuild prev/next buttons
            buttonNextHTML: null,
            buttonPrevHTML: null
        });
        $('.cycle-plain').cycle({
            fx: 'fade',
            timeout:  3500,
            speed: 600
        });
    
    });

    function showSliderItem(){
        $('.quiz-question').css('display', 'block');
        $('#slider-blends li').css('display', 'block');
        $('#slider-profiles li').css('display', 'block');
    };
    
    function slider6_initCallback(carousel) {
    
        $('#b_previous').bind('click', function() {
            carprev(carousel);
            return false;
        }); 
        $('#b_next').bind('click', function() {
            var NextSlide = $('.quiz-question:eq(' + carousel.last + ')');
            if (carousel.last == carousel.size() -1){
                if($('.quiz-question:eq(' + carousel.last + ')').children('label:first').is('.up, .down')){
                    $('#b_final').fadeIn(300);
                }else{
                }
                $(this).hide();         
            }else if ( $('.quiz-question:eq(' + carousel.last + ')').children('label:first').is('.up, .down') ) {
            }else{
                $(this).hide();
            }
            carnext(carousel);
            return false;
        }); 
    };
    var currentQuestion = $('#quiz-current-question').html();
    function carnext(carousel){
        carousel.next();
        $('#quiz-current-question').html(carousel.last);
    };
    function carprev(carousel){
        carousel.prev();
        $('#quiz-current-question').html(carousel.last);
        $('#b_next').fadeIn();
    };
    function disableCustomButtons(carousel){
        var prev_class = 'jcarousel-prev-disabled';
        if (carousel.first == 1) {
            $('#b_previous').hide();
        } else {
            $('#b_previous').fadeIn();
        }
        var next_class = 'jcarousel-next-disabled';
        if (carousel.last == carousel.size()) {
        } else {
            $('#b_final').hide();
        }
    };
    
    function sliderBlends_initCallBack(carousel){
        $('#b_previous_blends').bind('click', function() {
            carousel.prev();
            return false;
        });
        $('#b_next_blends').bind('click', function() {
            carousel.next();
            return false;
        });
        $(".openSlide_collection").bind("click", function(){
            var currentDescription = $(".jcarousel-skin-blends .jcarousel-item-" + carousel.last + " .cf-hidden-content").html();
            
            popin_content = "<span class='mmr-pi-content clearfix'>" + currentDescription + "</span>";
            popin_start   = createPopin("medium", "generic", "start", "");  
            popin_end     = createPopin("medium", "generic", "end", "");
            $.modal(popin_start + popin_content + popin_end);
            
            return false;
        });
    };
    function sliderOthers_initCallBack(carousel){
        $('#b_previous_other').bind('click', function() {
            carousel.prev();
            return false;
        });
        $('#b_next_other').bind('click', function() {
            carousel.next();
            return false;
        });
    
        $("#openSlide, .jcarousel-skin-other li a").bind("click", function(){
            var currentDescription = $(".jcarousel-skin-other .jcarousel-item-" + carousel.last).html();
            
            popin_content = "<span class='mmr-pi-content clearfix'>" + currentDescription + "</span>";
            popin_start   = createPopin("medium", "generic", "start", "");  
            popin_end     = createPopin("medium", "generic", "end", "");
            $.modal(popin_start + popin_content + popin_end);
            
            return false;
        });
    };


/*  ------------------------------------------------------------------
    Tracking events on outbound links -------------------------------- */
    function trackOutboudLinks(link, category, action, label) {
        try {
            var myTracker=_gat._getTrackerByName();
            _gaq.push(['myTracker._trackEvent', category, action, label]);
            setTimeout('document.location = "' + link.href + '"', 100)
        }catch(err){}
    }

