$(function() {
		$("a.mapmask").mouseover(
			function() {
				$(this).stop().animate({backgroundColor: '#060606'}, 200);
			});
		$("a.mapmask").mouseout(	
			function() {
				$(this).stop().animate({backgroundColor: '#2d2d2d'}, 200);
			});
	});


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 () {
    $('#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}, 2000);
            return false;
		}
	});
});

$(function () {
    $('#nav_top 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}, 2000);
            return false;
		}
	});
	
	
	
    // 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'});
	var nav_top = $('#nav_top');
	nav_top.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 = 20; // 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: '20px',
        	        position: 'fixed'
        	    });
        	    NAV_IS_FIXED = true;
        	}
        } /*else {
            if (NAV_IS_FIXED) {
                nav.css({
                    position: 'absolute',
                    top: '',
                    left: ''
                });
                NAV_IS_FIXED = false;
            }
        }*/
	});

	the_window.resize(function () {
	    left_point = $('#container').offset().left;
	    if (NAV_IS_FIXED) {
    	    nav.css('left', left_point);	        
	    }
	});

	/*
	 *     TOP_MENU NAVBAR
	 */
	var topmost_point_top = nav_top.offset().top;
    var left_point_top = $('#title').offset().left;
	var PADDING_TOP = 0; // MAGIC NUMBER
	var REAL_TOP = topmost_point_top - PADDING_TOP;
	var the_window = $(window);
	var NAV_TOP_IS_FIXED = (nav_top.css('position') == 'fixed');
	the_window.scroll(function () {
        if (the_window.scrollTop() > REAL_TOP) {
            if ($.browser.msie && $.browser.version == "6.0") {
                nav_top.css('top', the_window.scrollTop() + PADDING_TOP);
            } else if (!NAV_TOP_IS_FIXED) {
        	    nav_top.css({
                    top: PADDING_TOP,
					position: 'fixed',
					left:left_point_top
        	    });/*
				nav_top.animate({"left": "-=80px"}, "slow");
				nav_top.animate({
				width: '760px',
				fontSize:'15pt',
				fontColor: 'black',
				opacity: 0.7
				});*/
				$('#nav_top ul').animate({fontSize:'106%', width:'800px'}, 1000);
				NAV_TOP_IS_FIXED = true;
        	}
        } else {
            if (NAV_TOP_IS_FIXED) {
                nav_top.css({
                    position: 'absolute',
                    top: '',
                    left: ''
                });
				$('#nav_top ul').animate({fontSize:'100%', width:'780px'}, 1000);
				NAV_TOP_IS_FIXED = false;
            }
        }
	});

	the_window.resize(function () {
	    left_point_top = $('#title').offset().left;
	    if (NAV_TOP_IS_FIXED) {
    	    nav_top.css('left', left_point_top);	        
	    }
	});
});


//---
    return {
        format_price: format_price,
        get_price: get_price
    };
})();
