
/*se all'avvio c'� un anchor lo metto come url e cancello l'anchor*/
function anchorToUrl(){
    if(document.location.hash){
        var currentAnchor = document.location.hash;
        var url = currentAnchor.substring(1);
        if(startWithSlash(url)){
			
            window.location=url;
        }
    }
}

var currentAnchor = null;
//Function which chek if there are anchor changes, if there are, sends the ajax petition
function checkAnchor(){
    //Check if it has changes
    if(currentAnchor != document.location.hash){
        currentAnchor = document.location.hash;
        if(currentAnchor){
            //se l'ancor nn parte con slash potrebbe essere un anchor vero
            var url = currentAnchor.substring(1);
            if(startWithSlash(url)){

                //                url += " #content";
                if( currentAnchor == "/"){
                    url = "home";
                }

                //                    $("#content").load(url);
                $('img.loading-image').css("display","block");
							
				
                $.get(url,null,function(data){
                    $("#content").html($(data).find("#content"));
                    $('img.loading-image').css("display","none");
                    runAll();
                /*
				$("#content").fadeTo(200,0.001,function(){
						$("#content").html($(data).find("#content"));
						$("#content").fadeTo(100,1,function(){
							//rimette l'antialiasing su explorer '
							$("#content").attr("style","display: block");
							$('img.loading-image').css("display","none");
						});
					});*/
                });
            }
        }

    //Send the petition
    /* if($.browser.msie){
		ajaxLoad(url, null, false, '#content');
	}else{
		ajaxLoad(url, null, true, '#content');
	}*/
    }
}

function linksToAnchor(element){
    $(element).click(function () {
        // domEle == this
        var href = $(this).attr('href');
		
        if(href.indexOf('http://www.luigiantonini') != -1 ){
            //		        href = '#'+ href.substring('http://www.luigiantonini.it'.length,href.length);
            href = href.substring('http://www.luigiantonini.it'.length,href.length);
            window.location.hash = href;
            $('html, body').animate({
                scrollTop:0
            }, 'slow');
            return false;
        }
    });
/*
   $(element).each(function (index, domEle) {
        // domEle == this
        var href = $(domEle).attr('href');
		
        if(href.indexOf('http') == -1){
            href = '#'+ href;
            $(domEle).attr('href',href);
        } else if(href.indexOf('http://en.luigiantonini') != -1 ){
            href = '#'+ href.substring('http://en.luigiantonini.it'.length,href.length);
            $(domEle).attr('href',href);
        } else if(href.indexOf('http://www.luigiantonini') != -1 ){
            href = '#'+ href.substring('http://www.luigiantonini.it'.length,href.length); 
            $(domEle).attr('href',href);
        }
    });
	*/
}

function startWithSlash(string){
    return string.substring(0,1) == '/';
}



