function MaterialSupport() { } var $MSP = MaterialSupport.prototype; $MSP.constants = { MATERIAL_REQUEST_ITEM : 'pseudo_getmaterials', GROOVE_STYLE : 'groove_style', PAIRRING : 'pairring', FEMALERING : 'femalering', MATERIALS : 'materials', REPLACEMENTS : {/*5:3,6:3,*/7:3} }; $MSP.replaceable = function($color) { for (var $c in this.constants.REPLACEMENTS) { if ($c == $color) {return true;} } return false; }; $MSP.getMaterialRequestItem = function() { return 'pseudo_getmaterials'; }; $MSP.getGrooveStyle = function() { return 'groove_style' }; $MSP.getReplacement = function($color) { return this.constants.REPLACEMENTS[$color] === undefined ? 1 : this.constants.REPLACEMENTS[$color]; }; $MSP.getRequestGender = function($gender) { $gender = $gender || setGender; return ($gender==this.constants.PAIRRING) ? this.constants.FEMALERING : $gender; }; $MSP.getMaterial = function($callback) { GetAvalibleItems(this.getRequestGender(), this.getMaterialRequestItem(), $callback); }; $MSP.getFirstMaterial = function($callback) { this.getMaterial(function($d) { $callback($d.items[0][0]); }); }; $MSP.replace = function($callback) { var self = this; this.getFirstMaterial(function($material) { if (self.replaceable($material.color)) { SetItemValueDirect(setGender, self.constants.MATERIALS, [0, self.getReplacement($material.color), $material.surface], function($d) { AnalyzeSetData($d); $callback(); }); } else { if ($callback != null) { $callback(null); } } }); }; $MSP.refresh = function() { this.getMaterial(test); GetActiveItem(this.getRequestGender(), this.getGrooveStyle(), ShowActiveGrooveStyle); }; $MSP.isOneColored = function($division) { return ($division == 0); }; $MSP.setColorEnabled = function($color, $enabled) { var controller = $("#c" + $color); if (!$enabled) { controller.addClass("disabled") disable(); } else { controller.removeClass('disabled').removeAttr('style').unbind('click'); } }; $MSP.handleColor = function($color, $division, $callback) { var self = this; $division = $division || this.getDivision(); var $oneColored = this.isOneColored($division); function $finally() { for (var $c in self.constants.REPLACEMENTS) { self.setColorEnabled($c, $oneColored); } if ($callback != null) { $callback(); } } $oneColored ? $finally() : this.replace($finally); }; $MSP.getDivision = function() { // Dummy implementation return $('#selected_division').attr('src').replace(/^.*division_([0-9]+).*$/, "$1"); }; $MSP.getFirstColor = function() { return $('.box_cm1 a').attr('class').substr(9, 2); };