var jq = jQuery.noConflict();

//var hexDigits = new Array
//        ("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f");

//function hex(x) {
//  return isNaN(x) ? "00" : hexDigits[(x - x % 16) / 16] + hexDigits[x % 16];
// }
//
//
////Function to convert hex format to a rgb color
//function rgb2hex(rgb) {
// rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
// return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
//}


//funzione associata la cambio immagine colore del prodotto
//function changeColor(element) {
///*ROBA fatta con prototype ma dato che è piuttosto legnoso
//             *proviamo con jquery
//             *$colore = element.getAttribute('data-colore');
//
//                $$('div[class=colore]').each(function(s)
//                {
//                    if (rgbConvert(s.getStyle('background-color'))==$colore)
//                        {
//                            s.onclick();
//                        }
//                }
//            );*/
//
//            var $elemento = jq(element);
//            jq("#colori div").each(
//                function(){
//                    var RGB = jq(this).css('background-color');
//                    if(RGB.indexOf("#")<0){
//                        RGB = rgb2hex(jq(this).css('background-color'));
//                    }
//                    if(RGB == $elemento.attr('data-colore')){
//                        if(!jq(this).hasClass("selezionato")){
//                            jq(this).click();
//                        }
//                        return true;
//                    }
//                }
//            );
//}

function setImageFromDropdown(element){
  
    var col_dd= jq(element+'option:selected').text();
    jq("#MagicToolboxSelectorsContainer a").each(
        function(){
            
             if(col_dd == jq(this).attr('data-colore')){
                
                   MagicZoomPlus.update('MagicZoomPlusImagemagictoolbox1', jq(this).attr('href'), jq(this).attr('rev'), '');
                }

        });

}


//imposta l'immagine a partire
//function setCurrentImnage(element){
//    $elemento = jq(element);
//    jq("#MagicToolboxSelectorsContainer a").each(
//        function(){
//           var colore = $elemento.attr('alt');
//
////           if(RGB.indexOf("#")<0){
////               RGB = rgb2hex($elemento.css('background-color'));
////           }
//           if(colore == jq(this).attr('data-colore')){
//                //jq(this).parent().each(function(){
//                    //jq(this).parent().each(function(){
//                        //alert("ci clicco"+jq(this).attr("class"))
//                        MagicZoomPlus.update('MagicZoomPlusImagemagictoolbox1', jq(this).attr('href'), jq(this).attr('rev'), '');
//                    //});
//                //});
//                return true;
//            }
//        }
//    );
//}
