function watch_video(flv) {
	url = getPathToRoot() + 'swf/video_player.php?clip=' + flv;
	pop(url, 420, 440);
	return false;
}

function toggle_class(className) {

	// toggle visibility of elements by their class name
	var elements = getElementsByClass(className);
	
	var toggleLink = document.getElementById('toggle_' + className);
	
	for (i = 0; i < elements.length; i++) {
	
		element = elements[i];
		
		if (element.style.display == 'none') {
			// show
			element.style.display = '';
			if (toggleLink) {
				toggleLink.className += ' toggled';
			}
		} else {
			// hide
			element.style.display = 'none';
			if (toggleLink) {
				toggleLink.className = toggleLink.className.replace(/\b ?toggled\b/,'');
			}
		}
	}
	
}

function validateUsername(username_element) {
	
	if (!document.getElementById(username_element)) { return false; }
	
	var username_node = document.getElementById(username_element);
	var username = username_node.value;
	
	if (username.length < 2) {
		alert('Please provide a username between 2 and 40 characters long.');
		username_node.focus();
		return false;
	}
	
	if (username.length > 40) {
		alert('Please provide a username between 2 and 40 characters long.');
		username_node.focus();
		return false;
	}
	
	var regex = /^[A-Za-z0-9_\-\.]+$/
	
	if (!regex.test(username)) {
		alert('Please only use alphanumeric characters (A-Z and 0-9) in your username.');
		username_node.focus();
		return false;
	}
	
	return true;	

}

function setupURLJumperSelect() {
	// get all select elements with the class 'url_jump_select'
	var selects = getElementsByClass('url_jump_select', document, 'SELECT');
	// loop through, add event on change
	for (var i = 0; i < selects.length; i++) {
		selectElement = selects[i];
		// attach onclick function
		addEvent(selectElement, 'change', urlJumpSelect, false);
	}	
}

function urlJumpSelect(e) {
	// find the target
	var target = findTarget(e);
	var path = target.value;
	if (path.length > 0) {
		document.location.href = path;
	}
}

function setUpRadiosAndCheckboxes() {
	// get all select elements with the class 'url_jump_select'
	var inputs = document.getElementsByTagName('INPUT');
	// loop through, add class 'radio' if they are a radio or checkbox
	for (var i = 0; i < inputs.length; i++) {
		inputElement = inputs[i];
		if (inputElement.getAttribute('type') == 'checkbox' || inputElement.getAttribute('type') == 'radio') {
			// add class
			inputElement.className += ' radio';
		}
	}	
}

function toggleList(e) {
	
	// get a reference to the anchor and it's parentNode (the <li> element)
	if (window.event) {
		// IE does it differently... stores the event in a window.event object
		var thisA = window.event.srcElement;
		//alert(thisA);
		var thisLI = thisA.parentNode;
	} else {
		var thisA = this;
		var thisLI = this.parentNode;
	}
	// if this li has nested ul elements...
	if (thisLI.getElementsByTagName('ul').length > 0) {
		
		var toggleListTarget = thisLI.getElementsByTagName('ul')[0];
		//...toggle visibility of first ul
		if (toggleListTarget.style.display != 'none' ) {
			toggleListTarget.style.display = 'none';
			//thisA.style.color = '';
			thisA.style.backgroundImage = 'url(../images/arrowright.gif)';
			//closeListArrow();
		} else {
			toggleListTarget.style.display = '';
			//thisA.style.color = 'white';
			thisA.style.backgroundImage = 'url(../images/arrowdown.gif)';
			//expandListArrow();
		}
		// cancel bubble and href of this anchor
		cancelClick(e);
		// hack for Safari (stops browser following href link)
		thisA.onclick = function() { return false; }
	}
}

function setUpCollapsingList() {

	// find the toggle list
	var lists = getElementsByClass('collapsible_list', document, 'ul');
	
	for (var x = 0; x < lists.length; x++) {
		//list = document.getElementById('collapsingList');
		list = lists[x];
		// find all it's child UL elements
		var childLists = list.getElementsByTagName('ul');
		// hide them all
		for (var i = 0; i < childLists.length; i++) {
			var childList = childLists[i];
			childList.style.display = 'none';
		}
		
		// attach toggleList function to onclick of each anchor
		var childAnchors = list.getElementsByTagName('a');
		// hide them all
		for (var i = 0; i < childAnchors.length; i++) {
			var childAnchor = childAnchors[i];
			// attach toggleList function to onclick of each anchor
			addEvent(childAnchor, 'click', toggleList, false);
		}
	}
}

/*
addLoadEvent(load_ticker);
addLoadEvent(setupURLJumperSelect);
addLoadEvent(setUpRadiosAndCheckboxes);
addLoadEvent(setUpCollapsingList);
*/