$(document).ready(function(){
    
	qm_create(0,false,0,200,false,false,false,false,false);

    $.ajax({
        url:document.getElementById("logout") ? 'messaggi-manager.php?action=edit' : 'home.php',
        cache: false,
        beforeSend: function(){
            $('#main').fadeOut('slow');
            $('#loading').fadeIn('slow');
        },
        success: function(html){
            $('#loading').fadeOut('slow');
            $('#main').fadeIn('slow').html(html);
        },
        complete: function(){

        }
    });
    
	$('a.internal,report_row').click(function(event){
		event.preventDefault();
		var el = this;
		$.ajax({
			url: el.href,
			cache: false,
			beforeSend: function(){
				$('#main').fadeOut('slow');
				$('#loading').fadeIn('slow');
			},
			success: function(html){
				$('#loading').fadeOut('slow');
				$('#main').fadeIn('slow').html(html);
			},
			complete: function(){
				bindEvents();
			}
		});
	});
});

function bindEvents(){
    $('#dataEntry').submit(function(e){
       e.preventDefault();
       $(this).ajaxSubmit({
            url:$('#actionUrl').val(),
            target: '#main',
            complete:function(){
                bindEvents();
                $('#main').load($('#actionUrl').val());
            }
        });
        
        return false; // <-- important!
    });

    $('a.sublink').click(function(event){
		event.preventDefault();
		var el = this;
		$.ajax({
			url: el.href,
			cache: false,
			beforeSend: function(){
				$('#main').fadeOut('slow');
				$('#loading').fadeIn('slow');
			},
			success: function(html){
				$('#loading').fadeOut('slow');
				$('#main').fadeIn('slow').html(html);
			},
			complete: function(){
				bindEvents();
			}
		});
	});
     /*
     tinyMCE.init({
         theme : "advanced",
         mode: "exact",
         elements : "testo,body",
         theme_advanced_toolbar_location : "top",
         theme_advanced_buttons1 : "bold,italic,underline,strikethrough,separator,"
         + "justifyleft,justifycenter,justifyright,justifyfull,formatselect,"
         + "bullist,numlist,outdent,indent",
         theme_advanced_buttons2 : "link,unlink,anchor,image,separator,"
         +"undo,redo,cleanup,code,separator,sub,sup,charmap",
         theme_advanced_buttons3 : "",
         height:"200px",
         width:"600px",
         file_browser_callback : 'myFileBrowser'
  });
   */


}
function startLyteboxGallery(url_original){

    var anchor = this.document.createElement('a');
    anchor.setAttribute('href', url_original);
    anchor.setAttribute('rel', 'lytebox');
    myLytebox.start(anchor);
    return false;
}