function init(){}	
	
var defaultStr = 'Type a question here!';

function isBlank(q) {
    var whitespace = new String(" \t\n\r");

    for (var i = 0; i<q.length; i++) {
        if (whitespace.indexOf(q.charAt(i)) == -1) {
            return false;
        }
    }

    return true;
}
function submitForm(){
	var d = document.askusForm;
	d.action='/askus/results.jsp';
	if (d.question.value==defaultStr || isBlank(d.question.value))
		return;
	d.submit();
}
function verifyForm(){
	var d = document.askusForm
 	if (d.question.value==defaultStr  ||  isBlank(d.question.value))
 		return false;
}
function topTen(){
	var d = document.askusForm;
	d.action='/askus/topQuestions.jsp';
	d.submit();
}
function checkForEnter() {
	if (window.event) {
		if (window.event.keyCode == 13)
				submitForm();
	}	
}

function emailPage() {
	var emailForm = document.getElementById("mailpage");
	emailForm.submit();
}

function printPage() {
	window.print();  
}

function showTab(show,hide) {
	hideContent = document.getElementById(hide);
	hiddenContentLink = document.getElementById(hide+'-link');
	showContent = document.getElementById(show);
	visibleContentLink = document.getElementById(show+'-link');
	hideContent.style.display = 'none';
	hiddenContentLink.className = '';
	showContent.style.display = 'block';
	visibleContentLink.className = 'active';
	visibleContentLink.blur();	
}

function searchToggle(formLink,activeForm) {
	forms = $('search-options').select('form');	
	links = $('search-options').select('a');	
	for (i = 0; i < forms.length; i++) { forms[i].toggle(); links[i].className = ''; }
	formLink.className = 'active';
}

function initExpandables(expanderClass,expandableClass,effectType,containerID) {
	if (containerID) {
		expanders = $(containerID).select('.'+expanderClass);
		expandables = $(containerID).select('.'+expanderClass);	
	}
	else {
		expanders = $$('.'+expanderClass);
		expandables = $$('.'+expandableClass);	
	}
	for (i = 0; i < expanders.length; i++) {
		headingText = expanders[i].innerHTML;
		if ((headingText.indexOf('<img') != -1) || (headingText.indexOf('<IMG') != -1)) {
			headingText = headingText.split('>')[1];
		}
		headingText = headingText.replace(/\s/g,'');
		headingText = headingText.replace(/[^a-zA-Z 0-9]+/g,'');
		headingText = i + '-' + headingText;
		expanders[i].innerHTML = '<a href="#'+headingText+'" id="'+headingText+'-link">'+expanders[i].innerHTML+'</a>';
		expanderLink = $(headingText+'-link');
		expandables[i].id = headingText;
		Element.hide(expandables[i]);
		if (effectType == 'blind') {
			expanderLink.observe('click', blindContent.bindAsEventListener(this,expandables[i],expanders[i],expanderClass)); 
			expanderLink.onclick = function(){ return false; }
		}
		else { 
			expanderLink.observe('click', toggleContent.bindAsEventListener(this,expandables[i],expanders[i],expanderClass)); 
			expanderLink.onclick = function(){ return false; }
		}
	}
}

function blindContent(e,expandable,expander,expanderClass) {
	Effect.toggle(expandable,'blind',{duration:0.3});
	if (expander.className.indexOf('expanded') != -1) {
		expander.className = expanderClass;
	}
	else expander.className = expander.className + ' expanded';
}

function toggleContent(e,expandable,expander,expanderClass) {
	Element.toggle(expandable);
	if (expander.className.indexOf('expanded') != -1) {
		expander.className = expanderClass;
	}
	else expander.className = expander.className + ' expanded';
}

function expandAll(expanderClass,expandableClass) {
	expanders = $$('.'+expanderClass);
	expandables = $$('.'+expandableClass);	
	for (i = 0; i < expanders.length; i++) {
		Element.show(expandables[i]);
		expanders[i].className = expanders[i].className + ' expanded';
	}
}

function collapseAll(expanderClass,expandableClass) {
	expanders = $$('.'+expanderClass);
	expandables = $$('.'+expandableClass);	
	for (i = 0; i < expanders.length; i++) {
		Element.hide(expandables[i]);
		expanders[i].className = expanderClass;
	}
}

// VIDEOS

function loadVideos(videoContainer,username,compact,category) {
	if (category == null) category = 'uploads';
	new Ajax.Updater(videoContainer,'/includes/youtube_feeds.php?user='+username+
					 '&compact='+compact+
					 '&category='+category,{
		//insertion: 'bottom',
		onComplete: function(){ 
			getVideo('first',null,username,category);
			}
		});	
}

function getVideo(videoID,videoTitle,username,category) {
	if (videoID == 'first') {
		videoID = $(username+'-'+category+'-nav').select('li')[0];
		videoID = videoID.id;
		videoTitle = $(videoID).select('img')[0];
		videoTitle = videoTitle.getAttribute('alt');
		//videoTitle = videoTitle.innerHTML;
	}
	videoViewerID = username+'-'+category;
	$(videoViewerID).innerHTML = '<h3>'+videoTitle+'</h3>'+
		'<object width="300" height="250">'+
		'<param name="movie" value="http://www.youtube.com/v/'+videoID+'"></param>'+
		'<embed src="http://www.youtube.com/v/'+videoID+'&rel=0" '+
		'type="application/x-shockwave-flash" width="300" height="250">'+
		'</embed>'+
		'</object>';
}

function loadPhotos(photoContainer,username,tags) {
	params = 'user='+username;
	if (tags) params = params + '&tags='+tags;
	new Ajax.Updater(photoContainer,'/includes/flickr_feeds.php?'+params,{
		onComplete:function(){ 
			getLatestPhoto();
			}
		});
	//new Ajax.Updater('student-photos','/includes/gallery.php');	
}

function getLatestPhoto() {
	if ($('latest-photo')) {
		photo = $$('.flickr-feed')[0].select('img')[0];
		photoURL = photo.getAttribute('src');
		photoURL = photoURL.replace(/_s.jpg/,'');
		photoURL = photoURL + '_m.jpg';
		photo = document.createElement('img');
		photo.setAttribute('src',photoURL);
		$('latest-photo').appendChild(photo);
	}
}

