/* - - - - - - - - - - - - - - - - - - - - 
T E C H N O G Y M
THE WELLNESS SYSTEM
http://www.technogym.com
website by websolute
- - - - - - - - - - - - - - - - - - - - */

// adjust background
function adjustBackground() {
    var winWidth = $(window).width();
    var adjustMarginbg = (winWidth - 1280) / 2;
    if (winWidth >= 1280) {
        $('body .bg').show();
    } else {
        $('body .bg').hide();
    }
}

// adjust background HOME
function adjustBackgroundHome() {
    var winWidth = $(window).width();
    var adjustMarginbg = (winWidth - 1280) / 2;
    if (winWidth >= 1280) {
        $('#background_home_img').addClass('big');
    } else {
        $('#background_home_img').removeClass('big').find('img').css('margin-left', adjustMarginbg + 'px');
    }
}

// adjust background arab r-t-l

function rtlBackground() {
    var lingua = $('body').attr('class');
    var url = window.location.pathname;
    var idPage = url.substring(url.lastIndexOf('/') + 1);

    if (lingua == 'ar' && idPage == 10001) {
        $('.content .middle .body_content').css('background-image', 'url("/img/net/065_5133_soluzioni_hedader_arab.jpg")');
    };
    if (lingua == 'ar' && idPage == 498) {
        $('.content .middle .body_content').css('background-image', 'url("/img/net/065_194_wellness_header_arab.jpg")');
    };
    if (lingua == 'ar' && idPage == 10114) {
        $('.content .middle .body_content').css('background-image', 'url("/img/net/5209_header_arab.jpg")');
    };
    if (lingua == 'ar' && idPage == 10111) {
        $('.content .middle .body_content').css('background-image', 'url("/img/net/065_5207_big_005_arab.jpg")');
    };
    if (lingua == 'ar' && idPage == 10067) {
        $('.content .middle .body_content').css('background-image', 'url("/img/net/5134_company_arab.jpg")');
    };
}

// adjust prod versions txt list

function versionsText() {
    var url = window.location.pathname;
    var idPage = url.substring(url.lastIndexOf('/') + 1);
    if (idPage == 240) {
        $('.singleprod_header').css({ 'height': '150px', 'background-position': '-174px 136px' });
    }
}

// adjust ie7 scrollbars
function adjusScrollbars() {
    larghezza = $(window).width();
    if (larghezza <= 990) {
        $('body').css('overflow-x', 'auto');
    } else {
        $('body').css('overflow-x', 'hidden');
    }
}


function initFancybox() {
    if ($.browser.msie) {
        $("a[rel=head_gallery], a[rel=flickr_gallery]").fancybox({
            //overlayOpacity: 0.7,
            //overlayColor: '#000',
            'autoDimensions': false,
            padding: 20//,
            //titleShow: false,
            //transitionIn: 'fade',
            //transitionOut: 'none',
            //speedIn: 150
        });
    } else {
        $("a[rel=head_gallery], a[rel=flickr_gallery]").fancybox({
            //overlayOpacity: 0.7,
            //overlayColor: '#000',
            'autoDimensions': false,
            padding: 20//,
            //titleShow: false
        });
    }
}

// IE suck
$(function () {
    var zIndexNumber = 10;
    // Put your target element(s) in the selector below!
    $(".content .personal_input ul li.select").each(function () {
        $(this).css('zIndex', zIndexNumber);
        zIndexNumber -= 1;
    });
});

window.onload = function () {
    //tamingselect();

    $('ul.dropdownhidden li:first-child').hide();


    $('.dropdownhidden').each(function (index) {

        if ($(this).height() > 130) {
            $(this).css({ 'height': '130px', 'overflow': 'auto' });
        }
    });
    //$('.wrap_commercial, .text_details .login').css('display','none');

}

// validate email
function isValidEmailAddress(emailAddress) {
    var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
    return pattern.test(emailAddress);
}

