v_player='/site/swf/flvplayer.swf';


$(document).ready(function(){

    var url = window.location.toString();
    var domain = url.split('/')[2];
    
    var anteprime=$('#anteprime-ul');
    
    
    if ($('#anteprime').is('div')){
        overBoxes('el_anteprima','bg_anteprime_over','bg_anteprime','#f6821f');
    }
    
    if ((anteprime.is('ul')) )
        /*&&  (domain != '192.168.137.100') && (domain != '213.215.213.40') && (domain != 'web-cms.juventus.priv') && (domain != '213.215.213.144')*/   
        if (anteprime.find("li").get().length>4)    
        {
            var top=0;/*** il top dell'ul - the position of the ul ***/
            var direction=-1;/*** la direzione della rotazione -1=su, 1=giù - the rotate direction -1=up, 1=down ***/
            var heightLi=65;/*** altezza di un singolo elemento li - height of single li ***/
            var stateRotation;/*** è l'istanza che determina lo start/stop dell'ul - instance for star/stop ul element ***/
            
            /*** RR=Round-Robin ***/
            function startRotate() /*** la funzione che fa partire la rotazione - the function to start RR-rotation ***/
            {
                stateRotation = setInterval ( function () {
                    rotate_RR();
                }, 40 );
            }
            
            startRotate(); /*** la rotazione RR parte - start the RR-Rotation ***/

            function rotate_RR() {/*** RR=Round-Robin ***/
                top += direction;/*** incrementa/decrementa il top - increment/decrement the top***/
                if (top%heightLi==0) {
                    var li_el; /*** l'elemento da clonare dell'ul - the element to be clone in the ul ***/

                    if (direction==-1) li_el=anteprime.find("li:first"); 
                    else li_el=anteprime.find("li:last");
                    
                    var first_last_Li=li_el.clone(); /*** Clono li_el - I clone li_el ***/

                    if (direction==-1) anteprime.append(first_last_Li); /*** accodato - appended ***/
                    else anteprime.prepend(first_last_Li); /*** messo in testa - prepended ***/

                    top-=(direction*heightLi);/*** setto il top - correct the top ***/
                    li_el.remove();/*** cancello l'li - removing li_el li ***/

                    first_last_Li.mouseover(
                        function()
                        {clearInterval(stateRotation); }
                    ).mouseout(
                        function()
                        {startRotate();}
                    );
                    overBoxes('el_preview','bg_anteprime_over','bg_anteprime','#000000');
                }
                anteprime.css({"margin-top":top});/*** setto il top - the top is set ***/
            }
            
            $("#anteprime-up").mouseover(
                function()
                {
                    direction=1;
                }
            );
            
            $("#anteprime-down").mouseover(
                function()
                {
                    direction=-1;
                }
            );
            
            $('#anteprime-ul *').mouseover(
                function()
                {
                    clearInterval(stateRotation);
                }
            );
            
            $('#anteprime-ul li').mouseout(
                function()
                {
                   startRotate();
                }
            );
            
            overBoxes('el_preview','bg_anteprime_over','bg_anteprime','#000000');
        }
    


        if($('#layout-prehp').is('div')){
          initOverPreHp();
            }
        if($('#firstlevel').is('ul')){
          menutTop();
           menuSecondLevel();
            }   
        if($('#topbar').is('div')){
            $('#fuser').focus( function() { this.value=""; });
            $('#fpassword').focus( function() {this.value="";});
            $('#fkeyword').focus( function() {this.value="";});
            }
        
        if ($('#elenco_primavera').is('div')){
                if($('#elenco_primavera').attr('class') != 'no_overlist'){
                overBoxes('el_primavera','bg_anteprime_over','bg_anteprime','#f6821f');
                }
            }
        if ($('#elenco_organigramma').is('div')){
                if($('#elenco_organigramma').attr('class') != 'no_overlist'){
                overBoxes('el_organigramma','bg_anteprime_over','bg_anteprime_dark','#000');
                }
            }
        if ($('#elenco_parolebianconere').is('div')){
            overBoxes('el_parolebianconere','bg_anteprime_over','bg_anteprime','#f6821f');
            }       
        if ($('.banner343').is('div')){
            overBanner343();
            }
        if ($('.banner232').is('div')){
            overBanner232();
            }       
        if ($('.xc').is('div')){
            goRound();
            }
        if ($('.xctop')){
            goRoundTop();
            }   
        if($('#box_palmares').is('div')){
            overPalmares();
            }   
        if($('#cont_gallerygiocatore').is('div')){
            mngGallery();
        }
        if($('#cont_coppe').is('div')){
            switchTabs();
            }
        if($('#bnr_classris343').is('div')){
            switchTabs343();
            initSlider();
        }
        if($('#bnr_classris343').is('div')){
            cutPostTxt();
        }               

        if($('#selgiocatore').is('select')){
            previewPlayer();
            }
        if($('#txt_risultaticlassifica').is('div')){
            switchTabs598.init();
            mngSelectResult();
            getResults();
            }   
        if($('#box_sedeprincipale').is('div')){
            initMaps();
            }
        if($('#selects_selcategoria').is('select')){
            goPageFromMenu('selects_selcategoria','btn_go_catgiovani');
            }   
        if($('#selects_selpubfin').is('select')){
            goPageFromMenu('selects_selpubfin','btn_go_prospinf');
            }
        if($('#fsel_competizione').is('select')){
            goPageFromMenu('fsel_competizione','btn_go_ticket');
            }       
        if($('#infoinvestitori').is('table')){
            alternaterows('#infoinvestitori');
            }
        if($('#tabprezzi').is('table')){
            alternaterows('#tabprezzi');
            }   
        if($('#palinsesto').is('div')){
            altrowLis();
            switchTabsDays();
            }   
        if($('.btn_mover').is('img')||$('.btn_mover').is('input')){
            btnMover();
            }
        if($('#box_entertainment').is('div')){
            btnMoverEntertainment();
            }
        if($('#els_gallery').is('div')){
            overBoxes('el_gallery','bg_gall_on','bg_gall_off','#f6821f');
            }   
        if($('.els_faq_questions').is('div')){
            scrollFaq();
            }
        if($('#obj_slshowpro').is('div')){
            loadGallery('#obj_slshowpro');
            }
        if($('#gallery_banner').is('div')){
            mngGallBannerNews();
            }
        if($('#fotogiocatore').is('div')){  
        loadSwf('#fotogiocatore','206','285',swf_fname,'#ffffff','opaque'); 
        }
        if($('#gall_jplaces').is('div')){   
        loadGallery('#gall_jplaces');
        }
        if($('#bnr_videohighlight').is('div')){
            highLightVideo();
        }
        if($('#body').is('div')&&$('#body').attr('class')=='body_hp'){
            window.setTimeout('hp_chngImgPP.createImg()',7000);
            loadBnrHp();
            }
        if($('#content_browsematchprogram').is('div')){
            loadFlipObj();
            }
        if($('#content_browsehurra').is('div')){
            loadFlipObj();
            }
        if($('#lm_bar_up').is('p')){
            insl_LMHP();
            }
        if($('#choose_year').is('p')){
            swicthNewsArchive();
        }
        if($('#txt_calendario').is('div')){
            swicthCalendar();
        }
        if($('#content_socifondatori').is('div')){
            writeSociFondatori();
        }
        if($('#box_betclick').is('div')){
            writebox_betclick();
        }
        if($('#slideshow_primasquadra').is('div')){
            loadGallery('#slideshow_primasquadra');
        }   
        if($('#f_fjm').is('div')){
            clearInputValue('#f_fjm');
        }
        if($('#f_fjm_r').is('div')){
            clearInputValue('#f_fjm_r');
        }
        //if(!($.cookie('subscribed')) && ($('#box_primopiano').is('div'))){
        if(!($.cookie('subscribed')) && ($('#hp_layer').is('div')) && (domain != '192.168.137.100') && (domain != '213.215.213.40') && (domain != 'web-cms.juventus.priv')){
            handleHpLayer(getLang());
        }
        if($('#audio_news').is('p')){
            handleAudioNews();
        }
        if($('#lang').is('div')){
            handleLang();
        }
        if($('#nuovo_stadio_swf').is('div')){writeNuovoStadioSwf();}
});


