/*******

	***	Anchor Slider by Cedric Dugas   ***
	*** Http://www.position-absolute.com ***
	
	Never have an anchor jumping your content, slide it.

	Don't forget to put an id to your anchor !
	You can use and modify this script for any project you want, but please leave this comment as credit.
	
*****/
		


$(document).ready(function() {
	$("a.anchorLink").anchorAnimate()
	$('a[rel*=facebox]').facebox()
	
	$('#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 = $('#wrapper').offset().left;
	var PADDING_TOP = 45; // 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 = $('#wrapper').offset().left;
	    if (NAV_IS_FIXED) {
    	    nav.css('left', left_point);	        
	    }
	});
});

jQuery.fn.anchorAnimate = function(settings) {

 	settings = jQuery.extend({
		speed : 700
	}, settings);	
	
	return this.each(function(){
		var caller = this
		$(caller).click(function (event) {	
			event.preventDefault()
			var locationHref = window.location.href
			var elementClick = $(caller).attr("href")
			
			var destination = $(elementClick).offset().top;
			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, settings.speed, function() {
				window.location.hash = elementClick
			});
		  	return false;
		})
	})
}
