﻿$(document).ready(function() {
    $('ul').each(function() {
        $(this).find('li:first-child').addClass('first');
        $(this).find('li:last-child').addClass('last');
        $(this).find('li:even').addClass('odd');
        $(this).find('li:odd').addClass('even');
    });
    $('dl').each(function() {
        $(this).find('dt').addClass('dataTitle');
        $(this).find('dt:first').addClass('dataTitlefirst');
        $(this).find('dd:first').addClass('first');
        $(this).find('dd:last').addClass('last');
        $(this).find('dd:even').addClass('odd');
        $(this).find('dd:odd').addClass('even');
    });
    $('ol').each(function() {
        $(this).find('li:first-child').addClass('first');
        $(this).find('li:last-child').addClass('last');
        $(this).find('li:even').addClass('odd');
        $(this).find('li:odd').addClass('even');
    });
    $('table').each(function() {
        $(this).find('tr:first-child').addClass('first');
        $(this).find('tr:last-child').addClass('last');
        $(this).find('tr:even').addClass('odd');
        $(this).find('tr:odd').addClass('even');
    });
    $('div').each(function() {
        $(this).find('p:first').addClass('first');
        $(this).find('p:last').addClass('last');
        $(this).find('p:even').addClass('odd');
        $(this).find('p:odd').addClass('even');
    });

    $('#ab_additionalContent').find('a:first-child').addClass('first');
    $('#ab_additionalContent').find('a:last-child').addClass('last');

    $('table tr.first').each(function() {
        $(this).find('td').each(function(i) {
            i = i + 1;
            $(this).addClass('th-' + i);
        });
    });
    $('table tr.first').each(function() {
        $(this).find('th').each(function(i) {
            i = i + 1;
            $(this).addClass('th-' + i);
        });
    });
    $('table tr').each(function() {
        $(this).find('td').each(function(i) {
            i = i + 1;
            $(this).addClass('col' + i);
        });
    });
    $('table tr.last').each(function() {
        $(this).find('td').each(function(i) {
            i = i + 1;
            $(this).addClass('tf-' + i);
        });
    });
    $('dl').each(function() {
        $(this).find('dd').each(function(i) {
            i = i + 1;
            $(this).addClass('dd-' + i);
        });
    });

    //MANIPOLAZIONE DOM MODULO EVENTI
    $('.sf_eventsList li').each(function() {
        $("img.ab_logo").parent(".roundImg").addClass('roundImgLogo');
        //Sposto l'immagine dal paragrafo.sf_eventSummary all'h3
        $(this).find('h3.sf_eventTitle a').prepend($(this).find('.sf_eventSummary .roundImgLogo'));
        $(this).find('h3.sf_eventTitle a').prepend($(this).find('.sf_eventSummary img.ab_logo'));

        //Sposto la data dell'evento dopo il titolo
        $(this).find('h3.sf_eventTitle').after($(this).find('p.sf_eventPriod'));

        //Wrappo le date in un div.ab_eventPeriod
        $(this).find('p.sf_eventPriod').wrapAll('<div class="ab_eventPeriod" />');

        //Sposto l'indirizzo dopo la data
        $(this).find('.ab_eventPeriod').after($(this).find('.sf_eventLocation'));

        //Aggiungo un clear per resettare il float del logo
        $(this).find('.sf_eventLocation').after('<div class="clear"/>');
    });

    //MANIPOLAZIONE DOM LISTA ESPANSA (pubblicazioni)
    $('.ab_pubblicazioni .sf_expandedList li').each(function() {
        //Sposto l'h3
        $(this).find('h3.sf_listItemTitle').prependTo($(this).find('.sf_listItemBody .th-2'));
    });

    //MANIPOLAZIONE DOM LISTA ESPANSA (partners)
    $('.staff .sf_expandedList li').each(function() {
        //Sposto l'h3
        $(this).find('h3.sf_listItemTitle').prependTo($(this).find('.sf_listItemBody .th-2'));
    });

    //MANIPOLAZIONE DOM LISTA ESPANSA (staff)
    $('.partners .sf_expandedList li').each(function() {
        //Sposto l'h3
        $(this).find('h3.sf_listItemTitle').prependTo($(this).find('.sf_listItemBody .th-2'));
    });

    //Serve per l'allineamento in basso a destra dei download link PDF
    $('.ab_dwn-botRig').parent().addClass('ab_botRig');
    $('.ab_botRig').wrap('<div />');

    // PAGINATORE
    // Aggiungo le freccette a "previous page"  e "next page"
    $("a[id$='PreviousPage']").addClass('ab_prevPage');
    $("a[id$='NextPage']").addClass('ab_nextPage');

    //assegna classe "pdf" ai link alla libreria documenti
    $("a[href*=documentiPdf]").addClass("pdf");

    //assegno le classi "ab_horizontal" e "ab_menu" a <ul> contenuta nel div#ab_mainMenuBox
    $('#ab_mainMenuBox ul').addClass('ab_horizontal ab_menu');

    //assegno le classi "ab_horizontal" e "ab_menu" a <ul> contenuta nel div#ab_tabMenu
    $('#ab_tabMenu ul').addClass('ab_horizontal ab_menu');

    //OLD $('#ab_tabMenu > ul').wrap('<div class="ab_addBorder" />');
    $('#ab_tabMenu > div').addClass('ab_addBorder');

    //styles right column boxes
    $('.ab_roundItInner').corner("round 5px").parent().css('padding', '1px').corner("round 5px");

    //assign print function to a.ab_printBtn
    $('a.ab_printBtn').click(function() {
        window.print();
        return false;
    });

    //assegno ai titoli
    //$('h2').addClass('ab_titoloSottolineato');
    //assegno rimuovo la classe per i titoli delle news
    //$('h2.sf_newsTitle, h2.sf_NewsTitle').removeClass('ab_titoloSottolineato');

    //Rimuovo i paragrafi vuoti
    $('p:empty').css('display', 'none');

    //Aggiungo la classe newsSummary al terzo paragrafo figlio di ogni .sf_newsList li
    $('.sf_newsList li p:nth-child(3)').addClass('newsSummary');
    //Inserisco all'interno del p.newsSummay come ultimo elemento il p.sf_readMore
    $('.sf_readMore').each(function() {
        $(this).appendTo($(this).prev(['p.newsSummary']));
    })
    //Sostituisco il testo di default del link READMORE (FullStory) con l'immagine "ab_bg-readMore-icon.gif"
    $('p.sf_readMore a').html('... <img src="../../images/ab_bg-readMore-icon.gif">');

    //Sostituisco il testo di default del link READMORE (FullStory) con l'immagine "ab_bg-readMore-icon.gif"
    $('.archivio p.sf_readMore a').html('... <img src="../../../images/ab_bg-readMore-icon.gif">');

    //Assegno al paragrafo che precede p.sf_postCategory la proprietà css display:none;
    $('p.sf_postCategory').prev().css('margin', '0');

    //inserisco uno span all'interno del tag h2 per ottenere l'effetto del titolo parzialmente sottolineato
    //$('#ab_mainContent .ab_titoloSottolineato').wrapInner('<span />');

    //assegno all'elemento con classe "ab_sottotitolo" che segue immediatamente un h2.ab_titoloSottolineato la classe "ab_subAfter"
    $(".ab_titoloSottolineato + .ab_sottotitolo").addClass("ab_subAfter");

    // Add pdf icons to pdf links
    $("a[href$='.pdf']").addClass("pdf");
    // Add zip icons to Zip file links (zip, rar)
    $("a[href$='.zip'], a[href$='.rar']").addClass("zip");
    //Add external link icon to external links - 
    $('a').filter(function() {
        //Compare the anchor tag's host name with location's host name
        return this.hostname && this.hostname !== location.hostname;
    }).addClass("external");
    //Set the _target attribute to blank
    $('a').filter(function() {
        //Compare the anchor tag's host name with location's host name
        return this.hostname && this.hostname !== location.hostname;
    }).addClass("external").attr("target", "_blank");
    $('a').filter(function() {
        //Compare the anchor tag's host name with location's host name
        return this.hostname && this.hostname == location.hostname;
    }).addClass("internal");


    //Rende orizzontale il menu di servizio nelle pagine interne
    $('#ab_internaMaster ul.ab_menuServizio').addClass('ab_horizontal ab_menu');

    //Elimina i bullet dal menu di servizio nelle pagine interne aggiungendo la classe ab_menu
    $('#ab_homeMaster ul.ab_menuServizio').addClass('ab_menu');

    //SEARCH BOX --> per inserire un valore di default che scompare al focus del textBox    //global vars   

    /* var searchBoxes = $(".sf_searchText");
    var searchBox2 = $(".sf_searchText");
    var searchBoxEng = $(".sf_searchTextEng");
    var searchBox2Default = "CERCA";
    var searchBoxEng = "SEARCH";

    $(".sf_searchText").attr("value", searchBox2Default);
    $(".sf_searchTextEng").attr("value", searchBoxEng);

    //Searchbox2 show/hide default text if needed
    searchBox2.focus(function() {
    if ($(this).attr("value") == searchBox2Default) $(this).attr("value", "");
    });
    searchBox2.blur(function() {
    if ($(this).attr("value") == "") $(this).attr("value", searchBox2Default);
    });

    //Searchbox2 ENG show/hide default text if needed
    $(".sf_searchTextEng").focus(function() {
    if ($(this).attr("value") == searchBoxEng) $(this).attr("value", "");
    });
    $(".sf_searchTextEng").blur(function() {
    if ($(this).attr("value") == "") $(this).attr("value", searchBoxEng);
    });*/

    //search box
    var searchValue = $(".sf_searchText").attr("value");
    $(".sf_searchText").focus(function() {
        if ($(this).attr("value") == searchValue) $(this).attr("value", "");
    });
    $(".sf_searchText").blur(function() {
        if ($(this).attr("value") == "") $(this).attr("value", searchValue);
    });

    //alert(searchValue);


    //end search box

    //CLEAR > Scrivo un clear 
    $('#ab_homeMaster fieldset.sf_searchBox').after('<div class="clear"></div>');

    //IMMAGINI > Applico le classi 'iradius5 corner' per arrotondare gli angoli tramite plugin corner.js
    $('.roundImg img').each(function() {
        $(this).addClass('iradius5 corner').unwrap();
    });

    //TITOLO LISTA '.comitatoPresidenza' > Sposto il titolo della lista del comitato di presidenza nel div con il contenuto
    $('.comitatoPresidenza .sf_expandedList li').each(function() {
        $(this).find('.sf_listItemBody').prepend($(this).find('.sf_listItemTitle'));
    });

    //LIST ITEMS > Assegno la classe "thirdOfRow" ai listItem multipli di 3
    $('.comitatoPresidenza').each(function() {
        $(this).find('.sf_expandedList li:eq(2), .sf_expandedList li:eq(5), .sf_expandedList li:eq(8)').addClass('thirdOfRow');
    });

    //TITOLO LISTE > Rimuovo il titolo della lista del comitato di Presidenza se contiene "do-not-show" nel titolo
    $(".comitatoPresidenza h3.sf_listItemTitle:contains('do-not-show')").css('display', 'none');

    //TITOLO CON FILETTO > Se il titolo filettato è seguito da un sottotitolo prende la classe 'ab_conSottotitolo' che gli aggiunge un margin-bottom
    if ($(".ab_titoloSottolineato ~ .ab_sottotitolo").hasClass("ab_subAfter")) {
        $('.ab_titoloSottolineato').addClass('ab_conSottotitolo');
    }

    //BREADCRUMBS > Elimino la voce "home" (primo nodo)
    $("#ab_breadcrumbs span a:contains('Home')").addClass('linkHome').css('display', 'none').unwrap();
    //BREADCRUMBS > Elimino gli <span> vuoti
    $('#ab_breadcrumbs span:empty').css('display', 'none');
    //BREADCRUMBS > Elimino il primo <span>&gt;</span> (quello che segue Home)
    $("#ab_breadcrumbs .linkHome + span").css('display', 'none');

    //ISCRIZIONE MAILING LIST > Assegno uno classe diversa a "submit btn" a seconda della lingua
    $(".ab_submitBtn[value$='Subscribe']").addClass('ab_submitBtn-en');
    $(".ab_submitBtn[value$='Iscriviti']").addClass('ab_submitBtn-it');

    $(".ab_submitBtn[value$='Send']").addClass('ab_sendBtn-en');
    $(".ab_submitBtn[value$='Invia']").addClass('ab_sendBtn-it');

});





