// Ask the expert ******************************************************
var styledDrop = null;
function goTo(url) {
	window.location = url;	
}

Event.observe(window, 'load', function() {
	if ($('styled_dropdown')) {
		styledDrop = new myDropdown('styled', function(el) {
			selectstyledDrop(el);
		});
	}
	if ($('showme')) {
		$('showme').onclick= function () { 
			$('askexpertform').toggle();
			return false;
		};
	};
});



// styled dropdown menus ******************************************************

function selectstyledDrop(el) {
	curItem = el.id;
	if (curItem != '') {
		curItem = curItem.replace('-', '/');
		curItem = curItem.replace('-', '/');
		var url = '/'+curItem+'/';
		goTo(url);
	}
}

var myDropdown = Class.create();
myDropdown.prototype = {
	_name : null,
	_callback : null,
	_runCallback : null,
	
	initialize : function (name, callback) {
		this._name = name;
		this._callback = callback;
		this._runCallback = true;
		var self = this;
		
		$(name+'_dropdownBack').onclick= function () { self.toggleOptions() };
		
		this.loadEvents();
		
		self = this;
		Event.observe(document.body, 'click', function (evt) {
			var el = Event.element(evt);
			var name = self._name;
			
			if (el.id != name+'_dropdown' && 
				el.id != name+'_dropdownBack' && 
				el.id != name+'_dropdownPad' && 
				el.id != name+'_selection' && 
				el.id != name+'_arrow' && 
				el.id != name+'_arrowImg' && 
				el.id != name+'_options' && 
				el.className != 'dropOption' &&
				el.parentNode.className != 'dropOption' &&
				el.parentNode.parentNode.className != 'dropOption'
			) {
				if ($(name+'_options') && $(name+'_options').style.display == 'block') self.toggleOptions();
			}
		});
	},
	
	loadEvents : function() {
		var self = this;
		$$("#"+this._name+"_options .dropOption").each(function(el) {
			Event.observe(el, 'click', function() { self.makeSelection(el) });
		});	
	},
	
	decideShown : function (selEle) {var self = this;},
	
	makeSelection : function(el) {
		var curID = el.id;
		var convention = this._name+'_Op_';
		var curSelection = curID.replace(convention, '');
		this.setDropSelection(curSelection);
		
		this.decideShown(el);
		var ops = $(this._name+'_options');
		if (ops.style.display == 'block') this.toggleOptions();
		
		//if false it will skip the beat and set it back after
		if (this._runCallback) {
			this._callback(el);
		}
		else this.setRunCallBack(true);
	},
	
	setDropSelection : function(id) {
		this._dropSelection = id;
		return this._dropSelection;
	},
	getDropSelection : function() {
		return this._dropSelection;
	},
	toggleOptions : function() {
		var ops = $(this._name+'_options');
		if (ops.style.display == '' || ops.style.display == 'none') {
			ops.style.display = 'block';
			$('styled_dropdownBack').addClassName('clickclose');
		} else {
			ops.style.display = 'none';
			$('styled_dropdownBack').removeClassName('clickclose');
		}
	}
}

