
var AccessoriesFeatureExpandable = Class.create();
AccessoriesFeatureExpandable.prototype = {
	initialize: function(options) {
		this.options = Object.extend({
		    lang_id: 2,
			container_id:'accessories_expandable',
			expandable_control:'tr.expandable_control',
			expandable_content:'div.expandable_content'
		}, options || { });
		
		this.create();
	},
	create: function() {
		this.lang_id = this.options.lang_id
		this.container = $(this.options.container_id);
		if(this.container) {
			var me = this;
			me.expandable_controls = this.container.getElementsBySelector(this.options.expandable_control);
			me.expandable_contents = this.container.getElementsBySelector(this.options.expandable_content);
			me.expandable_controls.each(function(h,i) {
				var index = i;
				h.onmousedown = function(){
					me.open(index);
				}
			});
		}
	},
	open: function(index) {
		var me = this; 
        if(me.expandable_contents[index].visible()) {
            me.expandable_contents[index].hide();
        }
        else {     
            var url = '/AjaxAccessories.aspx';
            var pars = 'lng=' + me.lang_id;
            pars    += '&specitemid=' + me.expandable_contents[index].id;
            new Ajax.Updater(me.expandable_contents[index], url,{
	            method: 'get',
	            parameters: pars,
	            evalScripts:true,
	            onComplete: function() {
		            me.expandable_contents.each(function(h,i) {			    
			            if(index==i) {
			                h.show();
			            }
			            else {
			                h.hide();
			            }
		            });
	            }
            });
        }
	}
};