function showForgotPwd() {
    $.fancybox('/forgotPassword2.asp', { type: 'iframe' });
    //location.href = "/forgotPassword2.asp"
}

// a.aratari: gestione del "dimenticato password" dentro fancybox del wellness institute senza iframe
var old_content_width;
var old_content_height;

function showForgotPwd_FancyboxWI() {
    old_content_width = $('#fancybox-content').css('width');
    old_content_height = $('#fancybox-content').css('height');
    $('#fancybox-content').children('div').hide();

    $('#fancybox-close').remove();
    $('#fancybox-content').css('width', '560px').css('height', '225px').append('<iframe scrolling="auto" frameborder="0" src="/forgotPassword2.asp" hspace="0" name="fancybox-frame1315563602446" id="fancybox-frame"></iframe>');
    $('#fancybox-outer').css('width', '114%').append('<a id="fancybox-wi-fpwd-close" style="display: inline;" onclick="javascript: restore_wi_fancybox(); return false;"></a>');
}

function restore_wi_fancybox() {
    $('#fancybox-wi-fpwd-close').remove();
    $('#fancybox-content').children('div').show();
    $('#fancybox-outer').css('width', '100%').append('<a id="fancybox-close" style="display: inline;" onclick="javascript: $.fancybox.close()"></a>');
    $('#fancybox-content').css('width', old_content_width).css('height', old_content_height).children('iframe').remove();
}

// ----------------- aratari: paginazione dei prodotti nelle pagine linea
function paginazioneLinea() {
    var cont = 1;
    $('div.linea').css('margin-top', '50px').children().each(function () {
        if (cont == 3) {
            $(this).css('padding-right', '0px');
            cont = 0;
        }
        cont++;
    });

    pagingInternoLinea(1);
}

function pagingInternoLinea(pageNum) {

    var PAGE_SIZE = 6;
    var LINK_NUMBER = 5;

    if (pageNum == 0) return;

    var container = $('div.text'); // il contenitore
    var elems = container.find('div.wrap_box_item'); // tutti i prodotti
    var pagination = container.find('div.news_pagination'); // elemento che contiene la paginazione

    // sta tutto in una pagina
    if (elems.size() <= PAGE_SIZE) {
        elems.show();
        pagination.remove();
        return;
    }
    //

    var pageCount = Math.floor(elems.size() / PAGE_SIZE); // il numero
    if (elems.size() % PAGE_SIZE) pageCount++;            // di pagine totale

    // scrivo il div di paginazione

    var firstPage; // prima pagina visualizzata
    var lastPage;  // ultima pagina visualizzata
    if (pageNum < LINK_NUMBER)
        firstPage = 1
    else
        firstPage = pageNum - Math.floor(LINK_NUMBER / 2)

    lastPage = firstPage + LINK_NUMBER - 1
    if (lastPage > pageCount) {
        lastPage = pageCount
        firstPage = lastPage - LINK_NUMBER + 1
        if (firstPage <= 0) firstPage = 1
    }

    var pagHtml = '';
    for (var i = firstPage; i <= lastPage; i++) {
        pagHtml += '<a href="#"'
        if (i == pageNum) pagHtml += ' onclick="return false;" class="on"';
        else pagHtml += ' onclick="pagingInternoLinea(' + i.toString() + ');_linea_goUp();return false;"';
        pagHtml += '>' + i.toString() + '</a>'
    }

    pagHtml = '<div class="numbers clearfix">' + pagHtml + '</div>';
    if (pageNum !== pageCount) pagHtml = '<div class="next"><a href="#" onclick="pagingInternoLinea(' + (pageNum + 1).toString() + ');_linea_goUp();return false;">' + LABELS.NEXT + '</a></div>' + pagHtml;
    if (pageNum !== 1) pagHtml = '<div class="prev"><a href="#" onclick="pagingInternoLinea(' + (pageNum - 1).toString() + ');_linea_goUp();return false;">' + LABELS.PREVIOUS + '</a></div>' + pagHtml;
    //


    if (pagination.size() == 0) {
        container.append('<div class="news_pagination"></div>');
        pagination = container.find('div.news_pagination');
    }
    pagination.html(pagHtml);

    elems.hide();
    if (pageNum === 1) {
        container.find('div.wrap_box_item:lt(' + PAGE_SIZE.toString() + ')').show();
    } else {
        var first = (pageNum - 1) * PAGE_SIZE - 1;
        var last = first + PAGE_SIZE + 1;
        container.find('div.wrap_box_item:lt(' + last.toString() + '):gt(' + first.toString() + ')').show();
    }
}


