function paymentOfferChk(ref,skip) {
	
	if(!skip) {
		if(ref.checked) {
			ref.checked = false;
		} else {
			ref.checked = true;
		}
	}
	
	var v = $('payvalue');
	if(ref.checked) {
		v.value = ref.value;
	} else {
		v.value = '';
	}
	Reservation.updateRes();
}

function RoomsSelector(div,currentRoom) {
	
	var obj;
	var currentRoom;
	
	this.obj = $(div);
	this.currentRoom = currentRoom;
	
	this.init();
}

RoomsSelector.prototype.init = function() {
	
	var ref = this;
	var total = $$('.Variant').size();
	
	//console.log(total);
					
	this.list = document.createElement('div');
	this.list.className = 'RoomsList';	
	this.list.innerHTML = this.obj.innerHTML;
	this.list = $(this.list);
			
		/*var currentRoomObj = this.list.down('.Room-'+this.currentRoom);
	 var currentRoomObj = currentRoomObj.cloneNode(true);
	 var info = currentRoomObj.down('.Variants');
	 info.remove(info);*/
		//currentRoomObj.obj = this;
		$('RoomsSelectCurrent').obj = this;
		
		
		if (total > 1) {
			$('RoomsSelectCurrent').onclick = function(){
				this.obj.showList();
			}
		} else {
			
			$('RoomsSelectCurrent').addClassName('static');
			
		}
		
		this.obj.innerHTML = '';
		//this.obj.appendChild(currentRoomObj);
		this.obj.appendChild(this.list);
		
		this.list.hide();
		var ref = this;
		
		if (total > 1) {
		
			$$('.VariantHit').each(function(e){
				e.onclick = function(){
					ref.selectVariant(this);
				}
				e.onmouseover = function(){
					this.up().addClassName('hv');
				}
				e.onmouseout = function(){
					this.up().removeClassName('hv');
				}
			});
			
			$$('.Variants').invoke('hide');
			
			$$('.RoomsList .Room').each(function(e){
				e.onclick = function(){
					ref.showVariants(e);
				}
				e.onmouseover = function(){
					this.addClassName('hv');
				}
				e.onmouseout = function(){
					this.removeClassName('hv');
				}
				
				if(e.select('.Variant').length > 1) {
					e.select('.Variants')[0].show();
				}
				
			});
			
			$$('.Room-' + this.currentRoom)[0].addClassName('act');
			
			var currentVariants = $$('.Room-' + this.currentRoom)[0].down('.Variants');
			if (currentVariants.select('.Variant').length > 1) {
				currentVariants.show();
			}
			
			var closeBar = document.createElement('div');
			closeBar.className = 'RoomsClose';
			closeBar.innerHTML = Lang.get('wybierzPokojIWariant')+'<div id="rooms_close">'+Lang.get('zamknij')+'</div>';
			this.list.insertBefore(closeBar, this.list.firstChild);
			
			$("rooms_close").onmouseover = function(){
				$(this).addClassName('hv');
			}
			$("rooms_close").onmouseout = function(){
				$(this).removeClassName('hv');
			}
			
			$('rooms_close').onclick = function(){
				ref.list.hide();
			}
		
		}
	
}


RoomsSelector.prototype.showList = function() {
	this.list.show();
	var ref = this;
	document.onclick = function(e) { 
		if (e) {
			var p = $(e.target).up('#offer_form');
			if (!p) {
				document.onclick = false;
				ref.list.hide();
			}
		}
	}
}

RoomsSelector.prototype.selectVariant = function(ref) {
	var input = ref.up().down('input');
	if(input) {
		input.checked = true;
		Reservation.updateRes();
	}	
}

RoomsSelector.prototype.showVariants = function(ref) {	
	//$$('.Variants').invoke('hide');
	//this.list.down('.Variants').show();
	var variants = ref.select('.Variant');

	if (variants.length == 1) {
		this.selectVariant(variants[0].down('.VariantHit'));
	}
	else {
		//ref.down('.Variants').show();
	}
}

