jQuery(document).ready(function(){
	
	//=========================
	//		BARRA DEL TITOLO
	//=========================
	_createRollOver('.insideNavLInk a');
	jQuery('.titleWrapper .indietro a').click(function(e){
			e.preventDefault();
				
			history.back();
		})	
})

function _createRollOver(elements)
{
	jQuery(elements).each(function(index, elem){
			jQuery(elem).clone().addClass('hover').insertAfter(elem).animate({'opacity': 0}, 0).css('z-index', (parseInt(jQuery(elem).css('z-index')) + 10));
		});
	//hover function
	jQuery(elements).hover(function(){
		if(!jQuery(this).parent().hasClass('disabled'))
			jQuery(this).parent().children('.hover').stop().animate({'opacity': 1}, 300);
		}, function(){
			jQuery(this).parent().children('.hover').stop().animate({'opacity': 0}, 300);
		});
}

function _modalAlert(message, titolo)
{
	message = message || "Errore.";
	titolo = titolo || "ATTENZIONE";
	jQuery('body').append('<div id="alert_errore">'+message+'</div>');
	jQuery('#alert_errore').dialog({
			modal: true,
			width: 450,
			resizable: false,
			draggable: false,
			title: titolo,
			buttons: {
				Ok: function() {
					jQuery( this ).dialog( "close" );
					jQuery('#alert_errore').remove();
					return false;
				}
			}
		});//messaggio_errore
		
}
function _modalYoutube(url, width, height, titolo)
{
	//inizializzo le variabili
	url = url || "nourl";
	width = parseInt(width) || 640;
	height = parseInt(height) || 480;
	titolo = titolo || "VIDEO";
	var video_url;
	//watch, v, embed, youtu.be
	// CASO URL ?v=
	if( url.lastIndexOf("v=") != -1 ){
		video_url = "http://www.youtube.com/embed/" + url.substr(url.lastIndexOf("v=")+2, 11);
	} 
	// CASO URL /v/
	else if( url.lastIndexOf("/v/") != -1 ){
		video_url = "http://www.youtube.com/embed/" + url.substr(url.lastIndexOf("/v/")+3, 11);
	} 
	// CASO URL embed
	else if( url.lastIndexOf("/embed/") != -1 ){
		video_url = url;
	} 
	// CASO URL CORTO youtu.be
	else if( url.lastIndexOf("youtu.be/") != -1 ){
		video_url = "http://www.youtube.com/embed/" + url.substr(url.lastIndexOf("youtu.be/")+9, 11);
	} 
	// CASO SENZA URL
	else if( url == "nourl"){
		return false;
	}

	var message = '<iframe width="'+ width +'" height="'+ height +'" src="'+ video_url +'" frameborder="0" allowfullscreen></iframe>';
	jQuery('body').append('<div id="alert_errore">'+message+'</div>');
	jQuery('#alert_errore').dialog({
			modal: true,
			width: 640,
			resizable: false,
			draggable: false,
			title: titolo,
			close: function(event, ui) {
				jQuery('#alert_errore').remove();
//				return false;
			}
		});//messaggio_errore

}
