
var handleCar={
    carosello:null,
    h2:null,
    cliccato:null,
    bottoni:null,
    init:function()
    {
		handleCar.carosello = $('#specializzati div.carosello');
        handleCar.h2=handleCar.carosello.find("h2");
        handleCar.bottoni=$("#anteprima li a");
		if (handleCar.carosello.find('li').length > 1) {
			handleCar.carosello.children('div').jCarouselLite({
				btnNext: ".next",
				btnPrev: ".prev",
                circular: false,
			    btnGo: handleCar.bottoni,
			    afterEnd: function(a) {
                   handleCar.bottoni.removeClass("on");

                    handleCar.cliccato=handleCar.bottoni.eq(a.index());
                    handleCar.cliccato.addClass("on");
                    handleCar.h2.html(handleCar.cliccato.find("span").html());
                    
				    //var cliccato = a.index();
//				    $('#funzionalita_elenco > ol > li').eq(cliccato).addClass('on');
//				    $('#funzionalita_indicatore > span').eq(cliccato).addClass('on');
			    },
				visible: 1
			});
		} else {
			handleCar.carosello.find('button').hide();
		}
    }
}

function slideMng(obj)
{
    var slider={ //*** da verificare la presenza di piu' slider nella stessa pagina--> diventa function
        div:null,
        slideUl:null,
        toLeft:null,
        toRight:null,
        offset:0,
        limit:0,
        curPos:0,
        onAnimate:false,
        init:function()
        {
            slider.div=obj;//$("#col_dx div.slider");
            if (slider.div.length==0) return;
            slider.toLeft=slider.div.find("a.toLeft");
            slider.toRight=slider.div.find("a.toRight");
            slider.slideUl=slider.div.find("ul");
            slider.offset=parseInt(slider.slideUl.find("li:first").width());
            slider.limit=slider.slideUl.find("li").length-1;//slider.offset*(slider.slideUl.find("li").length-1);
            slider.callbacks();
        },
        callbacks:function()
        {
            slider.toLeft.click(function(){slider.slide(-1)});
            slider.toRight.click(function(){slider.slide(1)});
        },
        slide:function(direction)
        {
            slider.curPos+=direction;
            if (slider.curPos<0) slider.curPos=0
            else if(slider.curPos>slider.limit) slider.curPos=slider.limit;
            slider.slideUl.animate({"margin-left":-(slider.offset*slider.curPos)});
        }
    }
    slider.init()
}

function calcMaxHeight(obj)
{
    var maxHeight=0;
    var h;
    obj.each(
        function()
        {
            h=parseInt($(this).outerHeight());
            if (maxHeight<h) maxHeight=h;
        }
    )
    //console.log("h="+h);
    return h;
}

function tabs(obj)
{
    var tabs={
        obj:obj,
        tab:obj.find("ul.ul-tabs li"),
        divs:obj.find(".div-tabs>div"),
        callbacks:function()
        {
            tabs.tab.click(
                function()
                {
                    var _this=$(this);
                    tabs.tab.removeClass("current");
                    _this.addClass("current");
                    tabs.divs.removeClass("current");
                    tabs.divs.eq(tabs.tab.index(_this)).addClass("current");
                       
                }
            );
        }
        
    }

    if (tabs.obj.length>0)    tabs.callbacks();
}


function accordion(obj)
{
    var speed= ($.browser.msie && $.browser.version=="7.0") ? 21 : 10.5;
    var a=obj.find(">p>a,>a");
    var div=obj.find("div");
    var maxHeight;

    if (!obj.hasClass("blue"))//*** se e' l'accordion classico, accorcia il testo dei p
    {
        obj.find("p").each(
            function()
            {
                var p=$(this);
                if (p.text().length>130) p.text(p.text().substring(0,130)+"[..]");
            }
        );
        maxHeight=parseInt(div.eq(0).css("max-height"));//+(a.length*parseInt(a.filter(":first").height()));  //422;
    }
    else
    {
        var li=obj.find("ul:first li");
        maxHeight=li.length*li.eq(0).height();
    }

    var animationOn=false;
    var anim;
    div.eq(0).height(maxHeight);//parseInt(div.filter(".current").css("max-height")));

    function slide(_this) /* meglio dell'animate di jquery */
    {
        var startHeight=maxHeight;
        var current=obj.find("a.current");
        var divCurrent=current.next();
        if (divCurrent.length==0) divCurrent=current.parent().next(); //*** fck puo' incapsulare la a in un p e quindi, senza questo controllo non funzionerebbe
        var _thisDiv=_this.next("div");
        if (_thisDiv.length==0) _thisDiv=_this.parent().next("div"); //*** fck puo' incapsulare la a in un p e quindi, senza questo controllo non funzionerebbe

        anim = setInterval(
            function () {
	            slide_accordion();
            }, 1 
        );

        function slide_accordion()
        {
            if (startHeight>=9)
            {
               startHeight-=speed;
                divCurrent.height(startHeight);
//                _thisDiv.addClass("current");
                _thisDiv.height(maxHeight-startHeight);
            }
            else
            { 
                divCurrent.height(0);
                _thisDiv.height(maxHeight);
                clearInterval(anim);
                current.removeClass("current");
                divCurrent.removeClass("current");
                _this.addClass("current");
                _thisDiv.addClass("current");
                animationOn=false;
            }
        }    
    }

    a.click(
        function()
        {
            if (animationOn) return;
            animationOn=true;
            var _this=$(this);
            if (!_this.hasClass("current")) slide($(this));
            else animationOn=false;
        }
    ); 
}

var hotSpots={
    hotspots:null,
    loop:0,
    limit:11,
    offset:97,
    start:function()
    {
        hotSpots.hotspots=$("#hotspot div a > span");
        if (hotSpots.hotspots.length==0) return;
        var go=setInterval(hotSpots.changeBg,100);
    },
    changeBg:function()
    {
        hotSpots.loop++;
        if (hotSpots.loop>hotSpots.limit) hotSpots.loop=0;
        hotSpots.hotspots.css("background-position","5px -" + hotSpots.loop*hotSpots.offset+"px");
    }
}





