function selfOpen(url)
{
	var win = window.open(url, 'studentWin', 'fullscreen=1,location=0,menubar=0,resizable=0,scrollbars=0,status=0,toolbar=0');
	if (!win || win.name == undefined)
	{
		if (self.location.href)
			self.location.href = url;
		else
			self.location = url;
	}
	else
		win.focus();

}

function showForm(type)
{
	document.getElementById("studentusername").value = "";
	document.getElementById("studentpassword").value = "";
	
	document.getElementById("parentname").value = "";
	document.getElementById("parentpassword").value = "";
	
	document.getElementById("teachername").value = "";
	document.getElementById("teacherpassword").value = "";
	
	loginFormNames = ["loginChooser", "studentlogin", "parentlogin", "teacherlogin"];
	for (i=0; i<loginFormNames.length; i++)
		document.getElementById(loginFormNames[i]).style.display = "none";
	
	document.getElementById(type).style.display = "";
	
	if (type != "loginChooser")
		springBack = setTimeout("showLoginChooser()", 1*60*1000);
}

function showLoginChooser()
{
	showForm("loginChooser");
}

function submitStudentLogin()
{
	var u    = document.getElementById("studentusername").value;
	var p    = document.getElementById("studentpassword").value;
	var url  = "http://auth.whizz.com/student/login.php"
	url += "?action=process&redirect=/login/loginerror.html&username="+u+"&password="+p;
	selfOpen(url);
}

/* TESTIMONIALS */
function reorderQuotesDepth(topItem)
{
	var depth = 0;
	for (var i=0; i<quotes.length; i++)
	{
		var quote = quotes[i];
		if (i != topItem)
			quote.style.zIndex = depth++;
		else
			quote.style.zIndex = quotes.length;
	}
}

// the fading function
function fadeQuote()
{
	// claculate new opacity for the fading item
	var nextItemOpacity = fadeStep*10;
	// this is the fading item
	var nextItem = quotes[nextQuote];
	// this is the "current' item
	var crtItem  = quotes[crtQuote];

	// on first step, reorder elements
	if (fadeStep == 0)
	{
		reorderQuotesDepth(nextQuote);
	}

	// set the opacity
	nextItem.style.filter = "alpha(opacity="+nextItemOpacity+")";
	nextItem.style.opacity= "" + (nextItemOpacity/100);
	
	// if we reached the end
	if (fadeStep==10)
	{
		fadeStep = 0;
		
		// make the current item transparent
		crtItem.style.filter  = "alpha(opacity=0)";
		crtItem.style.opacity = "0";
		nextItem.style.filter = "none";
		
		// increase the counter
		if (nextQuote<quotes.length-1)
		{
			nextQuote++;
			crtQuote = nextQuote-1;
		}
		else
		{
			crtQuote++;
			nextQuote = 0;
		}
		
		setTimeout("fadeQuote()", 5000 + 3000*Math.random());
	}
	else
	{
		fadeStep++;
		setTimeout("fadeQuote()", 50);
	}
}

function setupTestimonialsBox()
{
	// set the overflow of container to fix layout problems, can't do this via class or we won't be able to edit quotes
	var container = document.getElementById("testimonialbox");
	
	// get all the quotes, reposition by stacking them one on top of the other
	quotes = document.getElementById("testimonialbox").getElementsByTagName("blockquote");
	for(var i=0; i<quotes.length; i++)
	{
		var quote = quotes[i];
		quote.style.position = "relative";
		quote.style.top      = "-"+250*i+"px";
		quote.style.zIndex   = i;
		
		// don't hide the first 
		if(i>0)
		{
			quote.style.filter = "alpha(opacity=0)";
			quote.style.opacity= "0";
		}
	}
	
	// set initial values
	crtQuote  = 0;
	nextQuote = 1;
	fadeStep  = 0;
	
	reorderQuotesDepth(0);
	setTimeout("fadeQuote()", 6000);
}

			
