function setMenu(){

	$('.js_btn_menu').mouseover(function(){
		var img = $(this).attr('src');
		if(img.indexOf(".jpg") != -1){
			img = img.replace(".off.jpg",".on.jpg");
		}else if(img.indexOf(".png") != -1){
			img = img.replace(".off.png",".on.png");
		}
		$(this).attr( {src: img} );
	}).mouseout(function(){
		var img = $(this).attr('src');
		
		if(img.indexOf(".jpg") != -1){
			img = img.replace(".on.jpg",".off.jpg");
		}else if(img.indexOf(".png") != -1){
			img = img.replace(".on.png",".off.png");
		}
		$(this).attr( {src: img} );
	});

}



/*
$.blockUI.defaults = { 
   message:  '', 
   css: { 
        padding:        0, 
        margin:         0, 
        width:          '30%', 
        top:            '40%', 
        left:           '35%', 
        textAlign:      'center', 
        color:          '#000', 
        border:         'none', 
        cursor:         'wait' 
    }, 
 
    overlayCSS:  { 
        backgroundColor: '#000', 
        opacity:         0.6 
    } 
}; 
*/


function openMessage(titolo, message, showbutton, onClose) {
	$("#dialog").dialog('destroy');
	$("#dialog").attr('title', titolo);
	$("#dialog_text").html(message);
	if (showbutton == false) {
		var bottoni = {};
	} else {
		var bottoni = {
			Ok: function() {
				$(this).dialog('close');
				$("#dialog").attr('title', '');
				$(this).dialog('destroy');
				if(onClose) { functionAfterClose(onClose); };
			}
		}	
	}
	$("#dialog").dialog({
		bgiframe: true,
		modal: true,
		autoOpen: false,
		width: 300,
		resizable: false,
		buttons: bottoni,
		close: function(event, ui) { $(this).dialog('destroy'); if(onClose) { functionAfterClose(onClose); }; }
	});
	
	// TOPPA PER RISOLVERE BUG SUL COMPONENTE INIZIO
	$('#ui-dialog-title-dialog').html(titolo);
	// TOPPA PER RISOLVERE BUG SUL COMPONENTE FINE
	$('#dialog').dialog('open');
	
}

function functionAfterClose(azione) {
	if (azione == "refresh") {
		window.location.reload( false );
		document.location.href = document.location.href;
	}else if(azione == "baktoHome") {
		document.location.href = BASE_URL;	
		
	}
}




function setBoxAzioni (){
	
	/*
	VOCI MENU AZIONI
	*/
	$('.js_btn_azione').click(function () { 
		var id = "#box_"+ $(this).attr('id');
		if($(id).css("display") == 'none'){			
			$(".box_azione").each(function (i) {
				if ($(this).css("display") != 'none'){
					$(this).slideUp("slow");
				}
			});	
			
			$(id).slideDown("slow");
		}else{
			$(id).slideUp("slow");
		}
		$(id+' .scroll-pane').addClass('pane1');
		setTimeout(setScrollPanel,500);
	});
	
	/*
	TASTO CHIUDI
	*/
	$('.js_chiudi_box_azione').click(function () { 
		var id = "#"+$(this).parent().attr("id");
		$(id).slideUp("slow");
   });
	
}

function setBoxCustom(){	
	$('#color1').colorPicker();
	$('#color2').colorPicker();
	$('#color3').colorPicker();
}
function setMipiace() {
	if ($(".mipiace")) {
		$(".mipiace").click(function() { 
			addLike($(this).attr("rel"));
		});
	}	
}
function setMipiaceBlock() {
	if ($(".mipiace")) {
		$(".mipiace").click(function() { 
			openMessage('Messaggio', 'Registrati per esprimere il tuo gradimento.');	
		});
	}	
}
function addLike(id) {
	$.ajax({
		type: "POST",
		url: BASE_URL + 'mipiace.php',
		data: "id_media="+id,
		success: function(msg) {
			if(msg.indexOf('OK') == -1){
				openMessage('Errore', msg);
			}else{
				openMessage('Messaggio', 'Il tuo gradimento &egrave; stato registrato con successo.');	
			}
		}
	});
}
