document.observe("dom:loaded", function() {
	var w = $$('html')[0].getWidth();
	if(w < 1010 && w > 850){
		$$("body")[0].setSyle({
			overflowX : "hidden"
		});
	}

	$$('.delme').each(function(it) {
		it.observe('focus', function() {
			if ($(this).match('input') || $(this).match('textarea')) {
				var orival = $(this).getValue();
				$(this).value = "";
			}else{
				var orival = $(this).innerHtml;
				$(this).update("");
			}

			$(this).observe('blur', function() {
				if($(this).match('input') || $(this).match('textarea')){
					if ($(this).getValue() != "" && $(this).getValue() != orival) {
						$(this).removeClassName('delme').stopObserving('blur').stopObserving('focus');
					}else{
						$(this).value = orival;
					}
				}else{
					if ($(this).innerHtml != "" && $(this).innerHtml != orival) {
						$(this).removeClassName('delme').stopObserving('blur').stopObserving('focus');
					}else if ($.browser.safari && $(this).getValue() != "" && $(this).getValue() != orival) {
						$(this).removeClassName('delme').stopObserving('blur').stopObserving('focus');
					}else{
						$(this).update(orival);
					}
				}
			});
		});
	});
});

// Menu laterale categorie
function toggleOpen(id) {
	try {
		var it = $(id);
		if(it.getStyle('height') == '0px') {
			var options = {
				scaleFrom: 0,
				scaleX: false,
				scaleContent: false,
				beforeSetup: function() {
					it.setStyle({
						height: 'auto'
					});
					it.siblings()[0].innerHTML = '-'
				}
			};
			new Effect.Scale(it, 100, options);
		}
		else {
			var options = {
				scaleFrom: 100,
				scaleX: false,
				scaleContent: false,
				afterFinish : function() {
					it.siblings()[0].innerHTML = '+'
				}
			};
			new Effect.Scale(it, 0, options);
		}
		return false;
	}
	catch(e) {
		alert(e.message);
	}
}

if ($('carousel')) theCarousel = new UI.Carousel("carousel");
if (Prototype.Browser.IE) Cufon.now();