jQuery(document).ready(function($) {
	jQuery(".content").append("<span id='ajax-loader'></span>");
	

    var $mainContent = jQuery(".content"), 
        siteUrl = "http://" + top.location.host.toString(), 
        url = ''; 

	jQuery(document).delegate("a[href^='"+siteUrl+"']:not([href*=/wp-admin/]):not([href*=/wp-content/]):not([href*=/wp-login.php]):not([href$=/feed/])", "click", function() { 
        location.hash = this.pathname; 
        return false; 
    }); 

	jQuery("#searchform").submit(function(e) { 
        location.hash = '?s=' + $("#s").val(); 
        e.preventDefault(); 
    }); 

	
	jQuery(window).bind('hashchange', function(){ 
        url = window.location.hash.substring(1); 
       
        if (!url) { 
            return; 
        } 

        url = url + " .contentinner";
        jQuery('#ajax-loader').fadeIn();
        jQuery("html").animate({ scrollTop: 0 }, 200);
        jQuery('.contentinner').delay(1000).animate({opacity: "0"}, 300, function(){
        	jQuery(this).load(url, function() {


        		jQuery(".contentinner").replaceWith(jQuery(".contentinner .contentinner"));
				jQuery('#ajax-loader').fadeOut(500, function() {
					jQuery('.contentinner').animate({opacity: "1"}, 1000);
				});
				jQuery(".accordion .tooltip:not(:first)").hide();
        		jQuery(".accordion h3").click(function(){
        			jQuery(this).next(".tooltip").slideToggle("fast").siblings(".tooltip:visible").slideUp("fast");
        			jQuery(this).toggleClass("selected");
        			jQuery(this).siblings("h3").removeClass("selected");
        		});
        		jQuery(".gal a").lightbox({
        			fitToScreen: true,
        			imageClickClose: false,
        			overlayOpacity: 0.9
        		});
        		jQuery('.gal a').attr('rel', 'gal[go]');
			jQuery(".lightbox").lightbox({
        			fitToScreen: true,
        			imageClickClose: false,
        			overlayOpacity: 0.9
        		});
        	});
		});
        
    });

	jQuery(window).trigger('hashchange'); 
});

