$(document).ready(pageLoaderInit);
function pageLoaderInit(){

Cufon.refresh();

/*
var 
	    $mainContent     = $("#allajax"),
	    $ajaxSpinner     = $("#ajax-loader"),
	    $searchInput     = $("#s"),
	    $allLinks        = $("a"),
	    $el;

	$('a:urlInternal').live('click', function(e) { 
	
		$el = $(this);
	
		if ((!$el.hasClass("comment-reply-link")) && ($el.attr("id") != 'cancel-comment-reply-link')) { 		
			var path = $(this).attr('href').replace(base, '');
			$.address.value(path);
			$(".current_page_item").removeClass("current_page_item");
			$allLinks.removeClass("current_link");
			$el.addClass("current_link").parent().addClass("current_page_item");
			return false;
		}
		
		// Default action (go to link) prevented for comment-related links (which use onclick attributes)
		e.preventDefault();
		
	});  
	
	
$.address.change(function(event) {  
		//if (event.value) {
			//loadPage(base + event.value);
		//} 

		
		var current = location.protocol + '//' + location.hostname + location.pathname;
		if (base + '/' != current) {
			var diff = current.replace(base, '');
			location = base + '/#' + diff;
		}
	}); 
*/

  $("#header a").click(function(event){
    if(this.href.indexOf(home)>=0&&this.href.indexOf('/wp-')<0){
    /*if(this.href.split('?')[1].split('=')[0]=='m'||
       this.href.split('?')[1].split('=')[0]=='p'||
       this.href.split('?')[1].split('=')[0]=='cat'||
       this.href.split('?')[1].split('=')[0]=='page_id'){*/
      // stop default behaviour
      event.preventDefault();
      // remove click border
      this.blur();
      // get caption: either title or name attribute
      var caption = this.title || this.name || "";
      // get rel attribute for image groups
      var group = this.rel || false;
      // display the box for the elements href
      loadPage(this.href);
    }
  });
  
  
  
}
function getHTTPObject() {
  var xmlhttp;
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}
var isWorking = false;
var http = getHTTPObject();
function loadPage(url){
  if(!isWorking){
    scroll(0,0);
    document.getElementById('allajax').innerHTML='<center><img src="'+loadingIMG.src+'" /></center>';
    http.open('GET',url,true);
    isWorking=true;
    http.onreadystatechange=showPage;
    http.send(null);
  }
}
function submitSearch(param){
  if(!isWorking){
    scroll(0,0);
    document.getElementById('allajax').innerHTML='<center><img src="'+loadingIMG.src+'" /></center>';
    http.open('GET',window.location+param,true);
    isWorking=true;
    http.onreadystatechange=showPage;
    http.send(null);
  }
}
function showPage(){
  if(http.readyState==4){
    if(http.status==200){
      isWorking=false;
      var content = http.responseText;
      content = content.split('id="allajax"')[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('allajax').innerHTML=output;
      pageLoaderInit();
    }else{
      alert(http.status);
    }
  }

}
