﻿function backgroundPosition(obj)
{
    var p = obj.css('background-position');
    if(typeof(p) === 'undefined')
    {
        return obj.css('background-position-x') + ' ' + obj.css('background-position-y');
    }
    else
    {
        return p;
    }
}

$(function() {
    regCL();
});

function regCL() {
    $(".itemCbo").click(
            function() {
                $(this).parent().hide();

                var img = $(this).children(".imagenDentroCbo").css("background-image");
                var pos = $(this).children(".imagenDentroCbo").css("background-position");
                var texto = $(this).children(".cboLindotxt").html();

                $(this).parent().siblings(".btnDefecto").children(".imagenDentroCbo").css({ "background-image": img });
                $(this).parent().siblings(".btnDefecto").children(".imagenDentroCbo").css({ "background-position": pos});
                $(this).parent().siblings(".btnDefecto").children(".cboLindotxt").html(texto);

            });

    $("#panelBotones.panelBotones").unbind("mouseleave");
    $("#panelBotones.panelBotones").mouseleave(
                function() {
                    $(this).fadeOut();
                });
                
    $(".itemCbo").unbind("mouseover");
    $(".itemCbo").mouseover(
                function() {
                    if (backgroundPosition($(this)) == "0px -47px") {
                        $(this).css("background-position", "0px -22px");
                    } else {
                        $(this).css("background-position", "0px -72px");
                    }
                });

    $(".itemCbo").unbind("mouseout");
    $(".itemCbo").mouseout(
                    function() {
                        //alert('pos mouseout ' + backgroundPosition($(this)));
                        if (backgroundPosition($(this)) == "0px -22px") {
                            $(this).css("background-position", "0px -47px");
                        } else {
                            $(this).css("background-position", "0px -94px");
                        }
                    });

    $('.btnDefecto').unbind("click");
    $('.btnDefecto').click(function() {
        mostrarPanelBotones($(this).siblings('#panelBotones'));
    });
}

function mostrarPanelBotones(elem) {
    if (elem.css("display") == "none") {
        elem.css({ "display": "block" });
    } else {
        elem.css({ "display": "none" });
    }
}
