function track(uri){
	var turi = uri.split(".xml").join(".page");
	turi = turi.split("http://"+document.location.host).join("");
    if (document.location.href.indexOf(turi)==-1
    		&& uri.indexOf("/service/")==-1
    		&& uri.indexOf("/common/")==-1)
        document.location = "#" + turi;
    $.gaTrackers['UA-6993477-1']._trackPageview(uri);
}

function dynamizeLabel(label, dynamicVal){
	$.each(dynamicVal, function(i, dval){
		label = label.replace(/#/, dval);
	})
	return label;
}
var trackonly = 0;
function init(){
 	trackonly++;
	var wmenu = $("body").width()-(124+137);
	var wfoot = $("body").width()-(270+270);
	$("#header ul.menu").css("width", wmenu+"px");
	$("#footer .info_bar").css("width", wfoot+"px");
	if($("body").height()<=($(window).height()-60)) {
		$("#footer").css("position","absolute");
	}else{
		$("#footer").css("position","relative");
	}
	if(trackonly==1){
		$.gaTrack("UA-6993477-1", {
	        cd_active: true,
	        cd_domainname: ".camomilla.it"
		});
	}
}

function setOverlay(status){
	if(status){
		$("body").append("<div id=\"overlay\"></div>");
		doSizeOverlay();
		$("body #overlay:last").fadeTo(0, 0.65);
		$("body #overlay:last").show();
	}else{
		$("body #overlay:last").remove();
	}
}

function getBox(title, message, close){
	$("body").append("<div id=\"error\" class=\"minibox hide\"><a href=\"#close\" class=\"close\">"+close+"</a><h3>"+title+"</h3><p>"+message+"</p></div>");
	$("body .close:last").click(function(){
		$("body #error:last").remove();
		setOverlay(false);
		return false;
	});
	centerBox();
	setOverlay(true);
	$("#error").show();
}

$(window).resize(function(){
	doSizeOverlay();
	centerBox();
});
$(window).scroll(function(){
	doSizeOverlay();
	centerBox();
});

function doSizeOverlay(){
	$("body #overlay:last").css("height", $(window).height()+$(document).scrollTop());
}

function centerBox(){
	var m_top = ($(window).height()/2)-(268/2)+$(document).scrollTop();
	var m_left = ($(window).width()/2)-(388/2);
	$("body #error:last").css("top", m_top+"px").css("left", m_left+"px");
}


var ajaxQueueCount = 0;

function displayOverlay()
{
	ajaxQueueCount++;
	if (ajaxQueueCount>1)
		return;
	if ($("#shopWait").length==0)
	{
		$(document.body).append('<div id="shopModalCover">&nbsp;</div>' +
						'<span id="shopWait">' +
						'<img src="http://test.camomilla.it/consumer/res/img/loader_white.gif"/>' +
						'Attendere..' +
						'</span>');
	}
	$("#shopModalCover").width($(window).width());
	$("#shopModalCover").height($(window).height());
	$("#shopModalCover").show();
	$("#shopWait").show();
		
}

function hideOverlay()
{
	ajaxQueueCount--;
	if (ajaxQueueCount>0)
		return;
	$("#shopModalCover").hide();
	$("#shopWait").hide();

}

