function initPopups()
{
	initPopup({
		openEvent:'click'
	});
}
if (window.addEventListener)
	window.addEventListener("load", initPopups, false);
else if (window.attachEvent)
	window.attachEvent("onload", initPopups);
	
function initPopup(_popup) {
	if (!_popup.popupHolderTag) _popup.popupHolderTag = 'div';
	if (!_popup.popupTag) _popup.popupTag = 'div';
	if (!_popup.popupHolderClass) _popup.popupHolderClass = 'popup-holder';
	if (!_popup.popupClass) _popup.popupClass = 'popup';
	if (!_popup.linkOpenClass) _popup.linkOpenClass = 'open';
	if (!_popup.linkCloseClass) _popup.linkCloseClass = 'close';
	if (!_popup.openClass) _popup.openClass = 'active';
	if (!_popup.openEvent) _popup.openEvent = 'hover';
	
	var timer = [];	
	var _popupHolderTag = document.getElementsByTagName(_popup.popupHolderTag);
	if (_popupHolderTag) {
		for (var i=0; i<_popupHolderTag.length; i++) {
			if (_popupHolderTag[i].className.indexOf(_popup.popupHolderClass) != -1) {
				var _popupLink = _popupHolderTag[i].getElementsByTagName('a');
				for (var j=0; j<_popupLink.length; j++) {
					_popupLink[j].parent = _popupHolderTag[i];
					if (_popupLink[j].className.indexOf(_popup.linkOpenClass) != -1) {
						if (_popup.openEvent == 'click') {
							_popupLink[j].onclick = function(){
								if (this.parent.className.indexOf(_popup.openClass) != -1) {
									this.parent.className = this.parent.className.replace(_popup.openClass,'');
								} else {
									this.parent.className += ' '+_popup.openClass;
								}
								return false;
							}
						} else {
							var _popupTag = _popupHolderTag[i].getElementsByTagName(_popup.popupTag);
							for (var k=0; k<_popupTag.length; k++) {
								if (_popupTag[k].className.indexOf(_popup.popupClass) != -1) {
									_popupTag[k].parent = _popupHolderTag[i];
									_popupTag[k].onmouseover = function(){
										if (timer[j]) clearTimeout(timer[j]);
										if (this.parent.className.indexOf(_popup.openClass) == -1) {
											this.parent.className += ' '+_popup.openClass;
										}
									}
									_popupTag[k].onmouseout = function(){
										var _this = this;
										timer[j] = setTimeout(function(){
											_this.parent.className = _this.parent.className.replace(_popup.openClass,'');
										},2);
									}	
								}
							}
							_popupLink[j].onmouseover = function(){
								if (timer[j]) clearTimeout(timer[j]);
								if (this.parent.className.indexOf(_popup.openClass) == -1) {
									this.parent.className += ' '+_popup.openClass;
								}
							}
							_popupLink[j].onmouseout = function(){
								var _this = this;
								timer[j] = setTimeout(function(){
									_this.parent.className = _this.parent.className.replace(_popup.openClass,'');
								},2);
							}
						}
					} else if (_popupLink[j].className.indexOf(_popup.linkCloseClass) != -1) {
						_popupLink[j].onclick = function(){
							if (this.parent.className.indexOf(_popup.openClass) != -1) {
								this.parent.className = this.parent.className.replace(_popup.openClass,'');
							} else {
								this.parent.className += ' '+_popup.openClass;
							}
							return false;
						}
					}
				}
			}		
		}
	}
}


$(document).ready(function(){
	$('div.comment').each(function(){
		var _slideSpeed = 500;
		var _holder = $(this);
		var _opener = _holder.find('a.comment');
		var _slider = _holder.find('> div.in-comment');

		_opener.css('cursor','pointer');
		_slider.css('display','none');

		_opener.click(function(){
			if(_holder.hasClass('expanded')) {
				_slider.slideUp(_slideSpeed);
				_holder.removeClass('expanded')
			} else {
				_slider.slideDown(_slideSpeed);
				_holder.addClass('expanded')
			}
			return false;
		});
	});
});


function initInputs() {
	var _inputs = document.getElementsByTagName('input');
	if (_inputs) {
		for(var i=0; i<_inputs.length; i++) {
			if (_inputs[i].type == 'text' || _inputs[i].type == 'password') {
				_inputs[i].alt = _inputs[i].value;

				_inputs[i].onfocus = function(){
					if(this.value==this.alt) this.value='';
					_value = this.value;
				}
				_inputs[i].onblur = function(){
					if (this.value == '')
					this.value = this.alt;
				}
			}
		}
	}
	var _textareas = document.getElementsByTagName('textarea');
	if (_textareas) {
		for(var i=0; i < _textareas.length; i++) {
			if (_textareas[i].value) {
				_textareas[i].title = _textareas[i].value;

				_textareas[i].onfocus = function(){
					if(this.value==this.title) this.value='';
					_value = this.value;
				}
				_textareas[i].onblur = function(){
					if (this.value == '')
					this.value = this.title;
				}
			}
		}
	}
}

if (window.addEventListener)
	window.addEventListener("load", initInputs, false);
else if (window.attachEvent)
	window.attachEvent("onload", initInputs);
	
function WBM_buildChildSelector(selectedValue, child, childValue, childLevel, arrDescendant, prefix)
{
	var selectedArray = eval(child + "JSArray");

	//*** Clear the old list (above element 0)
	//*** 0 - will display the new options only
	//*** 1 - will display the first existing option plus the new options
	count = 1;
	
	for (var i=0; i<arrDescendant.length; i++) 
	{
		descSelector = window.document.getElementById(prefix + arrDescendant[i]);
		descSelector.disabled = false;
		descSelector.options.length = count;
	}

	//*** Place all matching categories into Options.
	var tmpArr = new Array();
	childSelector = window.document.getElementById(prefix + arrDescendant[0]);
	for (var i=0; i<selectedArray.length; i++) 
	{
		tmpArr = selectedArray[i].split("|");
		if ( (childLevel == '1' && tmpArr[2] == selectedValue) || (childLevel == '2' && tmpArr[3] == selectedValue) ) 
		{
			 var childSelected = tmpArr[1]==childValue? true : false;
			 //*** new Option([text], [value], [defaultSelected], [selected])
			childSelector.options[count++] = new Option(tmpArr[0], tmpArr[1], false, childSelected);
		}
	}
				
	if (count == 1) 
	{
		childSelector.disabled = true;
		if (arrDescendant[1] != null) 
		{
			WBM_buildChildSelector(selectedValue, arrDescendant[1], '', '2', new Array(arrDescendant[1]), prefix);
		}
	} 
	
	/*if (childSelector != null && childSelector.disabled == false) 
	{
		//childSelector.options.selectedIndex = 2;
		childSelector.focus();
	}*/
}
