﻿Photos = function(params2)
// objectId - объект цвет которого надо изменить
// inputTextId - id inputа со строковым представлением цвета 
{
    this._object = document.getElementById(params2.objectId);
    this._objectId = params2.objectId;
    this.inputText = document.getElementById(params2.inputTextId);
    this.inputTextId = params2.inputTextId;
    this.titleText = document.getElementById(params2.titleTextId);
    this.titleTextId = params2.titleTextId;
    this.styleColor = params2.styleColor;
    this._containerId = params2.containerId;
    // eval('this.oldColor = this._object.style.'+params.styleColor);
    // this.inputText.value = this.oldColor;

    Photos.list[Photos.list.length] = 'allcolorselements' + this.inputTextId;

    this.pallete2 = params2.pallete2;

    this.rows = params2.rows;
    this.cols = params2.cols;
    this.width = params2.width;
    this.height = params2.height;
    this.border = params2.border;
    this.allwidth = this.cols * (this.width + this.border * 4) + this.border;
    this.allheight = 200;
    this.show();
}

Photos.list = new Array();

Photos.prototype.show = function() {
    var bttn = '<span id="allcolorselementsselect' + this.inputTextId + '" onclick="e = event||window.event; e.cancelBubble = true; document.getElementById(\'allcolorselements' + this.inputTextId + '\').style.display=\'block\'; document.getElementById(\'allcolorselementslink' + this.inputTextId + '\').focus();" style="cursor: pointer;"><span style="text-decoration: underline;"><img src="../images/design/add.png" border="0" width="16" height="16" class="iePNG"></span></span>';
    var table = '<input id="setc' + this.inputTextId + '" type="hidden" value="0" />';
    table += '<input id="oldColor' + this.inputTextId + '" type="hidden" value="#' + this.oldColor + '" />';
    table += '<div id="allcolorselements' + this.inputTextId + '" style="width: ' + this.allwidth + 'px; cursor: pointer; display: none; position: absolute; top:35px; z-index:1000; background-color:#bbb; border:solid 1px #bbb;">';
    table += '<iframe style="position:absolute; width:' + this.allwidth + 'px; height:' + this.allheight + 'px;left:0;border:none;z-index:-1; _filter:mask();"></iframe>';    
    table += '<a id="allcolorselementslink' + this.inputTextId + '" href="#" onclick="document.getElementById(\'allcolorselements' + this.inputTextId + '\').style.display=\'none\'; if (document.getElementById(\'setc' + this.inputTextId + '\').value!=\'1\') Photos.changecolor(document.getElementById(\'oldColor' + this.inputTextId + '\').value, \'' + this._objectId + '\', \'' + this.inputTextId + '\', \'' + this.styleColor + '\'); document.getElementById(\'setc' + this.inputTextId + '\').value=\'0\'; return false;">';   
    
    for (var i = 1, c = 0; i <= this.rows; i++) {
        //table += '<tr height="20">';
        for (var j = 1; j <= this.cols; j++) {
            table += '<div style="float:left; width:' + this.width + 'px; height:' + this.height + 'px; margin:' + this.border + 'px; border:solid ' + this.border + 'px #000;" onmousedown="document.getElementById(\'setc' + this.inputTextId + '\').value=\'1\'; document.getElementById(\'oldColor' + this.inputTextId + '\').value=this.style.backgroundColor;" onmousemove="Photos.changecolor(' + this.pallete2[c].id + ', \'' + this._objectId + '\', \'' + this.inputTextId + '\', \'' + this.styleColor + '\', \'' + this.titleTextId + '\', \'' + this.pallete2[c].title + '\');" onmouseover="this.style.border=\'solid ' + this.border + 'px #ffff00\'" onmouseout="this.style.border=\'solid ' + this.border + 'px #000\';"><img style="width:99px; height:62px;" src="' + this.pallete2[c].src + '" alt="' + this.pallete2[c].title + '" border="0" /></div>';
            c++;
        }
        table += '<div style="clear:both;"></div>';
    }
    table += '</a></div>';

    var container = document.getElementById(this._containerId);
    container.innerHTML = table;

    document.writeln(bttn);
}

Photos.changecolor = function(thiscolor, _object, inputText, styleColor) {
    //eval('document.getElementById(_object).style.'+styleColor+' = thiscolor');
    document.getElementById(inputText).value = thiscolor;
    if (arguments.length >= 5) {
        document.getElementById(arguments[4]).value = arguments[5];
    }
}

Photos.setup = function(params2) {
    function param_default(pname, def) { if (typeof params2[pname] == "undefined") { params2[pname] = def; } };
    param_default("rows", 3);
    param_default("cols", 3);
    param_default("width", 100);
    param_default("height", 63);
    param_default("border", 1);
    param_default("styleColor", "color");
    param_default("inputTextId", null);
    param_default("titleTextId", null);
    param_default("objectId", null);
    param_default("containerId", null);
    param_default("pallete2", new Array(
        { title: 'Лонг', src: './images/bodies/long.jpg', id: 1 }, { title: 'Внедорожник', src: 'images/bodies/suv.jpg', id: 2 }, { title: 'Кабриолет', src: 'images/bodies/cabriolet.jpg', id: 3 }, { title: 'Купе', src: 'images/bodies/coupe.jpg', id: 4 }, { title: 'Минивэн', src: 'images/bodies/minivan.jpg', id: 5 }, { title: 'Пикап', src: 'images/bodies/pickup.jpg', id: 6 }, { title: 'Седан', src: 'images/bodies/sedan.jpg', id: 7 }, { title: 'Универсал', src: 'images/bodies/universal.jpg', id: 8 }, { title: 'Хэтчбек', src: 'images/bodies/hatchback.jpg', id: 9 }
    ));

    var col = new Photos(params2);
    return col;
}


