jQuery(function($) {

	// sottomenu`
	$('#nav1 ul ul').wrap('<div class="sub"\/>').before(function(){
			var s=$(this).parent('.sub')
			.mouseleave(function(){$(this).hide(80).trigger('hide');});
			if ( $.browser.msie && 8>parseInt($.browser.version) ) { // ie7 bug 
				s.bind('show',function(e){$('#path').hide();});
				s.bind('hide',function(e){$('#path').show();});
			}
			return $('<h3/>').append(s.siblings('a').eq(0).mouseenter(function(){s.trigger('show');s.show(250);}).clone(false));
	})
	.each(function(i){ $(this).closest('li').css({zIndex:9999-i});}); // ie7 bug

	if ( $.browser.msie && 8>parseInt($.browser.version) ) { // x ie7 bug su overlay: sposta il sottomenu` in coda al body
		$('#nav1 ul div.sub').each(function(){
			this._menu = $(this).parent('li'); // = offsetParent
			$(this).bind('show',function(){var p = this._menu.offset(); $(this).css({top:p.top-7,left:p.left+1}); });
			$(this).detach().appendTo('body').addClass('iemenu').css({position:'absolute',zIndex:10000});
		});
	}


	/* News scroller */
	(function(){
		var m = $('#xtra .news ol');
		if (!m.length) return;
		var n ='scrollbox';
		m.each(function(){
			o = $(this);

			o	.wrap('<div class="'+n+'_out"><div class="'+n+'_wrp"><div class="'+n+'_inr" \/><\/div><\/div>')
				.parents('.'+n+'_wrp').after('<div class="'+n+'_bar"><div class="'+n+'_ctl" \/><\/div>');
			$('.'+n+'_out').css({overflow:'hidden',width:o.outerWidth()+'px'});
			$('.'+n+'_inr,.'+n+'_wrp,.'+n+'_bar').css({position:'relative'});
			$('.'+n+'_out,.'+n+'_bar').css({height:o.outerHeight()+'px'});
			$('.'+n+'_inr').css({overflow:'hidden'});

			o.css({overflow:'visible',width:'auto',height:'auto'});
			if ( $('.'+n+'_inr').outerHeight() < $('.'+n+'_out').height() ) $('.'+n+'_inr').css({height:$('.'+n+'_out').height()+'px'});

			var y0=$('.'+n+'_inr').offset().top-$('.'+n+'_out').offset().top;
			$('.'+n+'_ctl').draggable({axis:'y',containment:'.'+n+'_bar',scroll:false,drag:function(){
				var h=$(this).offsetParent().height()-$(this).outerHeight(true);
				var r=$(this).position().top/h;
				var h1,h2,t;
				h1=$('.'+n+'_out').innerHeight();
				h2=$('.'+n+'_inr').outerHeight(true)+y0;
				t=r*(h1-h2);
				$('.'+n+'_inr').css('top',t+'px');
			}});
		});

	})();


	/* Box ricerca */
	$('#auxl form:has(.box.ricerca-sito)')
	.find('input[type="text"]').each(function(){
		$(this)
			.data('dflt',$(this).val())
			.focus(function(){var t=$(this);if(t.data('dflt')==$.trim(t.val())){t.val('')} })
			.blur (function(){var t=$(this);if(''==$.trim(t.val())){t.val(t.data('dflt'))} })
			.trigger('blur');
	})
	.end().submit(function(e){
		var msg = str.err['emptysearch'];
		var r=true;
		$('input[type="text"]',this).each(function(){var v=$.trim($(this).val());if(v==''||v==$(this).data('dflt')){r=false;return;}});
		if (!r) { e.preventDefault(); alert(msg); }
		return r;
	});

	
	//equalHeights by james padolsey
	$.fn.equalHeights = function() {
		return this.height(Math.max.apply(null,
			this.map(function() {
			   return $(this).height()
			}).get()
		));
	};
	// altezza box intro corsi pareggiata
	$('.corsi #bxes .box>.int>div').equalHeights();


});