function _linea_goUp() { $('html, body').animate({ scrollTop: ($(".wrap_prod").offset().top) - 20 }, 1000); }
// ------------------

// Delete Call_To_Action_Shop

$(function () {
    //se non è definita non è ne un prodotto ne una soluzione
    if (typeof countries_call_to_action_shop != 'undefined') {
        //se la nazione non è contenuta nell'array delle nazioni allora devo cancellare le call_to_action_shop
        if (jQuery.inArray(technogym_page.country, countries_call_to_action_shop) < 0) {
            $('.call_to_action_shop').remove();
        }
    }
});

// -------------------------

// Form Swap Values
$(function () {
    var inputs = $("input.text[type=text], textarea.text");
    // tutti i testi tranne quelli dentro i mini form
    var miniForms = $('form.form_mini3[id]');
    if (miniForms.size() > 0) inputs = inputs.not(miniForms.find('input.text[type=text], textarea.text'))

    swapValues = [];
    inputs.each(function (i) {
        if ($.fn.formContainer)
          swapValues[i] = $(this).formContainer().find('span.empty').text()
        else
          swapValues[i] = $(this).prev('label').html() || $(this).prev().prev('label').html() || $(this).val();
        $(this).focus(function () {
            if ($(this).val() == swapValues[i]) {
                //if($(this).hasClass('password'))
                //    this.type = 'password';
                $(this).val("");

            }
        }).blur(function () {
            if ($.trim($(this).val()) == "") {
                $(this).val('');
                //if($(this).hasClass('password'))
                //    this.type = 'text';
                $(this).val(swapValues[i]);
            }
        });
    });

    //SWAP DEL CAMPO SITE SEARCH - gestione personalizzata
    var txt_search = $('input#txt_search');
    var lbl_search = $('input#txt_search_label');
    if (txt_search.val() == '') { txt_search.hide(); }

    lbl_search.focus(function () {
        lbl_search.hide();
        txt_search.show();
        txt_search.focus();
    });

    txt_search.focusout(function () {
        if (txt_search.val() == '') {
            txt_search.hide();
            lbl_search.show();
        }
    });

    $('#cse-search-box').submit(function () {
        if (txt_search.val() == '') {
            lbl_search.focus();
            return false;
        }
        else {
            return true;
        }
    });
});

// choice country-lang / login register
/*function countryShowhide() {
$('#log_reg_iframe').remove();
if ($("#choice_iframe").size() == 0) {
$('.header_menu').animate({ height: "480px" }, 800);
$('.header_menu').append("<iframe frameBorder='0' id='choice_iframe' src='/country.asp' width='960' height='458'></iframe>");
$('#choice_iframe').delay(800).fadeIn(500);
} else {
$('#choice_iframe').fadeOut(500);
$('.header_menu').delay(500).animate({ height: "32px" }, 800);
setTimeout("$('#choice_iframe').remove();", 800);
}
return false;
}

function logregisterShowhide() {
var header = $('div.header_menu');
header.children(':gt(0)').remove();
if ( !(header.get(0).isOpenedLog === true) ) {
header.get(0).isOpenedLog = true;
header.get(0).isOpenedShop = false;
header.animate({ height: "222px" }, 800);
header.append("<iframe frameBorder='0' id='log_reg_iframe' src='/log_register.aspx' width='960' height='180'></iframe>");
$('#log_reg_iframe').delay(800).fadeIn(500);
} else {
header.get(0).isOpenedLog = false;
$('#log_reg_iframe').fadeOut(500);
header.delay(500).animate({ height: "32px" }, 800);
setTimeout("$('#log_reg_iframe').remove();", 800);
}
return false;
}*/


