// Use prottype.js
var Section = Class.create();

/**
 *
 */
Section.prototype = {
	initialize: function(obj){
		this.obj = obj;
		this.object_id 	= this.obj.id.replace('_section', '');
		
		this.visible 	= $F(this.object_id +"_state") == 'true'?true:false; 
		this.windowState= $F(this.object_id +"_window_state") == 'true'?true:false; ;

		this.sectionObj	= $(this.object_id +'_section');
		this.blkObj		= $(this.object_id +'_blk');
		
		this.clearBtn	= $(this.object_id +'_clear_btn');

		// SwitchIcon
		//this.swicthIcon = new SwitchIcon(this, this.object_id);
		
		// Menu		
		this.menuObj = new Menu(this, this.object_id);
		
		// Help		
		this.helpOjb = new Help(this, this.object_id);
		
		// Clear
		Event.observe(this.clearBtn, 'click', this.onClick.bind(this));
	},
	
	isVisible:function() {
		return this.visible;
	},
	
	isWindowState:function() {
		return this.windowState;
	},
	
	setVisible:function(state) {
		this.visible = state;
		if (this.visible == true) {
			this.sectionObj.style.display= "inline";
			$(this.object_id +"_state").value = "true";	
			
			this.menuObj.setState(true);
			this.setWindowState(true);

		} else {
			this.sectionObj.style.display= "none";
			$(this.object_id +"_state").value = "false";
			
			this.menuObj.setState(false);
			this.helpOjb.setVisible(false);
			
			this.clearSearchArea();
		}
		CrossSearch.SetMenuInfomation();
	},
	
	setWindowState:function(state) {
		this.windowState = state;
		if (this.windowState == true) {
			this.blkObj.style.display= "inline";
			$(this.object_id +"_state").value = "true";	

			//this.swicthIcon.setVisible(true);

		} else {
			this.blkObj.style.display= "none";
			$(this.object_id +"_state").value = "false";
			
			//this.swicthIcon.setVisible(false);
		}		
	},
	
	clearSearchArea:function() {
		var list = this.blkObj.getElementsByTagName('input');
		for(var i = 0; i < list.length; i++) {
			var obj = list[i];
			if (obj.type == 'text') {
				obj.value = "";
			}
			else if (obj.type == "file") {
				obj.value = "";
				obj.disabled = true;
			}
			else if (obj.type == "radio") {
				obj.checked = false;
			}
			else if (obj.type == "checkbox") {
				obj.checked = false;
			}
		}	
		
		list = this.blkObj.getElementsByTagName('select');
		for(var i = 0; i < list.length; i++) {
			var obj = list[i];
			obj.selectedIndex = -1;
			
			if (obj.multiple == true) {
				obj.value = "";
			}
			else {
				obj.value = obj[0].value;
			}
		}	
		
		if (this.object_id == "gene_structure") {clearChrBandList();}
	},
	
	onClick:function() {
		this.clearSearchArea();
	}	
}

// Use prottype.js
var Menu = Class.create();

/**
 *
 */
Menu.prototype = {
	initialize: function(obj, id){
		this.parent = obj;

		this.obj 			= $(id +'_switch');
		this.iconObj		= $(this.obj.id +"_icon");
		this.closeIconObj 	= $(id +'_cls');
		
		Event.observe(this.obj, 'mouseover', this.onMouseOver.bind(this));
        Event.observe(this.obj, 'mouseout', this.onMouseOut.bind(this));
		Event.observe(this.obj, 'click', this.onClick.bind(this));
		Event.observe(this.closeIconObj, 'click', this.onClick.bind(this));
	},
	
	onMouseOver:function() {
		if (this.parent.isVisible() == true) {return;}
		this.obj.style.backgroundImage = 'url(./img/back_over.gif)';
	},
	
	onMouseOut:function() {
		if (this.parent.isVisible() == true) {return;}
		this.obj.style.backgroundImage = 'url(./img/back_active.gif)';
	},
	
	onClick:function() {
		this.parent.setVisible(!this.parent.isVisible());
	},
	
	setState:function(value) {
		if (value == true) {
			this.obj.style.backgroundImage = 'url(./img/back_over.gif)';
			this.iconObj.src = './img/icon/check.gif';				
		} else {
			this.obj.style.backgroundImage = 'url(./img/back_active.gif)';
			this.iconObj.src = './img/icon/check_off.gif';			
		}
	}
}

// Use prottype.js
var SwitchIcon = Class.create();

/**
 *
 */
SwitchIcon.prototype = {
	initialize: function(obj, id){
		this.parent = obj;
		this.iconObj= $(id +'_btn');
		
		Event.observe(this.iconObj, 'click', this.onClick.bind(this));
	},
	
	onClick:function() {
		if (this.parent.isWindowState() == true) {
			this.parent.setWindowState(false);
			
		} else {
			this.parent.setWindowState(true);
		}
	}, 
	
	setVisible:function(value) {
		if (value == true) {
			this.iconObj.src 	= "./img/icon/minus.gif";
			this.iconObj.alt	= "Min";
			this.iconObj.title	= "Min";

		} else {
			this.iconObj.src 	= "./img/icon/plus.gif";
			this.iconObj.alt	= "Max";
			this.iconObj.title	= "Max";
		}
	}
}

// Use prottype.js
var Help = Class.create();

/**
 *
 */
Help.prototype = {
	initialize: function(obj, id){
		this.parent = obj;
		
		this.iconObj= $(id +'_help_btn');
		this.blkObj	= $(id +'_help_blk');
		this.visible= false;
		
		Event.observe(this.iconObj, 'click', this.onClick.bind(this));

	},
	
	isVisible:function() {
		return this.visible;
	},
	
	onClick:function() {
		if (this.visible == true) {
			this.setVisible(false);
			
		} else {
			this.setVisible(true);
		}
	}, 
	
	setVisible:function(value) {
		if (value == true) {
			this.iconObj.src 	= "./img/icon/help_on.gif";
			this.blkObj.style.display = "inline";
			this.visible = true;
			
		} else {
			this.iconObj.src 	= "./img/icon/help.gif";
			this.blkObj.style.display = "none";
			this.visible = false;
		}		
	}
}