function apriPop(url, name, w, h) {
	var l = Math.floor((screen.width-w)/3);
	var t = Math.floor((screen.height-h)/3);
	window.open(url,name,"width=" + w + ",height=" + h + ",top=" + t + ",left=" + l);
}

//semplice show/hide del primo div sotto la classe btSh
function setSH() {

	var myElements = ".btSh";

	$(myElements).each(function(i) {

		$(this).click(function() {

			if($(this).next('div').css('display') == 'none')
				$(this).next('div').show('slow');
			else
				$(this).next('div').hide('slow');
		});

	});

}

//riporta le righe senza evidenziazione
function normRighe(pExclude) {

	var myElements = ".rowEvid";

	$(myElements).each(function() {

		if($(this).attr('id') != pExclude) {

			$(myElements).removeClass('evid');
			$(myElements).removeClass('freccia_blu');
			$(myElements).find('a:first').removeClass('active');

		}

	});

}

//riporta i thumbs senza evidenziazione (quadratino rosso)
function normThumb(pExclude) {

	var myElements = ".sqThmb";

	$(myElements).each(function() {

		if($(this).attr('id') != pExclude) {

			$(myElements).removeClass('sqThmb_active');

		}

	});

}

//evidenzia la riga con mouseover e se richiesto mostra la scheda
function evidRighe() {

	var myElements = ".rowEvid";

	$(myElements).mouseover(

		function() {

			normRighe($(this).attr('id'));

			$(this).addClass('evid');
			$(this).addClass('freccia_blu');

			$(this).find('a:first').addClass('active');

			var classes = $(this).attr('class');

			if(classes.search('showScheda') > 0) {
				showScheda($(this).attr('id'));
			}

		}
	);

}

// per mostrare immagine da thumbs con quadratino
function shImgPrinc() {

	var myElements = ".sqThmb";

	$(myElements).mouseover(

		function() {

			normThumb($(this).attr('id'));

			$(this).addClass('sqThmb_active');

			showScheda($(this).attr('id'));

		}
	);


}


// per mostrare la scheda o immagine richiesta e nasconde le altre
function showScheda(pId) {

	var myElements = ".contRiqScheda";

	$(myElements).each(function() {
		$(this).css('display', 'none');
	});

	$('#schDett'+pId).css('display', 'block');

}

//Menù a tendina
function submenu(){

	$(" #nav ul ").css({display: "none"}); // Opera Fix

	$(" #nav li").hover(function() {

		$(this).find('ul:first').css({visibility: "visible",display: "none"}).show(400);
		$(this).find('ul:first li.submenu:first').css('margin-top', "40px");


	},function() {

		$(this).find('ul:first').css({visibility: "hidden"});

	});
}


$(document).ready(function() {
//theRotator();
//	$('div.rotator').fadeIn(1000);
//    $('div.rotator ul li').fadeIn(1000); // tweek for IE
	submenu();

	setSH();

	evidRighe();

	shImgPrinc();

	if($.browser.msie) {
		if(jQuery.browser.version == '6.0') {

		}
	}

	//per le news in hp
	$('#riqNews').cycle({
		fx:    'fade',
    	delay: -1000,
    	sync: 1,
    	timeout: 20000,
    	width: '420',
    	height: '280'
	});

});
function theRotator() {
	//Set the opacity of all images to 0
	$('div.rotator ul li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	$('div.rotator ul li:first').css({opacity: 1.0});
		
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	
	setInterval('rotate()',6000);
	
}

function rotate() {	
	//Get the first image
	var current = ($('div.rotator ul li.show')?  $('div.rotator ul li.show') : $('div.rotator ul li:first'));

    if ( current.length == 0 ) current = $('div.rotator ul li:first');

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div.rotator ul li:first') :current.next()) : $('div.rotator ul li:first'));
	
	//Un-comment the 3 lines below to get the images in random order
	
	//var sibs = current.siblings();
        //var rndNum = Math.floor(Math.random() * sibs.length );
        //var next = $( sibs[ rndNum ] );
			

	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
};


