var County = new Class ({

initialize: function(options){
	options = $merge({
		'id':0,		
		'border': Class.empty,
		'index': 0,
		'onClick':Class.empty
	}, options);
	
	this.id = options.id;
	this.border = options.border;
	this.index = options.index;
	this.onClick = options.onClick;
},

init: function(){
	this.border.init();
},

draw: function(mapdiv){
	var AreaEl = new Element('area', {
		'shape':'poly',
		'coords': this.border.mapArea,
		'alt':this.border.imgAlt
	});
	AreaEl.title = "Tips Title :: " + this.border.imgAlt;
	var id = this.id;		
	AreaEl.injectInside(mapdiv);
	AreaEl.addEvent('mouseout', this.onOut.bind(this));
	AreaEl.addEvent('mouseover', this.onOver.bind(this));
	AreaEl.addEvent('click', this.onClick.pass(this.index));
	if(window.ie===true){
	}else{
		this.tips = new Tips(AreaEl, { className: 'custom' });	
	}
},

onOut: function(){
	this.border.onOut();
},

onOver: function(){
	this.border.onOver();
},

onclick: function(wasselect,sender) {
	this.sender =  sender;
	if(!wasselect) {		
		this.border.setSelect();
	}
},

//drawTownListByCounty: function(isempty){
//	if(!isempty){
//		if($defined(this.townList)) {			
//			this.getTownListCallback(this.townList);
//		} else {			
//			InplaceRequestProcessor.getTownListByCounty(this.id, this.getTownListCallback.bind(this));			
//		}		
//	} else {
//		if($defined(sender.townList)) {
//			this.getTownAllList(sender.townlist);
//		}else {
//			InplaceRequestProcessor.getTownListByCounty(0, this.getTownAllList.bind(this));
//		}		
//	}
//},


//getTownListCallback: function(townlist, isAllList){
//	if(!$defined(isAllList))
//		this.townList = townlist;
//	var town = $(this.townId); 
//	town.empty();
//	
//	var El0 = new Element('option', {
//	    'value': ''            
//	});
//	El0.appendText('All areas');
//	El0.injectInside(town);
//	
//	if($defined(townlist)){			
//		for(i=0; i<townlist.length; i++){
//			var El = new Element('option', {
//				'value': townlist[i].id
//			});
//			El.appendText(townlist[i].name);
//			El.injectInside(town);			
//		}
//	} 
//},

//getTownAllList: function(townlist){
//	this.getTownListCallback(townlist, true);
//	this.sender.townlist=townlist;
//},

setOnChange:function(onChange) {
	this.onChange = onChange;
},

setIndex: function(index){
	this.index = index;
},

getCountyTownList: function(callBackTownList) {
	this.callBackTownList = callBackTownList;
	if(!$defined(this.townList)) {			
		InplaceRequestProcessor.getTownListByCounty(this.id, this.getTownListCallback.bind(this));			
	} else {
		this.getTownListCallback(this.townlist);
	}
	return this.townList; 
},

getTownListCallback: function(townlist){
	if(!$defined(this.townlist)) 
		this.townlist = townlist;
	if($defined(this.callBackTownList))
		this.callBackTownList(this.townlist);
}

});