// choice country-lang / login register
function countryShowhide() {
    $('#log_reg_iframe, #shop_frame').remove();
    if ($("#log_reg_iframe, #choice_iframe, #shop_frame").size() == 0) {
        $('.header_menu').animate({ height: "480px" }, 800);
        $('.header_menu').append("<iframe frameBorder='0' id='choice_iframe' src='/country.asp' width='960' height='458'></iframe>");
        $('#choice_iframe').delay(800).fadeIn(500);
    } else {
        $('#choice_iframe').fadeOut(500);
        $('.header_menu').delay(500).animate({ height: "32px" }, 800);
        setTimeout("$('#choice_iframe').remove();", 800);
    }
    return false;
}

function logregisterShowhide() {
    $('#choice_iframe, #shop_frame').remove();
    if ($("#log_reg_iframe, #choice_iframe, #shop_frame").size() == 0) {

        $('.header_menu').animate({ height: "222px" }, 800);
        $('.header_menu').append('<iframe frameBorder="0" id="log_reg_iframe" src="/log_register.aspx" width="960" height="180"></iframe>');
        $('#log_reg_iframe').delay(800).fadeIn(500);
    } else {
        $('#log_reg_iframe').fadeOut(500);
        $('.header_menu').delay(500).animate({ height: "32px" }, 800);
        setTimeout("$('#log_reg_iframe').remove();", 800);
    }
    return false;
}

function dashboardShowhide() {
    $('#choice_iframe, #shop_frame').remove();
    if ($("#log_reg_iframe, #choice_iframe, #shop_frame").size() == 0) {

        $('.header_menu').animate({ height: "222px" }, 800);
        $('.header_menu').append('<iframe frameBorder="0" id="log_reg_iframe" src="/dashboard.aspx" width="960" height="180"></iframe>');
        $('#log_reg_iframe').delay(800).fadeIn(500);
    } else {
        $('#log_reg_iframe').fadeOut(500);
        $('.header_menu').delay(500).animate({ height: "32px" }, 800);
        setTimeout("$('#log_reg_iframe').remove();", 800);
    }
    return false;
}
if (document.cookie.match("openDashboard=true")) {
    document.cookie = "openDashboard=false; path=/; expires=Thu, 01-Jan-1970 00:00:01 GMT";
    if (window == parent) $(dashboardShowhide)
}

function logout() {
    $('.responce_error').hide();
    $.ajax({
        type: "POST",
        url: "/WS/wsForm.asmx/Logout",
        cache: false,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (data) {
            if (data.d) {
                parent.document.cookie = 'tgKeep=delete; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/'
                parent.location.reload(true)
            }
            else
                $('.responce_error').show();
        }
    })


    return false;
}

function beautifySelect() {

    $(this == window ? document : this).find("li.select, li.select_filter").each(function () {
        $(this).append('<span class="select close"><span style="width: 262px; overflow: hidden">' + $(this).find("option:selected").html() + '</span></span>')
				    .find("select")
				        .css({ opacity: 0 })
				        .change(function () {
				            $(this).parent().find("span.select span").text($(this).find(':selected').html());
				        });
    })

    /*$("li.select select").click(function(){
    $(this).parent().find("span.select").addClass("open").removeClass("close");
    }).bind("blur change",function(){
    $(this).parent().find("span.select").addClass("close").removeClass("open");

    });*/

}

function beautifySelectDue() {

    $(this == window ? document : this).find("li.select, li.select_filter").each(function () {
        $(this).find('.wrap_input').append('<span class="select close"><span class="select_text">' + $(this).find("option:selected").html() + '</span></span>')
				    .find("select")
				        .css({ opacity: 0 })
				        .change(function () {
				            $(this).parent().find("span.select span").text($(this).find(':selected').html());
				        });
    })

    /*$("li.select select").click(function(){
    $(this).parent().find("span.select").addClass("open").removeClass("close");
    }).bind("blur change",function(){
    $(this).parent().find("span.select").addClass("close").removeClass("open");

    });*/

}

