//submenu	

$(document).ready(function() {

	$menu = $("#menu > li");	
	$menu.each(function(i,val){
		$($menu[i]).find("a").attr("num",""+i+"");	})	
	$menu.each(function(i,val){	
		var index = $('.self').attr("num");
		
		$(".childmenu").hide();
		$($menu[index]).children("a").addClass("self").next().show();
		
		$($menu[i]).hover(
			function(){
				$(".childmenu").hide();
				$("#menu li a").removeClass('self');
				$(this).children("a").addClass("self").next().show();
			},
			function(){ 
				$(".childmenu").hide();				
				$("#menu li a").removeClass('self');				
				$($menu[index]).children("a").addClass("self").next().show();
			}
		)
	});
	
	
	
	$('a.null').click(function() {
	return false;
	});
	
	/* NATALE
	
	$('#menu').after('<div id="auguri"></div>');
	$('#auguri').css({'width':'990px','height':'40px','background':'url(http://www.key4biz.it/files/000185/00018517.jpg) no-repeat','margin':'-20px 0 20px'});
	
	*/
	
	$('form#petitionform').submit(function() {
			$('form#petitionform .error').remove();
			var hasError = false;
			$('.requiredField').each(function() {
				if(jQuery.trim($(this).val()) == '') {
					var labelText = $(this).prev('label').text();
					$(this).addClass('inputError');
					$(this).parent().append('<span class="error">Deve compilare il campo obbligatorio</span>');
					hasError = true;
					$(this).click(function() {
							$(this).removeClass('inputError');
							$(this).val('');
							$(this).parent().find('.error').fadeOut('fast',function() {$(this).parent().find('.error').remove();});
					});
					$(this).focus(function() {
							$(this).removeClass('inputError');
							$(this).val('');
							$(this).parent().find('.error').fadeOut('fast',function() {$(this).parent().find('.error').remove();});
					});
				} 
				
				else if($(this).hasClass('email')) {
					var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
					if(!emailReg.test(jQuery.trim($(this).val()))) {
						var labelText = $(this).prev('label').text();
						$(this).addClass('inputError');
						$(this).parent().append('<span class="error">Inserisca un indirizzo email valido</span>');
						hasError = true;
						$(this).click(function() {
								$(this).removeClass('inputError');
								$(this).val('');
						});
					}
				}
			});
			
			
			if(!hasError) {
				$('form#petitionform p.button').fadeOut('normal', function() {
					$(this).parent().append('<img src="/images/ajax-loader.gif" alt="Loading&hellip;" />');
				});
				
				var formInput = $(this).serialize();
				$.post($(this).attr('action'),formInput, function(data){
					$('form#petitionform').slideUp("fast", function() {
						var nome = $('.name').val();			   
						$(this).before('<div class="thanks"><p><strong>Gentile '+ nome +'</strong>,</p><p>Grazie per aver aderito  all\'appello "Fondi per la ricerca".</p><p>Il suo nome apparir&agrave; a breve nella lista dei firmatari.</p></div>');
					});
				});
			}
			
			return false;
			
		});
	
	//
	});
	
	function getElement(aID)
	    {
	        return (document.getElementById) ?
	            document.getElementById(aID) : 
	
	document.all[aID];
	    }
	
	    function getIFrameDocument(aID){ 
	        var rv = null; 
	        var frame=getElement(aID);
	        // if contentDocument exists, W3C 
	
	compliant (e.g. Mozilla) 
	        if (frame.contentDocument)
	            rv = frame.contentDocument;
	        else // bad Internet Explorer  ;)
	            rv = document.frames[aID].document;
	        return rv;
	    }
	
	    function adjustMyFrameHeight()
	    {
	        var frame = getElement
	
	("dailyframe");
	        var frameDoc = getIFrameDocument
	
	("dailyframe");
	        frame.height = frameDoc.body.offsetHeight;
	    }
