	var matchingClickAnchorRegex = 'a[href*=".m2k"],a[href$="./"]';

    	$(document).ready( function () {
    		if (!window.history.pushState)
    		{
    			var hrefhashcheck = window.location.href.match(/^(.*\/).*\.m2k(#.*\.m2k.*)/);
				if (hrefhashcheck != null && hrefhashcheck.length == 3)
				{
					window.location = hrefhashcheck[1].concat(hrefhashcheck[2]);
				}
				var hrefhashcheck2 = window.location.href.match(/^(.*\/)(.*\.m2k)(?!#.*\.m2k)(.*$)/);
				if (hrefhashcheck2 != null && hrefhashcheck2.length == 4 && hrefhashcheck2[2].substring(0,1) != '#')
				{
					window.location = hrefhashcheck2[1].concat("#" + hrefhashcheck2[2]).concat(hrefhashcheck2[3]);
				}
			}

			loadingPage(window.location.pathname + window.location.search + window.location.hash);

			History.Adapter.bind(window,'statechange',function(){ // Note: We are using statechange instead of popstate
				loadingPage(window.location.pathname + window.location.search + window.location.hash);
			});

		    $(matchingClickAnchorRegex).click(function () {
		    		ps(null, null, $(this).attr("href"));
					return false;
		    });
    	});



	    function loadingPage(href) {

	    	if (href.substring(href.length - 1, href.length - 0) == '/') {
	    		href = href.concat("Default.m2k");
	    	}
   			if (href.length != -1 && href.indexOf(".m2k") != -1)
			{
				//set html
				//$('#ga_div').load('ga.html');
				_gaq.push(['_trackPageview', href.replace(/#.\//g,'').replace(/#/g,'')]);
				
					var href_parts = href.split('/');
				var filename = href_parts[href_parts.length - 1].split('.')[0];
				if (filename.substring(0, 1) == '#') {
				  filename = filename.substring(1);
				}
				$('#mainContentPad').load(filename + '.html', function(response, status, xhr) {
					$('#mainContentPad').find(matchingClickAnchorRegex).click(function () {
										ps(null, null, $(this).attr("href"));
										return false;
		    		});

				});


				$('html, body').animate({
					scrollTop: ($('#mainContentPad').offset().top -155)
				}, 500);

				$('.sideNav > li > a').removeClass('selected');
				$('#NavigationContent_leftNav_' + filename).addClass('selected');
			}
		}

		function ps(var1, var2, html) {
			var ua = navigator.userAgent.toLowerCase();
			var isMobile = (ua.indexOf("android") > -1 || ua.indexOf("mobile") > -1 || ua.indexOf("iPhone") > -1) ;
			if(isMobile)
			  window.location = html;
			else
				History.pushState(null, null, html);
		}

