var UnicDropdown = Class.create();

UnicDropdown.prototype = {
		
	timeOutId: null,
	
	initialize: function(){
	
	},
	
	display: function(id){
		if(this.timeOutId != null){
			window.clearTimeout(this.timeOutId);
		}
		if(id != null && $(id) != null){
			$(id).show();
		}
	},
	
	hide: function(id){
		
		if(id != null && $(id) != null){
			if(this.timeOutId != null){
				window.clearTimeout(this.timeOutId);
			}
			this.timeOutId = Element.hide.delay(1, id);
		}
	}
}

var UnicFilterDropdown = Class.create();

UnicFilterDropdown.prototype = {
		
	timeOutId: null,
	timeOut: 0.2,
	open: 0,
	relatedDropdown: null,
	openId: null,
	objectId: null,
	
	initialize: function(id){
		this.objectId = id;
//		var isOpen = this.getCookie(this.objectId+'filterIsOpen');
//		if(isOpen == 1){
//			this.display(this.getCookie(this.objectId+'filterIsOpenId'));
//		}
	},
	
	setTimeOut: function(timeOut){
		this.timeOut = timeOut;
	},
	
	display: function(id){
		if(this.timeOutId != null){
			window.clearTimeout(this.timeOutId);
		}
		if(id != null && $(id) != null){
			if(this.relatedDropdown != null){
				if($(this.relatedDropdown).visible()){

					$(id).addClassName('white');
					$(id).removeClassName('black');
	
				}
				else{

					$(id).addClassName('black');
					$(id).removeClassName('white');

				}
			}
			$(id).show();
			this.open = 1;
//			this.setCookie(this.objectId+'filterIsOpen', 1);
//			this.setCookie(this.objectId+'filterIsOpenId', id);
		}
	},
	
	setRelatedDropdown: function(relatedDropdown){
		this.relatedDropdown = relatedDropdown;
	},
	
	hide: function(id){
		
		if(id != null && $(id) != null){
			if(this.timeOutId != null){
				window.clearTimeout(this.timeOutId);
			}
			if(this.timeOut == 0){
				$(id).hide();
			}
			else{
				this.timeOutId = Element.hide.delay(this.timeOut, id);
			}
		}
	},
	
	hideOrShow: function(id){
		if(this.open == 0){
			this.sendFilterStatusAjaxRequest('open');
			this.open = 1;
			this.display(id);
		}
		else{
			this.sendFilterStatusAjaxRequest('close');
			this.open = 0;
//			this.setCookie(this.objectId+'filterIsOpen', 0);
			this.hide(id);
		}
	},
	
	sendFilterStatusAjaxRequest: function(status){
		var host = location.host;
		var protocol = location.protocol;
		var url = protocol + "//" + host + "/modifications/index/setFilterDropdownStatus?status=" + status;		
		var options = {
				method: 'get',
				onSuccess: function(response){
				}
			};
		new Ajax.Request(url, options);
	},
	
	setCookie: function(name, value){
		var cookieString = name + "=" + escape(value);
		document.cookie = cookieString;
	},
	
	getCookie: function(name){
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0){
				return c.substring(nameEQ.length,c.length);
			}
		}
		return null;

	}
	
}