function writeNuovoStadioSwf(){
    $('#nuovo_stadio_swf').media({ 
        width:     343, 
        height:    82,  
        attrs:     {wmode : 'transparent',scale:'noscale',bgcolor : 'none'}, 
        params:    {wmode : 'transparent',scale:'noscale',bgcolor : 'none'},  
        src:       'styleJuventusCom/swf/bannerStadio.swf',     
        caption:   false
    }); 
}

$.blockUI = function(msg, css, opts) {
    $.blockUI.impl.install(window, msg, css, opts);
};

// expose version number so other plugins can interogate
$.blockUI.version = 1.33;


function goRoundTop(){
    var els2Round=$('.xctop');
    els2Round.each(function(i){ 
                            $(this).corner("tl tr 5px");
                            });
    }   
	
function cutPostTxt(){
  $('.el_ultimopost p').each(function(){
    var oldTxt = $(this).text().replace(/[\s\t]+/g ,' ');
    if (oldTxt.length > 95){
      var cutTxt = oldTxt.substring(0,93);
      var newTxt = cutTxt.lastIndexOf(' ');
      var myTxt = cutTxt.substring(0,newTxt);
      $(this).text(myTxt + "...");
    }
  });
}


/*******************GESTISCE I MOUSEOVER SU DIVERSI ELEMENTI DI BOX**************/