// iremove dotted links ie7
if (document.documentElement.attachEvent)
    document.documentElement.attachEvent('onmousedown', function () {
        event.srcElement.hideFocus = true
    });

// INIT
    $(document).ready(function () {


        // backgrounds - home / site
        if ($('.widget_header').size() != 0) {
            // background image
            adjustBackgroundHome();
        } else {
            // background image home
            adjustBackground();
        };

        if ($('.blu_wrap').size() > 0) {
            beautifySelect();
        }
        else {
            beautifySelectDue();
        }
        rtlBackground();
        adjusScrollbars();
        versionsText();

        //var valore = url.substring(url.lastIndexOf('/') + 1);
        //alert (valore);

        // generic tab
        function hideGenerictabs() {
            $('.generic_tab').each(function () {
                var ancora = $(this).attr('href');
                $(ancora).hide().css('background-color', '#fff');
            });
        }

        if ($('.generic_tab').size() != 0) {

            hideGenerictabs();

            $('.generic_tab').click(function () {
                var ancora = $(this).attr('href');
                hideGenerictabs();
                $(ancora).fadeIn();
                return false;
            });
        }


        // left menu
        if ($('.shopstep').size() == 0) {

            $('ul.contestual_menu li').each(function () {
                if ($(this).find("ul").size() > 0 && $(this).find("ul.opened").size() == 0 && $(this).find("ul.tre_level").size() == 0) {
                    $(this).append("<span class='submenu_ico'></span>");
                }
            });

            $("ul.contestual_menu li").hover(
	  function () {
	      $(this).find('ul:eq(0)').show();
	      if ($(this).find("ul.opened").size() == 0) {
	          $(this).children().addClass('underlined');
	          $(this).find('ul li:first-child').addClass('round_first');
	          $(this).find('ul li:last-child').addClass('round_last');
	      }
	  },
	  function () {
	      $(this).children().removeClass('underlined');
	      if ($(this).find("ul.opened").size() == 0) {
	          $(this).find('ul').hide();
	          $(this).find('ul li:first-child').removeClass('round_first');
	          $(this).find('ul li:last-child').removeClass('round_last');
	      }
	  }
	);

            /*$("ul.contestual_menu li").click(function() {
            window.location = $(this).find("a").attr("href");
            alert('eccolo')
            return false;
            });*/

            $('ul.contestual_menu li:not(.show_all, .hide_all)').live('click', function () {
                window.location = $(this).find("a").attr("href");
                return false;
            });

        } else {

            $('ul.contestual_menu li').css('cursor', 'default');

        };

        if ($('.col_left').height() < 476) {
            $('.col_left').css({ 'height': '476px', 'background': 'url(/img/net/sub_section_land_back.jpg) repeat-x scroll left bottom transparent' });
        };

        if ($('.col_left_subsection_land').height() < 400) {
            $('.col_left_subsection_land').css('height', '400px');
        };

        // lang - country
        $("li.country a, li.language a").click(countryShowhide);

        // login - register
        $("li.login_link a, li.register_link a").click(logregisterShowhide);

        $("li.logout_link a").click(logout);

        $('#span_attiva_iaa').click(function () {
            $.ajax
            ({
                type: "POST",
                url: "/WS/wsForm.asmx/Attivazione_Architetto",
                cache: false,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                    if (data.d) {
                        location.reload();
                    }
                }
            });
        });

        lingua = $('body').attr('class');
        if (lingua == 'ar') {
            $(".menu ul li:first-child").css("border-right", "none");
            $(".menu ul li:last-child").css("border-left", "none");
        } else {
            $(".menu ul li:first-child").css("border-left", "none");
            $(".menu ul li:last-child").css("border-right", "none");
        };

        $(".listing_news .listing_box:last-child").css("padding-bottom", "66px");
        $('.wrap_faccets .wrap_box_item:nth-child(3n), .wrap_faccets .wrap_box_item:last-child').css('padding-right', '0px');
        $('#text .wrap_box_item:nth-child(4n), #text .wrap_box_item:last-child').css('padding-right', '0px');
        $('.club_facet:nth-child(4n), .club_facet:last-child').css('padding-right', '0px');
        $(".quick_links ul li:last-child, .professional_services ul li:last-child, .col_right .box_where_buy ul li:last-child").css("background-image", "none");
        //$(".professional_services ul li:last-child").css("border-right" , "none");
        $(".footer_links ul li:first-child").css({ "padding-top": "0px", 'border-top': 'none' });
        $(".footer_links ul li:last-child").css({ "padding-bottom": "0px", 'border-bottom': 'none' });
        $(".breadcrumb ul li:last-child").css("margin-right", "0px");
        $('.gallery a:first-child').css('display', 'block');
        $('#confronta_prodotti .titolo_sezione:last').css('background-color', '#fff797');

        // adjust telephone number
        if (($('body').attr('id') != "it") && ($('body').attr('class') == "it")) {
            $('.call_us p.call').css('margin-top', '8px');
        }

        // controllo chiudi cassetto
        /*if ( ( $('#log_reg_iframe').size() != 0 ) || ( $('#choice_iframe').size() != 0 ) || ( $('#shop_frame').size() != 0 ) ) {
        }
        $('.wrap_menu ,.wrap_menu *').click(function(e)
        {
        e.stopPropagation();
        });
        $(document).click(function()
        {
        alert ('chiudi tutto')
        });*/




        // form actions
        //		$(".profile_radio").click(function(){
        //			if( ($(this).val()==="professional") || ($(this).val()==="commercial") ) {
        //				$(".wrap_commercial").slideDown(400);
        //				
        //				} else {
        //				$(".wrap_commercial").slideUp(400);
        //				}
        //				
        //			if( $(this).val()==="professional") {
        //				$('#ambito_commerciale').hide();
        //				$('#ambito_professionale').show();
        //			}
        //			if( $(this).val()==="commercial") {
        //				$('#ambito_commerciale').show();
        //				$('#ambito_professionale').hide();
        //			}
        //		});

        // validate email
        $(".validate_email").blur(function () {

            var email = $(".validate_email").val();

            if (email != 0) {
                if (isValidEmailAddress(email)) {
                    $(".validate_email").removeClass('errore_corto');
                    $(".validate_email").css('color', '#44555F')
                } else {
                    $(".validate_email").addClass('errore_corto');
                }
            } else {
                $(".validate_email").removeClass('errore_corto');
            }
        });

        if ($.fn.password)
            $('input.pwd[type=password]').password();

        $(".open_login").click(function () {

            if ($('.text_details .login').is(":hidden")) {
                $('.text_details .login').show();
            } else {
                $('.text_details .login').hide();
            }
            return false;
        });

        // INIT FB DEFAULT
        $.fn.fancybox.defaults.overlayOpacity = 0.7;
        $.fn.fancybox.defaults.overlayColor = '#000';
        $.fn.fancybox.defaults.titleShow = false;

        if ($.browser.msie) {
            $.fn.fancybox.defaults.transitionIn = 'none';
            $.fn.fancybox.defaults.transitionOut = 'none';
            $.fn.fancybox.defaults.speedIn = 150;
        }
        //

        // gallery flickr
        var flickrobj = $(".flckr_galleria");
        if (flickrobj.size() != 0) {
            flickrobj.flickr({
                photoset_id: (typeof (PHOTOSET_ID) == 'undefined' ? '72157623616258387' : PHOTOSET_ID),
                callback: initFancybox
            });
        }
        else {
            initFancybox();
        }
        flickrobj = null;

        $('#box_registrazione, .widg_top a, .fancy_prod').fancybox({
            'overlayOpacity': 0.7,
            'overlayColor': '#000',
            'autoDimensions': false,
            'padding': 20,
            'showNavArrows': false
        });

        $('a.box_registrazione_showroom, a.iframe_form').fancybox({
            'width': 715,
            'height': 650,
            'autoScale': false,
            'transitionIn': 'none',
            'transitionOut': 'none',
            'type': 'iframe'
        });

        $('a.box_mappa').fancybox({
            overlayOpacity: 0.7,
            overlayColor: '#000',
            'autoDimensions': false,
            'width': 820,
            'height': 530,
            padding: 20,
            showNavArrows: false,
            'onStart': function (obj) {
                var html = "";
                html += '<iframe src ="/servizi/showroom_geoloc/thickboxShowroom.asp?co_id=' + $(obj).attr('id_showroom') + '&showroom=1" width="100%" height="500px">';
                html += '<p>Your browser does not support iframes.</p></iframe>';
                $('#fancy_mappa').html(html);
            },
            'onClose': function () {
                $('#fancy_mappa').html("");
            }
        });

        $('a.fancy_noprices').fancybox({
            'width': 500,
            'height': 300,
            'autoDimensions': false,
            'type': 'iframe'
        });

        $('a.fancy_displayoption').fancybox({
            'width': 610,
            'height': 580,
            'autoDimensions': false,
            'type': 'iframe'
        });

        $('a.wi_fancybox').fancybox({
            'width': 600,
            'height': 200,
            'autoDimensions': false,
            'type': 'iframe'
        });

        if (window == parent && window.name.indexOf('fancybox') < 0) {
            $('a.thickbox').each(function () {
                var p = {
                    overlayOpacity: 0.7,
                    overlayColor: '#000',
                    'autoDimensions': false,
                    padding: 20,
                    showNavArrows: false,
                    titleShow: false
                },
                qs = new Array(),
                href = $(this).attr('href').split('?');

                if ($(this).hasClass('frame')) p.type = 'iframe';

                if (href.length > 1) {
                    var url = href[0],
                        splitted = href[1].match(/[^&\=]+/g);

                    for (i = splitted.length - 1; i >= 0; i -= 2) {
                        var name = splitted[i - 1].toLowerCase(), value = splitted[i];
                        switch (name) {
                            case 'width': p.width = Number(value); break;
                            case 'height': p.height = Number(value); break;
                            case 'tb_iframe': if (value.match(/true/i)) p.type = 'iframe'; break;
                            case 'tb_inline':
                            case 'keepthis': break;
                            default: qs.push(name + '=' + value); break;
                        }
                    }

                    $(this).attr('href', qs.length > 0 ? url + '?' + qs.join('&') : url);
                }

                $(this).fancybox(p);
            })
        }

        // gestione mancanza immagine su articoli
        $('.content .middle .central_image').each(function () {
            if ($(this).children().size() === 1 && $(this).find('img[src$=trasp.gif]').size() === 1)
                $(this).remove();
        })

        // verify json object
        if (typeof (JSON) === 'undefined') jQuery.ajax({ url: '/js/net/json2.min.js', async: false, dataType: 'script', success: function () { JSON = JSON2 } })
        //

        //gestione del link a wellness blog
        if (technogym_page.sezione == 'D') {
            $('a[href$="co_id=582"]').attr('href', '/blog/').attr('target', '_blank');
        }

        //se c'è il bottone di twitter riscrivo data-url con un short url
        if ($('.socials_container').children('.twitter-share-button').size()) {
            $.ajax({
                type: "POST",
                url: "/WS/wsGetContent.asmx/GetTinyUrl",
                cache: false,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                data: '{ "complete_url":"' + window.location.href + '" }',
                success: function (data) {
                    $('.twitter-share-button').attr('data-url', data.d);
                    $.getScript('http://platform.twitter.com/widgets.js');
                }
            })
        }


    });


$(window).resize(function () {
    adjustBackground();
    adjustBackgroundHome();
    adjusScrollbars();
});
