var arrAutos = new Array("v1.png","v2.png","v3.png","v4.png","v5.png","v6.png");

var carrousel;
var winfo = {
    show: function(sender) {
        jQ("#winfo_cont").html(sender.find(".winfo").clone().html());
        sender.first().hide();
        var lightopc;
        var strLight = sender.attr("light");
        if (strLight) {
            eval("lightopc = {" + sender.attr("light") + "}");
            jQ("#light_izq").css(lightopc.izquierda);
            jQ("#light_der").css(lightopc.derecha);
        }
        jQ("#winfo").show();
        jQ("#imginfo").attr("src", sender.find("img").attr("src"));
    },
    hide: function() { jQ(".roundabout-moveable-item").css("display", "block"); jQ("#winfo").hide(); jQ("#winfo_cont").empty(); }
}
jQ(document).ready(function() {
    var tooltip = {
        update: function(coord) { jQ("#ttip").css("top", coord.pageY).css("left", coord.pageX); },
        show: function(sender) { jQ("#cont_ttip").html(sender.siblings(".ttip").clone().html()); jQ("#ttip").show(); },
        hide: function() { jQ("#ttip").hide(); jQ("#ttip .ttip").remove(); }
    }

    carrousel = jQ('#carrousel');
    carrousel.find("img").each(function() {
        if (jQ.browser.msie) {
            jQ(this).css("filter", "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',sizingMethod='scale',src='" + jQ(this).attr("src") + "')");
        }
    });
    jQ("#winfo img, .faros").each(function() {
        if (jQ.browser.msie)
            jQ(this).css("filter", "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',sizingMethod='scale',src='" + jQ(this).attr("src") + "')");
    });
    carrousel.roundabout({
        shape: 'tearDrop',
        minScale: 0.4,
        duration: 900,
        maxOpacity: 1,
        minOpacity: 1,
        tilt: 0,
        reverse: false,
        minZ: 80,
        maxZ: 80 + (arrAutos.length -1),
        childSelector: "div",
        startingChild: 3/*, debug : true*/
    }, function() {
        var imgBg = new Image();
        for (var nImg = 1; nImg <= arrAutos.length; nImg++) {
            imgBg = new Image();
            imgBg.src = "img/autosHome/" + arrAutos[nImg - 1];
            carrousel.find("img:eq(" + (nImg - 1) + ")").attr("src", imgBg.src);
        }
        setTimeout(function() {
            carrousel.css("display", "block");
            carrousel.roundabout_animateToChild(0);
        }, 1000);
        carrousel.find("img").mousemove(function(coord) {
            tooltip.update(coord);
        }).mouseenter(function() {
            tooltip.show(jQ(this));
        }).mouseleave(function() {
            tooltip.hide();
        });
    });
    var curObj
    var nRound = 0;
    var bolInfo = false;
    carrousel.find("div").focus(function() {
        var f; var e = 130; var g = 250; var c = false; nRound++;
        if (jQ(this).hasClass("roundabout-in-focus") && curObj != this) {
            jQ(document).nap(function() { SigModelo(); }, function() { }, 100);
            carrousel.find('div[current-scale="0.5500"]').each(function() {
                f = jQ(this).position();
                if (f.left < 100) {
                    jQ(this).animate({ left: f.left + e }, g, function() { });
                }
                else {
                    jQ(this).animate({ left: f.left - e }, g, function() { });
                }
            });
            carrousel.find('div[current-scale="0.8500"]').each(function() {
                f = jQ(this).position();
                if (f.left > 100) {
                    jQ(this).animate({ left: f.left + 20, top: f.top + 20 }, g, function() { });
                }
                else {
                    jQ(this).animate({ left: f.left + 5, top: f.top + 35 }, g, function() { });
                }
            });
            curObj = this;
            var nCurRound = jQ.browser.msie ? 2 : 1;
            if (nRound > nCurRound)
                setTimeout(function() { winfo.show(jQ(curObj)); }, g);
        }
    });

    jQ("#winfo").hover(function() { bolInfo = true; }, function() { bolInfo = false; });
    jQ(document).mouseup(function() {
        if (!bolInfo) { winfo.hide(); }
    });
    jQ(".roundabout-moveable-item img").click(function() {
        var item = jQ(this).parent();
        if (item.hasClass("roundabout-in-focus"))
            winfo.show(item);
    });
    

});
function SigModelo() {
    winfo.hide();
    carrousel.roundabout_animateToPreviousChild();
}
function AntModelo() {
    winfo.hide();
    carrousel.roundabout_animateToNextChild();
}
