if (typeof $ === 'undefined') {
    window.location.reload(true);
}

$(function() {
    //var History = window.History;
    
    // deactivated so that we can see the user's movement in Google Analytics
//    rebindLinkClickEvents('.kelson', '#contents');
//    rebindLinkClickEvents('.kelson2', '#page-contents>div>div.jspPane');
    
/*
// add listener onto navbar
    $('.kelson').click(function() {	
	
        // store the reused object for speed
        var $t = $(this);
		
        // load the content in
        load_content($t.attr('title'),$t.attr('href'));
		
        // stop the default click event
        return false;
    });
*/
});


function rebindLinkClickEvents(linkSelector, contentSelector) {
    $(linkSelector).click(function(e) {
        // stop the default click event
        e.preventDefault();
        // store the reused object for speed
        var $t = $(this);
		
        // load the content in
        //load_content(contentSelector, $t.attr('title'),$t.attr('href'));
        History.pushState({
            type:linkSelector,
            content: contentSelector
        }, $t.attr('title'), $t.attr('href'));
    });
}

function load_content(contentSelector,title,url,skipHistory) {

/*
    $(contentSelector).load(url,function (data) {	
        // add google analytics page view
        //if (pageTracker)
        // pageTracker._trackPageview(url);
	
        // update the window title
        document.title = title;
	
        rebindLinkClickEvents('.kelson', '#contents');
        rebindLinkClickEvents('.kelson2', '#page-contents>div>div.jspPane');
        // generate stateObj, this is used on the pop event
        var stateObj = {
            title: title,
            url: url
        };
		
                
        // check to see if added to history or skipped
        if (!skipHistory) {
		
            // check if can handle pushState
            if (typeof window.history.pushState == 'function') {
			
                // push on to history
                window.history.pushState(stateObj,title,url);			
            }
	
        }*/

/*
    // do the AJAX call
    $.get(url,function (data) {	
        // add google analytics page view
        //if (pageTracker)
           // pageTracker._trackPageview(url);
	
        // update the window title
        document.title = title;
		
        // generate stateObj, this is used on the pop event
        var stateObj = {
            title: title,
            url: url
        };
		
        // check to see if added to history or skipped
        if (!skipHistory) {
		
            // check if can handle pushState
            if (typeof window.history.pushState == 'function') {
			
                // push on to history
                window.history.pushState(stateObj,title,url);			
            }
	
        }
		
        // populate the content section
        $('#contents').html(data);
*/		
/*    });*/
    

}

/*
// add opstate listener
window.onpopstate = function(event) {
	
    // if is one of ours
    if (event.state) {
				
        // load the content
        load_content(event.state.title, window.location.pathname, true);
    }
    else { // we need to make it one of ours
        // generate stateObj, this is used on the pop event
        var stateObj = {
            title: document.title,
            url: window.location.pathname 
        };
	
//        window.history.replaceState(stateObj,document.title,window.location.pathname);
    }
}
*/
