// GET COOCKIE
function Get_Cookie( check_name ) 
{
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	
	if ( !b_cookie_found )
	{
		return null;
	}
}

$(document).ready(function()
{
	$('#menu ul li.menuLi').mouseover(function() {				
		//$('#menu ul li').css('zIndex', 9999);
		//$('#menu ul li.prova2 div').css('zIndex', 9999);
		//$(this).find("div").css('zIndex', 9999);
		$('#menu ul li.menuLi div').css("display", "none");
		$('#menu ul li.menuLi div').css('position', 'absolute');
		$(this).find("div").show();
	});	
	
	$('#menu ul li.menuLi').mouseout(function() {
		$('#menu ul li.menuLi div').hide();
	});
	
	
	
	
})

$(window).load(function() {
	
	if($('#leadercont p') && $('#leadercont p').length>0) {
		$('#gironi table tbody tr').fadeTo(0, 1, function() {
		});
	}
	
	
	if($('#leadercont p') && $('#leadercont p').length>0) {
		$('#leadercont p').fadeTo(0, 0.8, function() {
		});
	};
	
	if($('.mainfocus') && $('.mainfocus').length>0) {
		$('.mainfocus').fadeTo(0, 0.7, function() {
		});
		$('.mainfocus h2').fadeTo(0, 1, function() {
		});
	};


	if($('#fotogallerybig') && $('#fotogallerybig').length>0) {
 		Galleria.loadTheme('/calciomercato/res/js/themes/big/galleria.big.js');
		$('#galleria').galleria({
			image_crop: false,
			transition: 'slide',
 			data_config: function(img) {
				return {
					description: $(img).next('div').html()
				};
			}
		});	
		$('#sidebar #photogallery').hide();
		$('#sidebar #videogallery').hide();
	} else { 
	  
	  
	}
	
		
});


// chiedi a pedulla
$(document).ready(function() {

	if ( $("#chiediapedulla form") && $("#chiediapedulla form").length>0 )
	{
		$("#chiediapedulla form").bind("submit",function()
		{
			var mailFromName = $(this).find("input[name='mailFromName']");
			var mailFrom = $(this).find("input[name='mailFrom']");
			var body = $(this).find("textarea[name='body']");
			
			
			var doSubmit = true;
			
			if (mailFromName.val().split(" ").join("").length==0)
			{
				mailFromName.css("background-color","#F00");
				mailFromName.css("color","#FFF");
				doSubmit = false;
			}
			else
				mailFromName.removeAttr("style");

			if (mailFrom.val().split(" ").join("").length==0)
			{
				mailFrom.css("background-color","#F00");
				mailFrom.css("color","#FFF");
				doSubmit = false;
			}
			else
				mailFrom.removeAttr("style");

			if (body.val().split(" ").join("").split("\n").join("").split("\r").join("").split("\t").join("").length==0)
			{
				body.css("background-color","#F00");
				body.css("color","#FFF");
				doSubmit = false;
			}
			else
				body.removeAttr("style");
				
			if (doSubmit)
			{
				$(this).find("input[type='submit']").hide();
				$(this).append("<div class=lmsg style=\"padding:5px 0 0 0; float:right;\">Attendere...</div>");
				if (document.location.hostname=="" || document.location.hostname=='localhost')
				{
					try 
					{
						netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
						netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
					} 
					catch (err){}
				}
				$.ajax({
					type: "POST",
					async: true,
					url: $(this).attr("action"),
					contentType:"application/x-www-form-urlencoded",
					data: $(this).serialize(),
					success: function() 
					{
						$("#chiediapedulla .lmsg").html("Invio effettuato con successo");
						$("#chiediapedulla form").trigger("reset");
					},
					error: function()
					{
						$("#chiediapedulla .lmsg").html("Si e' verificato un errore durante l'invio");
						setTimeout(function()
						{
							$("#chiediapedulla .lmsg").fadeOut("normal",function()
							{ 
								$("#chiediapedulla .lmsg").remove();
								$("#chiediapedulla input[type='submit']").show();
								$("#chiediapedulla input[type='submit']").blur();
							})
						},1500);
					}
				});
			}
				
			return false;
		})
	}
})
