jQuery(function() {

	/*
        Italian initialisation for the jQuery UI date picker plugin.
        Written by Apaella (apae...@gmail.com).
        Version 1.5b2
*/

jQuery(function($){
   
        $.datepicker.regional['it'] = {
            clearText: 'Svuota', clearStatus: '',
                clearStatus: 'Cancella la data corrente',
                closeText: 'Chiudi', closeStatus: '',
                closeStatus: 'Chiudi senza cambiamenti',
                prevText: '&lt;Prec', prevStatus: '',
                prevStatus: 'Mostra il mese precedente',
                nextText: 'Succ&gt;', nextStatus: '',
                nextStatus: 'Mostra il mese successivo',
                currentText: 'Oggi', currentStatus: '',
                currentStatus: 'Mostra il mese corrente',
                monthNames:
['Gennaio','Febbraio','Marzo','Aprile','Maggio','Giugno',
                'Luglio','Agosto','Settembre','Ottobre','Novembre','Dicembre'],
                monthNamesShort: ['Gen','Feb','Mar','Apr','Mag','Giu',
                'Lug','Ago','Set','Ott','Nov','Dic'],
                monthStatus: 'Mostra un altro mese',
                yearStatus: 'Mostra un altro anno',
                weekHeader: 'Sm', weekStatus: '',
                weekStatus: 'Settimana dell\'anno',
                dayNames:
['Domenica','Luned&#236','Marted&#236','Mercoled&#236','Gioved&#236','Venerd&#236','Sabato'],
                dayNamesShort: ['Dom','Lun','Mar','Mer','Gio','Ven','Sab'],
                dayNamesMin: ['Do','Lu','Ma','Me','Gio','Ve','Sa'],
                dayStatus: 'Imposta DD come primo giorno della settimana',
                dateStatus: 'Seleziona DD, M d',
                dateFormat: 'dd/mm/yy', firstDay: 1,
                initStatus: 'Seleziona una data',
                isRTL: false
        };
        $.datepicker.setDefaults($.datepicker.regional['it']);
}); 


            jQuery("#body").wymeditor({lang: 'it', name: 'body', toolsItems: [
                                                                              {'name': 'Bold', 'title': 'Strong', 'css': 'wym_tools_strong'}, 
                                                                              {'name': 'Italic', 'title': 'Emphasis', 'css': 'wym_tools_emphasis'},
                                                                              {'name': 'Superscript', 'title': 'Superscript', 'css': 'wym_tools_superscript'},
                                                                              {'name': 'Subscript', 'title': 'Subscript', 'css': 'wym_tools_subscript'},
                                                                              {'name': 'InsertOrderedList', 'title': 'Ordered_List', 'css': 'wym_tools_ordered_list'},
                                                                              {'name': 'InsertUnorderedList', 'title': 'Unordered_List', 'css': 'wym_tools_unordered_list'},
                                                                              {'name': 'Indent', 'title': 'Indent', 'css': 'wym_tools_indent'},
                                                                              {'name': 'Outdent', 'title': 'Outdent', 'css': 'wym_tools_outdent'},
                                                                              {'name': 'Undo', 'title': 'Undo', 'css': 'wym_tools_undo'},
                                                                              {'name': 'Redo', 'title': 'Redo', 'css': 'wym_tools_redo'},
                                                                              {'name': 'InsertTable', 'title': 'Table', 'css': 'wym_tools_table'},
                                                                              {'name': 'Paste', 'title': 'Paste_From_Word', 'css': 'wym_tools_paste'},
                                                                              {'name': 'ToggleHtml', 'title': 'HTML', 'css': 'wym_tools_html'},
                                                                              {'name': 'Preview', 'title': 'Preview', 'css': 'wym_tools_preview'},
                                                                               {'name': 'CreateLink', 'title': 'Link', 'css': 'wym_tools_link'},
                                                                               {'name': 'Unlink', 'title': 'Unlink', 'css': 'wym_tools_unlink'},
   
                                                                             ], containersHtml: '', classesHtml: ''
                                        });
               jQuery("#short_body").wymeditor({lang: 'it', name: 'body', toolsItems: [
                                                                              {'name': 'Bold', 'title': 'Strong', 'css': 'wym_tools_strong'}, 
                                                                              {'name': 'Italic', 'title': 'Emphasis', 'css': 'wym_tools_emphasis'},
                                                                              {'name': 'Superscript', 'title': 'Superscript', 'css': 'wym_tools_superscript'},
                                                                              {'name': 'Subscript', 'title': 'Subscript', 'css': 'wym_tools_subscript'},
                                                                              {'name': 'InsertOrderedList', 'title': 'Ordered_List', 'css': 'wym_tools_ordered_list'},
                                                                              {'name': 'InsertUnorderedList', 'title': 'Unordered_List', 'css': 'wym_tools_unordered_list'},
                                                                              {'name': 'Indent', 'title': 'Indent', 'css': 'wym_tools_indent'},
                                                                              {'name': 'Outdent', 'title': 'Outdent', 'css': 'wym_tools_outdent'},
                                                                              {'name': 'Undo', 'title': 'Undo', 'css': 'wym_tools_undo'},
                                                                              {'name': 'Redo', 'title': 'Redo', 'css': 'wym_tools_redo'},
                                                                              {'name': 'InsertTable', 'title': 'Table', 'css': 'wym_tools_table'},
                                                                              {'name': 'Paste', 'title': 'Paste_From_Word', 'css': 'wym_tools_paste'},
                                                                              {'name': 'ToggleHtml', 'title': 'HTML', 'css': 'wym_tools_html'},
                                                                              {'name': 'Preview', 'title': 'Preview', 'css': 'wym_tools_preview'},
                                                                               {'name': 'CreateLink', 'title': 'Link', 'css': 'wym_tools_link'},
                                                                               {'name': 'Unlink', 'title': 'Unlink', 'css': 'wym_tools_unlink'},
   
                                                                             ], containersHtml: '', classesHtml: ''
                                        });
    
    
    	
    	
    // binding click event on "Add photogallery photo" article form button and do the logic to add new photogallery photo input elements
   	
    $("button#addphotogalleryphoto").click(function () {
    
	    		  var elements_number = $('.photogallery-photos-group').length;
			      var id_attribute = $('.photogallery-photos-group').eq(elements_number-1).attr("id");
			      if (id_attribute) {
				      // processing the id attribute of the last button element inserted to extract the array index
				      id_attribute = id_attribute.slice(5, id_attribute.length);
				      id_attribute = parseInt(id_attribute);
				      $(this).parent().before('<li class="element-group photobox"><h3 style="margin: 0;margin-bottom: 30px">Inserisci foto</h3><label class="photogallery-photos-group required" for="photo' + (id_attribute + 1) + '">Inserisci una foto per la foto gallery</label> <input type="file" class="photogallery-photos-group" value="" id="photo' + (id_attribute + 1) +'" name="photo[]"/></li><li class="photogallery-photo-description"><label class="required" for="description'+ (id_attribute + 1) +'">Descrizione foto</label><input type="text" value="" id="description'+ (id_attribute + 1) +'" name="photo-description[]"/></li><li class="remove-photogallery-photo" id="remove-photogallery-photo-' + (id_attribute + 1) + '"><button value="Rimuovi la foto" type="button">Rimuovi la foto</button></li>'); 
				  } else {
				  	$(this).parent().before('<li class="element-group photobox"><h3 style="margin: 0;margin-bottom: 30px">Inserisci foto</h3><label class="photogallery-photos-group required" for="photo0">Inserisci una foto per la foto gallery</label> <input type="file" class="photogallery-photos-group" value="" id="photo0" name="photo[]"/></li><li class="photogallery-photo-description"><label class="required" for="description0">Descrizione foto</label><input type="text" value="" id="description0" name="photo-description[]"/></li><li class="remove-photogallery-photo" id="remove-photogallery-photo-0"><button value="Rimuovi la foto" type="button">Rimuovi la foto</button></li>'); 
				  }
	    	
    	}); 
    
    	
    	// different logic for the edit article and news edit form
    	
    	$("button#addphotogalleryphotoeditform").click(function () {
    	
    		var elements_number = $('.photogallery-photos-group').length;
			      var id_attribute = $('.photogallery-photos-group').eq(elements_number-1).attr("id");
			      if (id_attribute) {
				      // processing the id attribute of the last button element inserted to extract the array index
				      id_attribute = id_attribute.slice(5, id_attribute.length);
				      id_attribute = parseInt(id_attribute);
				      $(this).parent().before('<li class="element-group photobox"><h3 style="margin: 0;margin-bottom: 30px">Inserisci foto</h3><label class="photogallery-photos-group required" for="photo' + (id_attribute + 1) + '">Inserisci una foto per la foto gallery</label> <input type="file" class="photogallery-photos-group" value="" id="photo' + (id_attribute + 1) +'" name="photo[]"/></li><li class="photogallery-photo-description"><label class="required" for="description'+ (id_attribute + 1) +'">Descrizione foto</label><input type="text" value="" id="description'+ (id_attribute + 1) +'" name="photo-description[]"/></li><li class="remove-photogallery-photo" id="remove-photogallery-photo-' + (id_attribute + 1) + '"><button value="Rimuovi la foto" type="button">Rimuovi la foto</button></li>'); 
				  } else {
				  	$(this).parent().before('<li class="element-group photobox"><h3 style="margin: 0;margin-bottom: 30px">Inserisci foto</h3><label class="photogallery-photos-group required" for="photo0">Inserisci una foto per la foto gallery</label> <input type="file" class="photogallery-photos-group" value="" id="photo0" name="photo[]"/></li><li class="photogallery-photo-description"><label class="required" for="description0">Descrizione foto</label><input type="text" value="" id="description0" name="photo-description[]"/></li><li class="remove-photogallery-photo" id="remove-photogallery-photo-0"><button value="Rimuovi la foto" type="button">Rimuovi la foto</button></li>'); 
				  }
    	
    	});
     
    
   
    $("#date").datepicker(
    {showStatus: true});
    
    
    
    	
    
 
     
   	 // binding click event on "Remove photogallery photo" buttons
   
     $(".remove-photogallery-photo").livequery('click', function () { 
      	var remove_button_id = $(this).attr('id');
      	var remove_button_id_number = remove_button_id.slice(26, remove_button_id.length);
      	$("#description" + remove_button_id_number).parent().remove();
      	$("#photo" + remove_button_id_number).parent().remove();
      	$("#" + remove_button_id).remove();
      	
     });
     
     
    // binding the ajax submit event to the article form to validate the form in ajax to prevent to lost photogallery photo elements on validate
    // first assign a div only to those elements who need validation and need to be replaced by html server respnse on ajax (follow the news equivalent)
    
     // Article part
    
    $('#InserimentoArticolo').ajaxForm({url: '/articolo/nuovo', type: 'POST', success: function(data) {
    	if (data != '1' && data != '0') {
	    	$('#fieldset-ajaxformreplace').html(data);
	    	
	    	jQuery("#body").wymeditor({lang: 'it', name: 'body', toolsItems: [
	    	                                                                  {'name': 'Bold', 'title': 'Strong', 'css': 'wym_tools_strong'}, 
	    	                                                                  {'name': 'Italic', 'title': 'Emphasis', 'css': 'wym_tools_emphasis'},
	    	                                                                  {'name': 'Superscript', 'title': 'Superscript', 'css': 'wym_tools_superscript'},
	    	                                                                  {'name': 'Subscript', 'title': 'Subscript', 'css': 'wym_tools_subscript'},
	    	                                                                  {'name': 'InsertOrderedList', 'title': 'Ordered_List', 'css': 'wym_tools_ordered_list'},
	    	                                                                  {'name': 'InsertUnorderedList', 'title': 'Unordered_List', 'css': 'wym_tools_unordered_list'},
	    	                                                                  {'name': 'Indent', 'title': 'Indent', 'css': 'wym_tools_indent'},
	    	                                                                  {'name': 'Outdent', 'title': 'Outdent', 'css': 'wym_tools_outdent'},
	    	                                                                  {'name': 'Undo', 'title': 'Undo', 'css': 'wym_tools_undo'},
	    	                                                                  {'name': 'Redo', 'title': 'Redo', 'css': 'wym_tools_redo'},
	    	                                                                  {'name': 'InsertTable', 'title': 'Table', 'css': 'wym_tools_table'},
	    	                                                                  {'name': 'Paste', 'title': 'Paste_From_Word', 'css': 'wym_tools_paste'},
	    	                                                                  {'name': 'ToggleHtml', 'title': 'HTML', 'css': 'wym_tools_html'},
	    	                                                                  {'name': 'Preview', 'title': 'Preview', 'css': 'wym_tools_preview'},
                                                                               {'name': 'CreateLink', 'title': 'Link', 'css': 'wym_tools_link'},
                                                                               {'name': 'Unlink', 'title': 'Unlink', 'css': 'wym_tools_unlink'},
   
	    	                                                                 ], containersHtml: '', classesHtml: ''
	    	                            });
                      jQuery("#short_body").wymeditor({lang: 'it', name: 'body', toolsItems: [
                                                                              {'name': 'Bold', 'title': 'Strong', 'css': 'wym_tools_strong'}, 
                                                                              {'name': 'Italic', 'title': 'Emphasis', 'css': 'wym_tools_emphasis'},
                                                                              {'name': 'Superscript', 'title': 'Superscript', 'css': 'wym_tools_superscript'},
                                                                              {'name': 'Subscript', 'title': 'Subscript', 'css': 'wym_tools_subscript'},
                                                                              {'name': 'InsertOrderedList', 'title': 'Ordered_List', 'css': 'wym_tools_ordered_list'},
                                                                              {'name': 'InsertUnorderedList', 'title': 'Unordered_List', 'css': 'wym_tools_unordered_list'},
                                                                              {'name': 'Indent', 'title': 'Indent', 'css': 'wym_tools_indent'},
                                                                              {'name': 'Outdent', 'title': 'Outdent', 'css': 'wym_tools_outdent'},
                                                                              {'name': 'Undo', 'title': 'Undo', 'css': 'wym_tools_undo'},
                                                                              {'name': 'Redo', 'title': 'Redo', 'css': 'wym_tools_redo'},
                                                                              {'name': 'InsertTable', 'title': 'Table', 'css': 'wym_tools_table'},
                                                                              {'name': 'Paste', 'title': 'Paste_From_Word', 'css': 'wym_tools_paste'},
                                                                              {'name': 'ToggleHtml', 'title': 'HTML', 'css': 'wym_tools_html'},
                                                                              {'name': 'Preview', 'title': 'Preview', 'css': 'wym_tools_preview'},
                                                                               {'name': 'CreateLink', 'title': 'Link', 'css': 'wym_tools_link'},
                                                                               {'name': 'Unlink', 'title': 'Unlink', 'css': 'wym_tools_unlink'},
   
                                                                             ], containersHtml: '', classesHtml: ''
                                        });
	    	
	    	 $("#date").datepicker(
	    		{showStatus: true});
	    		
	    	// to style (not float left) the label of the textarea (body of the article with the wyswyg editor) in the new article form page
		   
		   $('#body').prev().css('float','none');
		   $('#body').next().css('marginTop','15px');
		   $('#body').parent().css('paddingTop','15px');
		   $('#body').parent().css('paddingBottom','15px');
	    	
	    	$('#article_form').css('marginLeft','auto');
		   $('#article_form').css('marginRight','auto');
		} else  {
			window.location = '/admin/gestione-articoli/pagina/1';
		}
	   
    }, beforeSend: function() {
    // display a progress bar indicator when the "Article and news form"  are submitted
    	$('#article_form').css('position', 'relative');
    		$('#InserimentoArticolo').css('opacity', 0.5);
    		$("#article_form").append('<div id="bar-container"><img src="/images/pleasewait.gif" alt="" /></div>');
    		$('#bar-container').width(214);
    		$('#bar-container').height(15);
    		$("#bar-container").css({backgroundColor: '#ffffff',backgroundImage: 'url(/images/pleasewait.gif)', backgroundRepeat: 'no-repeat',position: 'absolute', bottom: '150px', left: '193px', opacity: 1});		
    }, complete: function() {
    	$('#InserimentoArticolo').css('opacity', 1);
    		$("#bar-container").remove();
    		
    }
    });
    
    
  
    
     
     $('#ModificaArticolo').ajaxForm({url: location.href, type: 'POST', success: function(data) {
    	if (data != '1' && data != '0') {
	    	$('#fieldset-ajaxformreplace').html(data);
	    	
	    	             jQuery("#body").wymeditor({lang: 'it', name: 'body', toolsItems: [
                                                                              {'name': 'Bold', 'title': 'Strong', 'css': 'wym_tools_strong'}, 
                                                                              {'name': 'Italic', 'title': 'Emphasis', 'css': 'wym_tools_emphasis'},
                                                                              {'name': 'Superscript', 'title': 'Superscript', 'css': 'wym_tools_superscript'},
                                                                              {'name': 'Subscript', 'title': 'Subscript', 'css': 'wym_tools_subscript'},
                                                                              {'name': 'InsertOrderedList', 'title': 'Ordered_List', 'css': 'wym_tools_ordered_list'},
                                                                              {'name': 'InsertUnorderedList', 'title': 'Unordered_List', 'css': 'wym_tools_unordered_list'},
                                                                              {'name': 'Indent', 'title': 'Indent', 'css': 'wym_tools_indent'},
                                                                              {'name': 'Outdent', 'title': 'Outdent', 'css': 'wym_tools_outdent'},
                                                                              {'name': 'Undo', 'title': 'Undo', 'css': 'wym_tools_undo'},
                                                                              {'name': 'Redo', 'title': 'Redo', 'css': 'wym_tools_redo'},
                                                                              {'name': 'InsertTable', 'title': 'Table', 'css': 'wym_tools_table'},
                                                                              {'name': 'Paste', 'title': 'Paste_From_Word', 'css': 'wym_tools_paste'},
                                                                              {'name': 'ToggleHtml', 'title': 'HTML', 'css': 'wym_tools_html'},
                                                                              {'name': 'Preview', 'title': 'Preview', 'css': 'wym_tools_preview'},
                                                                               {'name': 'CreateLink', 'title': 'Link', 'css': 'wym_tools_link'},
                                                                               {'name': 'Unlink', 'title': 'Unlink', 'css': 'wym_tools_unlink'},
   
                                                                             ], containersHtml: '', classesHtml: ''
                                        });
               jQuery("#short_body").wymeditor({lang: 'it', name: 'body', toolsItems: [
                                                                              {'name': 'Bold', 'title': 'Strong', 'css': 'wym_tools_strong'}, 
                                                                              {'name': 'Italic', 'title': 'Emphasis', 'css': 'wym_tools_emphasis'},
                                                                              {'name': 'Superscript', 'title': 'Superscript', 'css': 'wym_tools_superscript'},
                                                                              {'name': 'Subscript', 'title': 'Subscript', 'css': 'wym_tools_subscript'},
                                                                              {'name': 'InsertOrderedList', 'title': 'Ordered_List', 'css': 'wym_tools_ordered_list'},
                                                                              {'name': 'InsertUnorderedList', 'title': 'Unordered_List', 'css': 'wym_tools_unordered_list'},
                                                                              {'name': 'Indent', 'title': 'Indent', 'css': 'wym_tools_indent'},
                                                                              {'name': 'Outdent', 'title': 'Outdent', 'css': 'wym_tools_outdent'},
                                                                              {'name': 'Undo', 'title': 'Undo', 'css': 'wym_tools_undo'},
                                                                              {'name': 'Redo', 'title': 'Redo', 'css': 'wym_tools_redo'},
                                                                              {'name': 'InsertTable', 'title': 'Table', 'css': 'wym_tools_table'},
                                                                              {'name': 'Paste', 'title': 'Paste_From_Word', 'css': 'wym_tools_paste'},
                                                                              {'name': 'ToggleHtml', 'title': 'HTML', 'css': 'wym_tools_html'},
                                                                              {'name': 'Preview', 'title': 'Preview', 'css': 'wym_tools_preview'},
                                                                               {'name': 'CreateLink', 'title': 'Link', 'css': 'wym_tools_link'},
                                                                               {'name': 'Unlink', 'title': 'Unlink', 'css': 'wym_tools_unlink'},
   
                                                                             ], containersHtml: '', classesHtml: ''
                                        });
	    	
	    	 $("#date").datepicker(
	    		{showStatus: true});
	    		
	    	// to style (not float left) the label of the textarea (body of the article with the wyswyg editor) in the new article form page
		   
		   $('#body').prev().css('float','none');
		   $('#body').next().css('marginTop','15px');
		   $('#body').parent().css('paddingTop','15px');
		   $('#body').parent().css('paddingBottom','15px');
	    	
	    	$('#article_form').css('marginLeft','auto');
		   $('#article_form').css('marginRight','auto');
		} else {
			window.location = '/admin/gestione-articoli/pagina/1';
		}
	   
    }, beforeSend: function() {
    // display a progress bar indicator when the "Edit Article and edit news Form" are submitted
    	$('#article_form').css('position', 'relative');
    		$('#ModificaArticolo').css('opacity', 0.5);
    		$("#article_form").append('<div id="bar-container"><img src="/images/pleasewait.gif" alt="" /></div>');
    		$('#bar-container').width(214);
    		$('#bar-container').height(15);
    		$("#bar-container").css({backgroundColor: '#ffffff',backgroundImage: 'url(/images/pleasewait.gif)', backgroundRepeat: 'no-repeat',position: 'absolute', bottom: '150px', left: '193px', opacity: 1});		
    }, complete: function() {
    	$('#ModificaArticolo').css('opacity', 1);
    		$("#bar-container").remove();
    		
    }
    });
    
     	
     	// News part
     
     $('#InserimentoNotizia').ajaxForm({url: '/notizia/nuova', type: 'POST', success: function(data) {
     	if (data != '1' && data != '0') {
 	    	$('#fieldset-ajaxformreplace').html(data);
            jQuery("#body").wymeditor({lang: 'it', name: 'body', toolsItems: [
                                                                              {'name': 'Bold', 'title': 'Strong', 'css': 'wym_tools_strong'}, 
                                                                              {'name': 'Italic', 'title': 'Emphasis', 'css': 'wym_tools_emphasis'},
                                                                              {'name': 'Superscript', 'title': 'Superscript', 'css': 'wym_tools_superscript'},
                                                                              {'name': 'Subscript', 'title': 'Subscript', 'css': 'wym_tools_subscript'},
                                                                              {'name': 'InsertOrderedList', 'title': 'Ordered_List', 'css': 'wym_tools_ordered_list'},
                                                                              {'name': 'InsertUnorderedList', 'title': 'Unordered_List', 'css': 'wym_tools_unordered_list'},
                                                                              {'name': 'Indent', 'title': 'Indent', 'css': 'wym_tools_indent'},
                                                                              {'name': 'Outdent', 'title': 'Outdent', 'css': 'wym_tools_outdent'},
                                                                              {'name': 'Undo', 'title': 'Undo', 'css': 'wym_tools_undo'},
                                                                              {'name': 'Redo', 'title': 'Redo', 'css': 'wym_tools_redo'},
                                                                              {'name': 'InsertTable', 'title': 'Table', 'css': 'wym_tools_table'},
                                                                              {'name': 'Paste', 'title': 'Paste_From_Word', 'css': 'wym_tools_paste'},
                                                                              {'name': 'ToggleHtml', 'title': 'HTML', 'css': 'wym_tools_html'},
                                                                              {'name': 'Preview', 'title': 'Preview', 'css': 'wym_tools_preview'},
                                                                               {'name': 'CreateLink', 'title': 'Link', 'css': 'wym_tools_link'},
                                                                               {'name': 'Unlink', 'title': 'Unlink', 'css': 'wym_tools_unlink'},
   
                                                                             ], containersHtml: '', classesHtml: ''
                                        });
                         jQuery("#short_body").wymeditor({lang: 'it', name: 'body', toolsItems: [
                                                                              {'name': 'Bold', 'title': 'Strong', 'css': 'wym_tools_strong'}, 
                                                                              {'name': 'Italic', 'title': 'Emphasis', 'css': 'wym_tools_emphasis'},
                                                                              {'name': 'Superscript', 'title': 'Superscript', 'css': 'wym_tools_superscript'},
                                                                              {'name': 'Subscript', 'title': 'Subscript', 'css': 'wym_tools_subscript'},
                                                                              {'name': 'InsertOrderedList', 'title': 'Ordered_List', 'css': 'wym_tools_ordered_list'},
                                                                              {'name': 'InsertUnorderedList', 'title': 'Unordered_List', 'css': 'wym_tools_unordered_list'},
                                                                              {'name': 'Indent', 'title': 'Indent', 'css': 'wym_tools_indent'},
                                                                              {'name': 'Outdent', 'title': 'Outdent', 'css': 'wym_tools_outdent'},
                                                                              {'name': 'Undo', 'title': 'Undo', 'css': 'wym_tools_undo'},
                                                                              {'name': 'Redo', 'title': 'Redo', 'css': 'wym_tools_redo'},
                                                                              {'name': 'InsertTable', 'title': 'Table', 'css': 'wym_tools_table'},
                                                                              {'name': 'Paste', 'title': 'Paste_From_Word', 'css': 'wym_tools_paste'},
                                                                              {'name': 'ToggleHtml', 'title': 'HTML', 'css': 'wym_tools_html'},
                                                                              {'name': 'Preview', 'title': 'Preview', 'css': 'wym_tools_preview'},
                                                                               {'name': 'CreateLink', 'title': 'Link', 'css': 'wym_tools_link'},
                                                                               {'name': 'Unlink', 'title': 'Unlink', 'css': 'wym_tools_unlink'},
   
                                                                             ], containersHtml: '', classesHtml: ''
                                        });
 	    	
 	    	 $("#date").datepicker(
 	    		{showStatus: true});
 	    		
 	    	// to style (not float left) the label of the textarea (body of the article with the wyswyg editor) in the new article form page
 		   
 		   $('#body').prev().css('float','none');
 		   $('#body').next().css('marginTop','15px');
 		   $('#body').parent().css('paddingTop','15px');
 		   $('#body').parent().css('paddingBottom','15px');
 	    	
 	    	$('#news_form').css('marginLeft','auto');
 		   $('#news_form').css('marginRight','auto');
 		} else  {
 			window.location = '/admin/gestione-notizie/pagina/1';
 		}
 	   
     }, beforeSend: function() {
     // display a progress bar indicator when the  news form is submitted
     	$('#news_form').css('position', 'relative');
     		$('#InserimentoNotizia').css('opacity', 0.5);
     		$("#news_form").append('<div id="bar-container"><img src="/images/pleasewait.gif" alt="" /></div>');
     		$('#bar-container').width(214);
     		$('#bar-container').height(15);
     		$("#bar-container").css({backgroundColor: '#ffffff',backgroundImage: 'url(/images/pleasewait.gif)', backgroundRepeat: 'no-repeat',position: 'absolute', bottom: '150px', left: '193px', opacity: 1});		
     }, complete: function() {
     	$('#InserimentoNotizia').css('opacity', 1);
     		$("#bar-container").remove();
     		
     }
     });
     
       
      
      $('#ModificaNotizia').ajaxForm({url: location.href, type: 'POST', success: function(data) {
     	if (data != '1' && data != '0') {
 	    	$('#fieldset-ajaxformreplace').html(data);
 	    	             jQuery("#body").wymeditor({lang: 'it', name: 'body', toolsItems: [
                                                                              {'name': 'Bold', 'title': 'Strong', 'css': 'wym_tools_strong'}, 
                                                                              {'name': 'Italic', 'title': 'Emphasis', 'css': 'wym_tools_emphasis'},
                                                                              {'name': 'Superscript', 'title': 'Superscript', 'css': 'wym_tools_superscript'},
                                                                              {'name': 'Subscript', 'title': 'Subscript', 'css': 'wym_tools_subscript'},
                                                                              {'name': 'InsertOrderedList', 'title': 'Ordered_List', 'css': 'wym_tools_ordered_list'},
                                                                              {'name': 'InsertUnorderedList', 'title': 'Unordered_List', 'css': 'wym_tools_unordered_list'},
                                                                              {'name': 'Indent', 'title': 'Indent', 'css': 'wym_tools_indent'},
                                                                              {'name': 'Outdent', 'title': 'Outdent', 'css': 'wym_tools_outdent'},
                                                                              {'name': 'Undo', 'title': 'Undo', 'css': 'wym_tools_undo'},
                                                                              {'name': 'Redo', 'title': 'Redo', 'css': 'wym_tools_redo'},
                                                                              {'name': 'InsertTable', 'title': 'Table', 'css': 'wym_tools_table'},
                                                                              {'name': 'Paste', 'title': 'Paste_From_Word', 'css': 'wym_tools_paste'},
                                                                              {'name': 'ToggleHtml', 'title': 'HTML', 'css': 'wym_tools_html'},
                                                                              {'name': 'Preview', 'title': 'Preview', 'css': 'wym_tools_preview'},
                                                                               {'name': 'CreateLink', 'title': 'Link', 'css': 'wym_tools_link'},
                                                                               {'name': 'Unlink', 'title': 'Unlink', 'css': 'wym_tools_unlink'},
   
                                                                             ], containersHtml: '', classesHtml: ''
                                        });
                jQuery("#short_body").wymeditor({lang: 'it', name: 'body', toolsItems: [
                                                                              {'name': 'Bold', 'title': 'Strong', 'css': 'wym_tools_strong'}, 
                                                                              {'name': 'Italic', 'title': 'Emphasis', 'css': 'wym_tools_emphasis'},
                                                                              {'name': 'Superscript', 'title': 'Superscript', 'css': 'wym_tools_superscript'},
                                                                              {'name': 'Subscript', 'title': 'Subscript', 'css': 'wym_tools_subscript'},
                                                                              {'name': 'InsertOrderedList', 'title': 'Ordered_List', 'css': 'wym_tools_ordered_list'},
                                                                              {'name': 'InsertUnorderedList', 'title': 'Unordered_List', 'css': 'wym_tools_unordered_list'},
                                                                              {'name': 'Indent', 'title': 'Indent', 'css': 'wym_tools_indent'},
                                                                              {'name': 'Outdent', 'title': 'Outdent', 'css': 'wym_tools_outdent'},
                                                                              {'name': 'Undo', 'title': 'Undo', 'css': 'wym_tools_undo'},
                                                                              {'name': 'Redo', 'title': 'Redo', 'css': 'wym_tools_redo'},
                                                                              {'name': 'InsertTable', 'title': 'Table', 'css': 'wym_tools_table'},
                                                                              {'name': 'Paste', 'title': 'Paste_From_Word', 'css': 'wym_tools_paste'},
                                                                              {'name': 'ToggleHtml', 'title': 'HTML', 'css': 'wym_tools_html'},
                                                                              {'name': 'Preview', 'title': 'Preview', 'css': 'wym_tools_preview'},
                                                                               {'name': 'CreateLink', 'title': 'Link', 'css': 'wym_tools_link'},
                                                                               {'name': 'Unlink', 'title': 'Unlink', 'css': 'wym_tools_unlink'},
   
                                                                             ], containersHtml: '', classesHtml: ''
                                        });
 	    	
 	    	 $("#date").datepicker(
 	    		{showStatus: true});
 	    		
 	    	// to style (not float left) the label of the textarea (body of the news with the wyswyg editor) in the new news form page
 		   
 		   $('#body').prev().css('float','none');
 		   $('#body').next().css('marginTop','15px');
 		   $('#body').parent().css('paddingTop','15px');
 		   $('#body').parent().css('paddingBottom','15px');
 	    	
 	    	$('#article_form').css('marginLeft','auto');
 		   $('#article_form').css('marginRight','auto');
 		} else {
 			window.location = '/admin/gestione-notizie/pagina/1';
 		}
 	   
     }, beforeSend: function() {
     // display a progress bar indicator when the edit news Form is submitted
     	$('#news_form').css('position', 'relative');
     		$('#ModificaNotizia').css('opacity', 0.5);
     		$("#news_form").append('<div id="bar-container"><img src="/images/pleasewait.gif" alt="" /></div>');
     		$('#bar-container').width(214);
     		$('#bar-container').height(15);
     		$("#bar-container").css({backgroundColor: '#ffffff',backgroundImage: 'url(/images/pleasewait.gif)', backgroundRepeat: 'no-repeat',position: 'absolute', bottom: '150px', left: '193px', opacity: 1});		
     }, complete: function() {
     	$('#ModificaNotizia').css('opacity', 1);
     		$("#bar-container").remove();
     		
     }
     });
     
     
     
 
		// to activate the photogalleries

		// when clicking the article photogallery link (on the article page) open the article photogallery via ajax. When javascript is not enable on the client load the photogallery normally in a new page following the normal link
		           
        $("#article-photogallery").click(function (event) {
        	event.preventDefault(); 
        	
        	if ($('#jqGS0').length == 0) { // do this only if  there isn't already loaded the fotogallery container
        	var article_photogallery_link = $(this).attr('href');
      		$.get(article_photogallery_link, function(data){
      			$("#media").append(data);
      			$("#media").css('position', 'relative');
      			$("#photogallery").jqGalScroll({height: 855, width: 675});
      			$('#jqGS0').width(675);
      			$('#jqGS0').append('<a id="close-photogallery" href="">Chiudi</a>');
      			$('#close-photogallery').css({position: 'absolute', top: '0', right: '0', backgroundColor: 'red', color: '#ffffff', padding: '3px', borderLeft: '1px solid #000000',borderBottom: '1px solid #000000', fontWeight: 'bold', textAlign: 'center'});
      			$('.jqGSImgContainer').css('border', 'none');
      			var photogallery_width = $('#jqGS0').width();
      			var photogallery_height = $('#jqGS0').height();
      			
      		
      			
      			$("#jqGS0").hide();
      			$("#jqGS0").show(3000);
      			
      				$("#jqGS0").css({backgroundColor: '#ffffff',border: '1px solid #000000', position: 'absolute', bottom: '-100px', left: '200px', opacity: 1});
      			
      				
      			
      			
      			$('#layout-wrapper').css('backgroundColor','#F0EEEF');	
      			$('.articolo_centrale').animate({opacity: 0.5}, 3000);
      			$('#media ul.media').animate({opacity: 0.5}, 3000);
      		
      		});
        	}
    	});
    	
    	// when clicking the news photogallery link (on the news page) open the news photogallery via ajax. When javascript is not enable on the client load the photogallery normally in a new page following the normal link
		           
        $("#news-photogallery").click(function (event) {
        	event.preventDefault();
        	if ($('#jqGS0').length == 0) { // do this only if  there isn't already loaded the fotogallery container
	        	
	        	var article_photogallery_link = $(this).attr('href');
	      		$.get(article_photogallery_link, function(data){
	      			$("#media").append(data);
	      			$("#media").css('position', 'relative');
	      			$("#photogallery").jqGalScroll({height: 855, width: 675});
	      			$('#jqGS0').width(675);
	      			$('#jqGS0').append('<a id="close-photogallery" href="">Chiudi</a>');
	      			$('#close-photogallery').css({position: 'absolute', top: '0', right: '0', color: '#ffffff', backgroundColor: 'red', padding: '3px',  borderLeft: '1px solid #000000',borderBottom: '1px solid #000000', fontWeight: 'bold', textAlign: 'center'});
	      			$('.jqGSImgContainer').css('border', 'none');
	      			var photogallery_width = $('#jqGS0').width();
	      			var photogallery_height = $('#jqGS0').height();
	      			
	      		
	      			
	      			$("#jqGS0").hide();
	      			
	      			$("#jqGS0").show(3000);
	      			
	      			
	      				$("#jqGS0").css({backgroundColor: '#ffffff',border: '1px solid #000000', position: 'absolute', bottom: '-100px' , left: '200px', opacity: 1});
	      			
	      			$('#layout-wrapper').css('backgroundColor','#F0EEEF');	
	      			$('.articolo_centrale').animate({opacity: 0.5}, 3000);
	      			$('#media ul.media').animate({opacity: 0.5}, 3000);
	      		
	      			
      			
      			
      
      		});
        	}
    	});
    	
    	// when clicking the close link on the photogallery remove the photogallery html from the page
    	
    	
    	$("#close-photogallery").livequery('click', function (event) {
        	event.preventDefault();
        	
	        	$("#jqGS0").fadeOut(3000, function(){$("#jqGS0").remove();}); 
	        	$('.articolo_centrale').animate({opacity: 1}, 3000);
      			$('#media ul.media').animate({opacity: 1}, 3000);
      			
	  		
    	});
    	
    	

   		// disable (visually reducing opacity) the "permalink" input field in the edit article form and in the edit news form
     	$('#ModificaArticolo input#permalink').css('opacity', 0.5);
     	$('#ModificaNotizia input#permalink').css('opacity', 0.5);
     	
     
     	// binding click/toggle event on the "Edita descrizione foto" link on the edit article form in the photogallery editing area of the form
     	$("a.photodesc").css({color: '#000000', width: '150px', marginTop: '13px', display: 'block', marginLeft: 'auto', marginRight: 'auto'}).hover(function() {
     		$(this).css('color','red');
     	}, function() {
     		$(this).css('color','#000000');
     	});
     	
     	$("a.photodesc").toggle(function (event) {
     		var photo_id = $(this).attr('id');
     		var photo_desc = $(this).attr('desc');
     		$(this).after("<li id='photodesc"+ photo_id +"'class='element-group'><label for='photodesc"+ photo_id +"'>Descrizione foto</label><input type='text' value='"+ photo_desc +"' name='photodesc["+ photo_id +"]' class='photodesc'/></li>");
     		$('li#photodesc'+photo_id).css('display','none').show('slow')
     		$(this).text('Rimuovi descrizione');
     	},function (event) {
     		var photo_id = $(this).attr('id');
     		$('li#photodesc'+photo_id).hide('slow', function() {
     			$('li#photodesc'+photo_id).remove();
     		});
     		$(this).text('Edita descrizione foto');
     	});
     	
     	// confirmation dialog when attempting to delete an article or news from the database in the relative admin management page
     	$('input.delete-article').click(function(event) {
     		 if (!confirm('Sei sicuro di voler eliminare questo articolo?')) {
     		 	event.preventDefault(); 
     		 }
     	});
   		$('input.delete-news').click(function(event) {
	   		 if (!confirm('Sei sicuro di voler eliminare questa notizia?')) {
	   		 	event.preventDefault(); 
	   		 }
     	});
     	
     	
     	
     	// display the hand when overing the delete article or news link button
     	$("input.delete-article").hover(function () {
	        $(this).css('cursor', 'pointer');
	      	}, 
	      	function () {
	        $(this).css('cursor', 'default');
	      	}
	    );
	    $("input.delete-news").hover(function () {
	        $(this).css('cursor', 'pointer');
	      	}, 
	      	function () {
	        $(this).css('cursor', 'default');
	      	}
	    );
	    
	    // logic for the article list order table in the admin area
	    
	    $("table.article-order").tableDnD({onDragClass: 'ondrag'});
	    
	    // make an ajax request when the "confirm order" button on the order table page is clicked to process the new articles order, sending all the articles ids in order
     	$('div#article-order form').submit(function(event) {
     		event.preventDefault();
     	});
     	
     	
     	$('input#confirm-order').click(function() {
     		
     		 var ids_array = new Array();
     		 $("table.article-order tr.data").each(function() {
     		 	ids_array.push($(this).attr('id'));
     		 });
     		
     		$.post('/admin/articoli/ordina',{ids: ids_array.toString()},function(data) {
     			if (data != '0') { // nessun errore
     				$('div#article-order').html(data);
     				$("table.article-order").tableDnD({onDragClass: 'ondrag'});
     				$('table.article-order').effect("highlight", {}, 1000);
     				$('#flash-msg-article-order').remove();
     				$('a#main-menu-order-utility').parent().after('<h3 id="flash-msg-article-order">Nuovo Riordinamento avvenuto</h3>');
     				
     				// to style the ajax flash message of the new article order
			     	$('h3#flash-msg-article-order').hide();
			     	
			     	$('h3#flash-msg-article-order').css('color', 'red');
			     	$('h3#flash-msg-article-order').css('backgroundColor', '#ffffff');
			     	$('h3#flash-msg-article-order').effect("pulsate", { times: 3 }, 3000);
     			} else {
     				window.location = '/admin/gestione-articoli/pagina/1';
     			}
     		});
     	
     	
     	
     	});
     	
     	
        // logic for the news list order table in the admin area
     	
     	
     	$("table.news-order").tableDnD({onDragClass: 'ondrag'});
	    
	    // make an ajax request when the "confirm order" button on the order table page is clicked to process the new news order, sending all the news ids in order
     	$('div#news-order form').submit(function(event) {
     		event.preventDefault();
     	});
     	
     	
     	$('input#confirm-order').click(function() {
     		
     		 var ids_array = new Array();
     		 $("table.news-order tr.data").each(function() {
     		 	ids_array.push($(this).attr('id'));
     		 });
     		
     		$.post('/admin/notizie/ordina',{ids: ids_array.toString()},function(data) {
     			if (data != '0') { // nessun errore
     				$('div#news-order').html(data);
     				$("table.news-order").tableDnD({onDragClass: 'ondrag'});
     				$('table.news-order').effect("highlight", {}, 1000);
     				$('#flash-msg-article-order').remove();
     				$('a#main-menu-order-utility').parent().after('<h3 id="flash-msg-article-order">Nuovo Riordinamento avvenuto</h3>');
     				
     				// to style the ajax flash message of the new news order
			     	$('h3#flash-msg-article-order').hide();
			     	
			     	$('h3#flash-msg-article-order').css('color', 'red');
			     	$('h3#flash-msg-article-order').css('backgroundColor', '#ffffff');
			     	$('h3#flash-msg-article-order').effect("pulsate", { times: 3 }, 3000);
     			} else {
     				window.location = '/admin/gestione-notizie/pagina/1';
     			}
     		});
     	
     	
     	
     	});
     	
     		
     		
     	// logic for the public or not public an article or a news on the article and news management pages in the admin area (ajax)
     		
     		// for the articles
     		$('table#article-list a.published-yes').click(function(event) {
     			event.preventDefault();
     			var current_td_element = $(this).parent().parent();
     			var article_permalink = $(this).parent().parent().parent().attr('id');
     			current_td_element.css('opacity', 0.5);
     			current_td_element.css({backgroundImage: 'url(/images/loading.gif)', backgroundRepeat: 'no-repeat', backgroundPosition: 'center center'});
	     		$.post("/admin/articolo/pubblica", { flag: 'yes', permalink: article_permalink},
	     				  function(data){
	     				    if (data == 'ok') {
	     				    	current_td_element.css({opacity: 1, backgroundImage: 'none'});
	     				    	$('img', current_td_element).attr({src: '/images/articles/check.gif'});
	     				    } else if (data == 'db-error') {
	     				    	window.location = '/admin/gestione-articoli/pagina/1';
	     				    }
	     				  });
     		});
     		
     		$('table#article-list a.published-no').click(function(event) {
     			event.preventDefault();
     			var current_td_element = $(this).parent().parent();
     			var article_permalink = $(this).parent().parent().parent().attr('id');
     			current_td_element.css('opacity', 0.5);
     			current_td_element.css({backgroundImage: 'url(/images/loading.gif)', backgroundRepeat: 'no-repeat', backgroundPosition: 'center center'});
	     		$.post("/admin/articolo/pubblica", { flag: 'no', permalink: article_permalink},
	     				  function(data){
	     				    if (data == 'ok') {
	     				    	current_td_element.css({opacity: 1, backgroundImage: 'none'});
	     				    	$('img', current_td_element).attr({src: '/images/articles/denied.jpg'});
	     				   } else if (data == 'db-error') {
	     				    	window.location = '/admin/gestione-articoli/pagina/1';
	     				    }
	     				  });
     		});
     		
     		// for the news
     		$('table#news-list a.published-yes').click(function(event) {
     			event.preventDefault();
     			var current_td_element = $(this).parent().parent();
     			var article_permalink = $(this).parent().parent().parent().attr('id');
     			current_td_element.css('opacity', 0.5);
     			current_td_element.css({backgroundImage: 'url(/images/loading.gif)', backgroundRepeat: 'no-repeat', backgroundPosition: 'center center'});
	     		$.post("/admin/notizia/pubblica", { flag: 'yes', permalink: article_permalink},
	     				  function(data){
	     				    if (data == 'ok') {
	     				    	current_td_element.css({opacity: 1, backgroundImage: 'none'});
	     				    	$('img', current_td_element).attr({src: '/images/articles/check.gif'});
	     				   } else if (data == 'db-error') {
	     				    	window.location = '/admin/gestione-articoli/pagina/1';
	     				    }
	     				  });
     		});
     		
     		$('table#news-list a.published-no').click(function(event) {
     			event.preventDefault();
     			var current_td_element = $(this).parent().parent();
     			var article_permalink = $(this).parent().parent().parent().attr('id');
     			current_td_element.css('opacity', 0.5);
     			current_td_element.css({backgroundImage: 'url(/images/loading.gif)', backgroundRepeat: 'no-repeat', backgroundPosition: 'center center'});
	     		$.post("/admin/notizia/pubblica", { flag: 'no', permalink: article_permalink},
	     				  function(data){
	     				    if (data == 'ok') {
	     				    	current_td_element.css({opacity: 1, backgroundImage: 'none'});
	     				    	$('img', current_td_element).attr({src: '/images/articles/denied.jpg'});
	     				   } else if (data == 'db-error') {
	     				    	window.location = '/admin/gestione-articoli/pagina/1';
	     				    }
	     				  });
     		});
     	
     	
     	
     	// the link to external url in the article show page must open a new browser window
     	
     	$('a#external-link').click(function(event) {
     		$(this).attr('target', 'blank');
     	});
     	
     	// also the links in the articles body (if present) must open in a new browser window
     	$("div.articolo_centrale p[class!='sottotitolo'] a").click(function(event) {
     		$(this).attr('target', 'blank');
     	});
     	
     	// also the pdf link (download) in the single article page in the public area
     	$("div.articolo_centrale a#pdf-link").click(function(event) {
     		$(this).attr('target', 'blank');
     	});
     	
     	
     	// style the p element parent of the span with the text "Foto attualmente nella fotogallery (elimina le selezionate o aggiorna le descrizioni)" in the article edit page
			
			$('span#photogallery-title').parent().width('620px').css({marginTop: '25px', marginBottom: '25px', marginLeft: '-155px'});
			
	   // to style various forms in the admin area 
	   
	   $('#login_form').css('marginLeft','auto');
	   $('#login_form').css('marginRight','auto');
	   
	   $('#article_form').css('marginLeft','auto');
	   $('#article_form').css('marginRight','auto');
	   
	   $('#news_form').css('marginLeft','auto');
	   $('#news_form').css('marginRight','auto');
	   
	   // to style (not float left) the label of the textarea (body of the article with the wyswyg editor) in the new article form page
	   $('#short_body').prev().css('float','none');
	   $('#short_body').next().css('marginTop','15px');
	   $('#author').parent().css('paddingTop','25px');
	   $('#body').prev().css('float','none');
	   $('#body').next().css('marginTop','15px');
	   $('#body').parent().css('paddingTop','15px');
	   $('#body').parent().css('paddingBottom','15px');
	   
	   // lucene re-index utility in the admin panel
	   $('input#lucene').click(function(event) {
   		 if (!confirm('Sei sicuro di voler re-indicizzare articoli e news?')) {
   		 	event.preventDefault(); 
   		 }
   	});
	  
    
});