$(document).ready(pageLoaderInit);
	var buo = 'http://habeshacollection.com/';
/*	var buo = 'http://localhost/projets/habesha/www/wordpress/';*/
		
	var js_includes = buo + 'wp-includes/';
	$.getScript( js_includes + 'js/tw-sack.js');
	
	$(document).ready(function(){
		$(".ajaxnav a").addClass('xv');
		$(".ajaxnav a").click(function(event){
		if(this.href.indexOf(home)>=0&&this.href.indexOf('/wp-')<0){
			var navRequest = new sack(this.href);
			navRequest.onCompletion = roule;
			navRequest.method = 'GET';
			navRequest.runAJAX();
			document.getElementById('content').innerHTML +='<div id="ajax-ld-hbsh"><img src="'+loadingIMG.src+'" /></div>';
	 }
 });
});

function pageLoaderInit(){

	$('#menu li ul li ul li a').click( function (){
		$(this).parent().addClass("current_page_item");
	})
	$('#cg-container').each(function(){
		$.getScript( js_includes + 'js/jquery/jquery.catalogue-hbsh.js');
	});
	$('#post-97').each(function(){
		$.getScript( buo + 'wp-content/plugins/wp-ajax-newsletter/snews_ajax.js');
	});
	$("a").click(function(){
		$(this).blur();
	});



	 $(".ajaxnav 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
			// 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



			if(this.href.indexOf(home)>=0&&this.href.indexOf('/wp-')<0){	}

				if (! $(this).hasClass('xv')){
					 var navRequest = new sack(this.href);
					navRequest.onCompletion = roule;
					navRequest.method = 'GET';
					navRequest.runAJAX();
					document.getElementById('content').innerHTML +='<div id="ajax-ld-hbsh"><img src="'+loadingIMG.src+'" /></div>';
					$(this).addClass('xv'); 
				}
		
		}
	});
}

function roule(){
	var content = this.response;
	content = content.split('id="content"')[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('content').innerHTML=output;
	pageLoaderInit();	
}