jQuery.noConflict();
jQuery(document).ready(function(){
	jQuery('.regali').click(function(){
		jQuery('.regali_menu').toggle();
	});
	jQuery('select').change(function(){
		var opt = jQuery(this).val();
		if (opt==3 || opt==4) {
			jQuery('.nascosto input').val('');
			jQuery('.nascosto').slideDown();
		}
		else {
			jQuery('.nascosto').slideUp();
		}
	});
	jQuery('#main-position form').submit(function(){
		if (jQuery('.nascosto').css('display')!='block') {
			var ta = jQuery('.nascosto input');
			if (jQuery.trim(ta.val()) == '') {
				ta.val('-');
			}
		}		
		return true;
	});
	// layer che appare dall'alto
	var popup = jQuery('.layer_bk');
	var img = popup.find('img:eq(0)');
	if (img.length == 0) {
		img = popup.find('object:eq(0)');
		if (img.length == 0) {
			img = popup.find('embed:eq(0)');
		}
	}
	var leftPos = Math.round((jQuery().width() -img.attr('width')) /2);
	popup.css({
			width:img.attr('width')+'px',
			height:img.attr('height')+'px',
			position:'absolute',
			left:leftPos+'px',
			top:'-'+img.attr('height')+'px',
			display:'block',
			zIndex: '999'
		});
	popup.animate({top:'100px'},{duration:2000});

	layer_timeout = setTimeout(function(){
						var me = jQuery('.layer_bk');
						me.animate({top:-me.height()},{duration:1000});
						setTimeout(function(){
							me.fadeOut(500,function(){
								me.remove();
							});
						},1000);
					}, 17000);

	jQuery().one('click',function(){
		clearTimeout(layer_timeout);
		var me = jQuery('.layer_bk');
		me.animate({top:-me.height()},{duration:1000});
						setTimeout(function(){
							me.fadeOut(500,function(){
								me.remove();
							});
						},1000);
	});
	

});
