jQuery(function() {
    //scroll
    jQuery.localScroll({
        hash:true,
        easing:"easeInOutCubic"
    });
    jQuery(window).bind("scroll load", function(){
        var scrolled = jQuery(window).scrollTop(),
            delta = 230;
        jQuery("#logo").css("top", 20+scrolled + "px");
        jQuery("#menu")
            .stop()
            .animate({"top": (scrolled + delta) + "px"}, "slow"/*, "easeInOutExpo"*/ );
    });

    //ajax links
    jQuery("a:not([rel^='lightbox']|[rel^='direct'])").live("click", function(){
        var defaultContainer = "#content",
            new_page = jQuery(this).prop("href");

        jQuery("#loader").fadeIn("fast");
        var container = jQuery(this).prop("rel") || defaultContainer;
        jQuery(container).fadeOut("fast", function(){
            jQuery(container).load(new_page, function(){
                jQuery("#loader").fadeOut();
                jQuery(this).fadeIn("fast");
				jQuery('#gallery').jcarousel({scroll: 1});

                //if this is a link from the main menu - show it as hash
                if( container == defaultContainer ){
                    window.location.hash = new_page.replace(/^.*\/|\.[^.]*$/g, '');
                }
            });
        });

        return false;
    });
    
    //submission form
    jQuery("form").live("submit", function(){
        var target = jQuery(this).prop("rel") || "#content";
        jQuery(this).ajaxSubmit(function(response){
            jQuery(target).html(response);
        });
        return false;
    });
    
    //see if the user is coming from a hash
    if( window.location.hash != "" ){
        var page = window.location.hash.replace("#", "");
        jQuery("a[href='"+page+".php']").click();
    }
	
	jQuery("#menu a").bind("click",function(){
		jQuery("#menu a").removeClass("current");
		jQuery(this).addClass("current");
		});
		
	jQuery('#gallery').jcarousel({scroll: 1});
});
