var timeout = 5000;
$(document).ready(function() {
    //setTimeout("autoBanner()",timeout);		
	//$('#menu a:last-child').css('background','none');
	$('#menu li:last-child').css('background','none');
	
	$(function() {
		$("a[rel='_blank']").attr("target","_blank");				
	});
	
	$('.textinput, .textarea, .select').focus(
			function() {
				$(this).css({'border-color':'#333333'});
	});
	$('.textinput, .textarea, .select').blur(
			function() {
				$(this).css({'border-color':'#CCCCCC'});
	});
	
	// INIZIO FUNZIONE COMPARSA/SCOMPARSA TOOLBAR NEWS
	$(function() {
		if( $(".newsItem .toolbar").length > 0 ) {
			$('.newsItem').hover(function(){
				$(this).find('.toolbar').stop().animate({ top: 0 });
			}, function() {
				$(this).find('.toolbar').stop().animate({ top: -30 });	
			});
		}
	});
	// FINE FUNZIONE COMPARSA/SCOMPARSA TOOLBAR NEWS
	
	// INIZIO FUNZIONE ROLLOVER LISTA GIOCATORI
	$(function() {
			$('ul.team li').hover(function(){
				$(this).addClass('hover');
			}, function() {
				$(this).removeClass('hover');	
			});
			$('ul.team li').click(function(){
				var getPath = $(this).find('a').attr('href');
				document.location.href = getPath;
			});
	});
	// FINE FUNZIONE ROLLOVER LISTA GIOCATORI
	
	// INIZIO FUNZIONE PER UNIFORMARE ALTEZZE DEFINITION LISTS
	$("dt").each(function () {
		dtheight = $(this).height();				   
    	ddheight = $(this).next().height();
		if(dtheight >= ddheight) {
			$(this).height(dtheight);
			$(this).next().height(dtheight);
		}
		if(dtheight < ddheight) {
			$(this).height(ddheight);
		}
	});
	// FINE FUNZIONE PER UNIFORMARE ALTEZZE DEFINITION LISTS
	
	// INIZIO FUNZIONE ROLLOVER SONDAGGIO
	$(function() {
			$('ul.pollOptions li').hover(function(){
				$(this).addClass('hover');
			}, function() {
				$(this).removeClass('hover');	
			});
			$('ul.pollOptions li').click(function(){
				$('ul.pollOptions li').find('input[type=radio]').attr('checked', false);
				$('ul.pollOptions li').removeClass('click');
				$(this).addClass('click');
				$(this).find('input[type=radio]').attr('checked', true); 
			});
	});
	// FINE FUNZIONE ROLLOVER SONDAGGIO
	
	// INIZIO FUNZIONE PANNELLO BOOKMARK
	$(function() {
	$(".others").show();
	var panelWidth = $('.socialBookmarks').width();		   
	$(".others").click(function() {
		$('.socialBookmarks').stop().animate({width: "280px"});
		$(this).hide();
		$('.close').show();
		return false
	});
	$(".close").click(function() {
		$(this).hide();
		$('.socialBookmarks').stop().animate({width: "128px"});
		$('.others').show();
		return false
	});
	});
	// FINE FUNZIONE PANNELLO BOOKMARK
	
	$.urlParam = function(name){
		var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
		if(results) {
			return results[1] || 0;
		}
	};

	// DIALOG BOX GENERICO
	$(function() {
		$("#generic_dialog").dialog(
			{
				bgiframe: true,
				autoOpen: false,
				resizable: false,
				height:140,
				modal: true,
				overlay: {
					backgroundColor: '#000',
					opacity: 0.5
				},
				buttons: {
					'OK': function() {
						$(this).dialog('close');
					}
				}
			}
		);
	});			
});

function nextSideVideo(pagina){
	var page = pagina + 1;
	var poststr = "&page="+page;
	makePOSTRequest("getSideVideo.php",poststr,"side_video");
}

function prevSideVideo(pagina){
	var page = pagina - 1;
	var poststr = "&page="+page;
	makePOSTRequest("getSideVideo.php",poststr,"side_video");
}

function nextSidePhotogallery(pagina){
	var page = pagina + 1;
	var poststr = "&page="+page;
	makePOSTRequest("getSidePhotogallery.php",poststr,"side_photogallery");
}

function prevSidePhotogallery(pagina){
	var page = pagina - 1;
	var poststr = "&page="+page;
	makePOSTRequest("getSidePhotogallery.php",poststr,"side_photogallery");
}

function nextSideHi(pagina){
	var page = pagina + 1;
	var poststr = "&page="+page;
	makePOSTRequest("getSideHi.php",poststr,"side_hi");
}

function prevSideHi(pagina){
	var page = pagina - 1;
	var poststr = "&page="+page;
	makePOSTRequest("getSideHi.php",poststr,"side_hi");
}

function autoBanner(){
    $("#banner_1").fadeOut(1000);
    $.post("getBannerAuto.php",{id_categoria: 'banner_lato_destro_1xxxxxxxxxxxx', div: 'banner_1'}, function (data){
        $('#banner_1').delay(1000, function(){
            $("#banner_1").html(data);
            $("#banner_1").fadeIn(1000);
        });        
    });

    $("#banner_2").fadeOut(1000);
    $.post("getBannerAuto.php",{id_categoria: 'banner_lato_destro_2xxxxxxxxxxxx', div: 'banner_2'}, function (data){
        $('#banner_2').delay(1000, function(){
            $("#banner_2").html(data);
            $("#banner_2").fadeIn(1000);
        });        
    });

    $("#banner_3").fadeOut(1000);
    $.post("getBannerAuto.php",{id_categoria: 'banner_lato_destro_3xxxxxxxxxxxx', div: 'banner_3'}, function (data){
        $('#banner_3').delay(1000, function(){
            $("#banner_3").html(data);
            $("#banner_3").fadeIn(1000);
        });        
    });

    $("#banner_4").fadeOut(1000);
    $.post("getBannerAuto.php",{id_categoria: 'banner_lato_destro_4xxxxxxxxxxxx', div: 'banner_4'}, function (data){
        $('#banner_4').delay(1000, function(){
            $("#banner_4").html(data);
            $("#banner_4").fadeIn(1000);
        });        
    });

    $("#banner_5").fadeOut(1000);
    $.post("getBannerAuto.php",{id_categoria: 'banner_lato_destro_5xxxxxxxxxxxx', div: 'banner_5'}, function (data){
        $('#banner_5').delay(1000, function(){
            $("#banner_5").html(data);
            $("#banner_5").fadeIn(1000);
        });        
    });

    $("#topBanner").fadeOut(1000);
    $.post("getBannerAuto.php",{id_categoria: 'banner_alto_xxxxxxxxxxxxxxxxxxxx', div: 'topBanner'}, function (data){
        $('#topBanner').delay(1000, function(){
            $("#topBanner").html(data);
            $("#topBanner").fadeIn(1000);
        });        
    });

    $("#headBanner").fadeOut(1000);
    $.post("getBannerAuto.php",{id_categoria: 'banner_top_xxxxxxxxxxxxxxxxxxxxx', div: 'headBanner'}, function (data){
        $('#headBanner').delay(1000, function(){
            $("#headBanner").html(data);
            $("#headBanner").fadeIn(1000);
        });        
    });

    
    setTimeout("autoBanner()",timeout);
}
