window.onload = function() {
	
	var el_left = (( $(window).width() - 960 ) / 2)+20;
	var nav = $('#nav');
	nav.css('left', el_left);
	
	
}

/*
$(document).ready(function(){
 
	$("#nav").hover(
	function() {
	$(this).stop().animate({"opacity": "1"}, "slow");
	},
	function() {
	$(this).stop().animate({"opacity": ".5"}, "slow");
	});
 
});
*/

$(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 BG = "url('images/trans.png')";
	var topmost_point = nav.offset().top;
    //var left_point = $('#container').offset().left;
    var left_point = (( $(window).width() - 960 ) / 2)+20;
    var PADDING_TOP = 40; // 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);
                var left_point = (( $(window).width() - 960 ) / 2)+20;
                nav.css('left', left_point);
            } else if (!NAV_IS_FIXED) {
            	var left_point = (( $(window).width() - 960 ) / 2)+20;
        	    nav.css({
                    left: left_point,
        	        top: PADDING_TOP,
        	        position: 'fixed'
        	    });
        	    NAV_IS_FIXED = true;
        	}
        } else {
            if (NAV_IS_FIXED) {
            	var left_point = (( $(window).width() - 960 ) / 2)+20;
                nav.css({
                    position: 'absolute',
                    top: topmost_point,
                    left: left_point
                });
                NAV_IS_FIXED = false;
            }
        }
	});
	
	the_window.resize(function () {
	   	//left_point = $('#container').offset().left;
	    var lefty = (( $(window).width() - 960 ) / 2)+20;
		nav.css('left', lefty);	 
	});
});
