function pageInit(){
  jQuery("#stContents div.navigation a").click(function(event){
      // stop default behaviour
      event.preventDefault();
      this.blur();
      pageLoaderInit(this.href);
  });
}
function getHTTPObject() {
	  var xmlhttp;
	if (window.XMLHttpRequest) {
	  // If IE7, Mozilla, Safari, and so on: Use native object.
	  xmlhttp = new XMLHttpRequest();
	}
	else{
	  if (window.ActiveXObject) {
		 // ...otherwise, use the ActiveX control for IE5.x and IE6.
		 xmlhttp = new ActiveXObject('MSXML2.XMLHTTP.3.0');
	  }
	}
	  return xmlhttp;
}
var isWorking = false;
var http = getHTTPObject();
function pageLoaderInit(theUrl, theState){
	if(!isWorking){
	jQuery('div.col-left div#stContents').html('<span id="load"><img src="http://www.morespaceplacefranchise.com/wp-content/themes/top100/images/ajax-loader.gif" alt="loading..." /></span>' );
		var toLoad = theUrl +' div.post';
		jQuery.ajax({
		url : theUrl,
		success : function (data) {
			isWorking=false;
			var content = data;
		  	content = content.split('class="span-10"')[1];
		  	content = content.substring(content.indexOf('>')+1);
		  	var depth=1;
		  	var output='';
			  while(depth>0){
				temp = content.split('</div>')[0];
				//count occurrences
				i=0;
				pos = temp.indexOf("<div");
				while(pos!=-1){
				  i++;
				  pos = temp.indexOf("<div",pos+1);
				}
				//end count
				depth=depth+i-1;
				output=output+content.split('</div>')[0]+'</div>';
				content = content.substring(content.indexOf('</div>')+6);
			  }
			document.getElementById('stContents').innerHTML=output;
			jQuery("#stContents div.post").hide();
			jQuery("#stContents div.post").fadeIn();
			jQuery('div.stateHead h2').text(theState);
			
			jQuery('#stContents div.navigation a').click(function(){
				pageLoaderInit(this.href);
				return false;
				//pageInit();
			});	
			
			//pageInit();
			}
		});
	
	}
}