/*overBoxes è una funzione generica per tutte le liste che necessitano di over: ad es. anteprime news o elenco giocatori etc*/
function overBoxes(nomeBox,imgOver,imgOut,bgColor){
    $('.'+nomeBox).hover(function(){
                            if(nomeBox=='el_organigramma'){
                                 $(this).find('p.dati').find('span');
                                }
                                 if(nomeBox=='el_gallery'){
                                 $(this).find('p.data');
                                }   

                           },
                         function(){
                             if(nomeBox=='el_organigramma'){
                                 $(this).find('p.dati').find('span');
                                }
                                 if(nomeBox=='el_gallery'){
                                 $(this).find('p.data');
                                }   
                              });
    }   

    
/*mouseover su tutti i banner della colonna di destra*/ 
function overBanner343(){
    $('.banner343').each(function(){
                                $(this).hover(function(){ 
                                                     $(this).animate({'backgroundColor': '#f0c650'}, 'fast');
                                                        },
                                              function(){
                                                    $(this).animate({'backgroundColor': '#fff'}, 'fast');
                                                        });
                                  });
    }   

/*banner 232px sono presenti nel template wide in basso (hurra juventus, storia etc)*/
function overBanner232(){
    $('.banner232').each(function(i){ 
                                 $(this).mouseover(function(){
                                        $(this).animate({'backgroundColor': '#f0c650'}, 'fast');
                                        });
                                  $(this).mouseout(function(){$(this).css({background:'#fff'});
                                      });
                                  });
    
    }
 (function($) {

// the gory details
$.blockUI.impl = {
    box: null,
    boxCallback: null,
    pageBlock: null,
    pageBlockEls: [],
    op8: window.opera && window.opera.version() < 9,
    ie6: $.browser.msie && /MSIE 6.0/.test(navigator.userAgent),
    install: function(el, msg, css, opts) {
        opts = opts || {};
        this.boxCallback = typeof opts.displayMode == 'function' ? opts.displayMode : null;
        this.box = opts.displayMode ? msg : null;
        var full = (el == window);

        // use logical settings for opacity support based on browser but allow overrides via opts arg
        var noalpha = this.op8 || $.browser.mozilla && /Linux/.test(navigator.platform);
        if (typeof opts.alphaOverride != 'undefined')
            noalpha = opts.alphaOverride == 0 ? 1 : 0;

        if (full && this.pageBlock) this.remove(window, {fadeOut:0});
        // check to see if we were only passed the css object (a literal)
        if (msg && typeof msg == 'object' && !msg.jquery && !msg.nodeType) {
            css = msg;
            msg = null;
        }
        msg = msg ? (msg.nodeType ? $(msg) : msg) : full ? $.blockUI.defaults.pageMessage : $.blockUI.defaults.elementMessage;
        if (opts.displayMode)
            var basecss = jQuery.extend({}, $.blockUI.defaults.displayBoxCSS);
        else
            var basecss = jQuery.extend({}, full ? $.blockUI.defaults.pageMessageCSS : $.blockUI.defaults.elementMessageCSS);
        css = jQuery.extend(basecss, css || {});
        var f = ($.browser.msie) ? $('<iframe class="blockUI" style="z-index:1000;border:none;margin:0;padding:0;position:absolute;width:100%;height:100%;top:0;left:0" src="javascript:false;"></iframe>')
                                 : $('<div class="blockUI" style="display:none"></div>');
        var w = $('<div class="blockUI" style="z-index:1001;cursor:wait;border:none;margin:0;padding:0;width:100%;height:100%;top:0;left:0"></div>');
        var m = full ? $('<div class="blockUI blockMsg" style="z-index:1002;cursor:wait;padding:0;position:fixed"></div>')
                     : $('<div class="blockUI" style="display:none;z-index:1002;cursor:wait;position:absolute"></div>');
        w.css('position', full ? 'fixed' : 'absolute');
        if (msg) m.css(css);
        if (!noalpha) w.css($.blockUI.defaults.overlayCSS);
        if (this.op8) w.css({ width:''+el.clientWidth,height:''+el.clientHeight }); // lame
        if ($.browser.msie) f.css('opacity','0.0');

        $([f[0],w[0],m[0]]).appendTo(full ? 'body' : el);

        // ie7 must use absolute positioning in quirks mode and to account for activex issues (when scrolling)
        var expr = $.browser.msie && (!$.boxModel || $('object,embed', full ? null : el).length > 0);
        if (this.ie6 || expr) {
            // stretch content area if it's short
            if (full && $.blockUI.defaults.ie6Stretch && $.boxModel)
                $('html,body').css('height','100%');

            // fix ie6 problem when blocked element has a border width
            if ((this.ie6 || !$.boxModel) && !full) {
                var t = this.sz(el,'borderTopWidth'), l = this.sz(el,'borderLeftWidth');
                var fixT = t ? '(0 - '+t+')' : 0;
                var fixL = l ? '(0 - '+l+')' : 0;
            }

            // simulate fixed position
            $.each([f,w,m], function(i,o) {
                var s = o[0].style;
                s.position = 'absolute';
                if (i < 2) {
                    full ? s.setExpression('height','document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + "px"')
                         : s.setExpression('height','this.parentNode.offsetHeight + "px"');
                    full ? s.setExpression('width','jQuery.boxModel && document.documentElement.clientWidth || document.body.clientWidth + "px"')
                         : s.setExpression('width','this.parentNode.offsetWidth + "px"');
                    if (fixL) s.setExpression('left', fixL);
                    if (fixT) s.setExpression('top', fixT);
                }
                else {
                    if (full) s.setExpression('top','(document.documentElement.clientHeight || document.body.clientHeight) / 2 - (this.offsetHeight / 2) + (blah = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + "px"');
                    s.marginTop = 0;
                }
            });
        }
        if (opts.displayMode) {
            w.css('cursor','default').attr('title', $.blockUI.defaults.closeMessage);
            m.css('cursor','default');
            $([f[0],w[0],m[0]]).removeClass('blockUI').addClass('displayBox');
            $().click($.blockUI.impl.boxHandler).bind('keypress', $.blockUI.impl.boxHandler);
        }
        else
            this.bind(1, el);
        m.append(msg).show();
        if (msg.jquery) msg.show();
        if (opts.displayMode) return;
        if (full) {
            this.pageBlock = m[0];
            this.pageBlockEls = $(':input:enabled:visible',this.pageBlock);
            setTimeout(this.focus, 20);
        }
        else this.center(m[0]);
    },
    remove: function(el, opts) {
        var o = $.extend({}, $.blockUI.defaults, opts);
        this.bind(0, el);
        var full = el == window;
        var els = full ? $('body').children().filter('.blockUI') : $('.blockUI', el);
        if (full) this.pageBlock = this.pageBlockEls = null;

        if (o.fadeOut) {
            els.fadeOut(o.fadeTime, function() {
                if (this.parentNode) this.parentNode.removeChild(this);
            });
        }
        else els.remove();
    },
    boxRemove: function(el) {
        $().unbind('click',$.blockUI.impl.boxHandler).unbind('keypress', $.blockUI.impl.boxHandler);
        if (this.boxCallback)
            this.boxCallback(this.box);
        $('body .displayBox').hide().remove();
    },
    // event handler to suppress keyboard/mouse events when blocking
    handler: function(e) {
        if (e.keyCode && e.keyCode == 9) {
            if ($.blockUI.impl.pageBlock && !$.blockUI.defaults.allowTabToLeave) {
                var els = $.blockUI.impl.pageBlockEls;
                var fwd = !e.shiftKey && e.target == els[els.length-1];
                var back = e.shiftKey && e.target == els[0];
                if (fwd || back) {
                    setTimeout(function(){$.blockUI.impl.focus(back)},10);
                    return false;
                }
            }
        }
        if ($(e.target).parents('div.blockMsg').length > 0)
            return true;
        return $(e.target).parents().children().filter('div.blockUI').length == 0;
    },
    boxHandler: function(e) {
        if ((e.keyCode && e.keyCode == 27) || (e.type == 'click' && $(e.target).parents('div.blockMsg').length == 0))
            $.blockUI.impl.boxRemove();
        return true;
    },
    // bind/unbind the handler
    bind: function(b, el) {
        var full = el == window;
        // don't bother unbinding if there is nothing to unbind
        if (!b && (full && !this.pageBlock || !full && !el.$blocked)) return;
        if (!full) el.$blocked = b;
        var $e = $(el).find('a,:input');
        $.each(['mousedown','mouseup','keydown','keypress','click'], function(i,o) {
            $e[b?'bind':'unbind'](o, $.blockUI.impl.handler);
        });
    },
    focus: function(back) {
        if (!$.blockUI.impl.pageBlockEls) return;
        var e = $.blockUI.impl.pageBlockEls[back===true ? $.blockUI.impl.pageBlockEls.length-1 : 0];
        if (e) e.focus();
    },
    center: function(el) {
        var p = el.parentNode, s = el.style;
        var l = ((p.offsetWidth - el.offsetWidth)/2) - this.sz(p,'borderLeftWidth');
        var t = ((p.offsetHeight - el.offsetHeight)/2) - this.sz(p,'borderTopWidth');
        s.left = l > 0 ? (l+'px') : '0';
        s.top  = t > 0 ? (t+'px') : '0';
    },
    sz: function(el, p) { return parseInt($.css(el,p))||0; }
};

})(jQuery);
(function($) {

$.fn.media = function(options, f1, f2) {
    return this.each(function() {
        if (typeof options == 'function') {
            f2 = f1;
            f1 = options;
            options = {};
        }
        var o = getSettings(this, options);
        // pre-conversion callback, passes original element and fully populated options
        if (typeof f1 == 'function') f1(this, o);
        
        var r = getTypesRegExp();
        var m = r.exec(o.src) || [''];
        o.type ? m[0] = o.type : m.shift();
        for (var i=0; i < m.length; i++) {
            fn = m[i].toLowerCase();
            if (isDigit(fn[0])) fn = 'fn' + fn; // fns can't begin with numbers
            if (!$.fn.media[fn]) 
                continue;  // unrecognized media type
            // normalize autoplay settings
            var player = $.fn.media[fn+'_player'];
            if (!o.params) o.params = {};
            if (player) {
                var num = player.autoplayAttr == 'autostart';
                o.params[player.autoplayAttr || 'autoplay'] = num ? (o.autoplay ? 1 : 0) : o.autoplay ? true : false;
            }
            var $div = $.fn.media[fn](this, o);

            $div.css('backgroundColor', o.bgColor).width(o.width);
            
            // post-conversion callback, passes original element, new div element and fully populated options
            if (typeof f2 == 'function') f2(this, $div[0], o, player.name);
            break;
        }
    });
};

function generate(el, opts, player) {
    var $el = $(el);
    var o = $.fn.media.defaults.players[player];
    
    if (player == 'iframe') {
        var o = $('<iframe' + ' width="' + opts.width + '" height="' + opts.height + '" >');
        o.attr('src', opts.src);
        o.css('backgroundColor', o.bgColor);
    }
    else if ($.browser.msie) {
        var a = ['<object width="' + opts.width + '" height="' + opts.height + '" '];
        for (var key in opts.attrs)
            a.push(key + '="'+opts.attrs[key]+'" ');
        for (var key in o.oAttrs || {})
            a.push(key + '="'+o.oAttrs[key]+'" ');
        a.push('></ob'+'ject'+'>');
        var p = ['<param name="' + (o.oUrl || 'src') +'" value="' + opts.src + '">'];
        for (var key in opts.params)
            p.push('<param name="'+ key +'" value="' + opts.params[key] + '">');
        var o = document.createElement(a.join(''));
        for (var i=0; i < p.length; i++)
            o.appendChild(document.createElement(p[i]));
    }
    else {
        var a = ['<embed width="' + opts.width + '" height="' + opts.height + '" style="display:block"'];
        if (opts.src) a.push(' src="' + opts.src + '" ');
        for (var key in opts.attrs)
            a.push(key + '="'+opts.attrs[key]+'" ');
        for (var key in o.eAttrs || {})
            a.push(key + '="'+o.eAttrs[key]+'" ');
        for (var key in opts.params)
            a.push(key + '="'+opts.params[key]+'" ');
        a.push('></em'+'bed'+'>');
    }
    // convert element to div
    var id = el.id ? (' id="'+el.id+'"') : '';
    var cls = opts.cls ? (' class="' + opts.cls + '"') : '';
    var $div = $('<div' + id + cls + '>');
    $el.after($div).remove();
    ($.browser.msie || player == 'iframe') ? $div.append(o) : $div.html(a.join(''));
    if (opts.caption) $('<div>').appendTo($div).html(opts.caption);
    return $div;
};


})(jQuery);

jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};