

//rewrite url and copy to clipboard for user

function shorturl(){
		surlout = location.href.replace("http://www2.warwick.ac.uk/fac/soc/wbs/central/issu/help/","http://help.wbs.ac.uk/")
		sanshash = surlout.split("#")
		//alert(sanshash[0])
		window.clipboardData.setData('text',sanshash[0]);
//to use this, eg. <a href="javascript:shorturl()" mce_href="javascript:shorturl()">help.wbs</a>
}

//change hash value of url and set appropriate view

function students(persist){
		if(persist){createCookie("wbshelp","students",365)}		

		window.location.hash = 'students'
		studentview()
}

function staff(persist){
		if(persist){createCookie("wbshelp","staff",365)}

		window.location.hash = 'staff'
		staffview()
}

function all(persist){
		if(persist){eraseCookie("wbshelp")}

		window.location.hash = 'all'
		allview()
}


//manipulate class tags to show and hide relevant content

function studentview() {
		$$('.students').invoke('appear',{ delay: 0.35 });
		$$('.staff').invoke('fade',{ duration: 1.0, from: 1, to: 0 });
		$$('.all').invoke('hide');
		$$('.staff-only').invoke('hide');
		$$('.students-only').invoke('show');

		$$('#students-link').invoke('setStyle',{'textDecoration': "none", 'fontSize' : "100%", 'color' : "maroon"});
		$$('#staff-link').invoke('setStyle',{'textDecoration': "underline", 'fontSize' : "150%", 'color' : ""});
		$$('#all-link').invoke('setStyle',{'textDecoration': "underline", 'fontSize' : "150%", 'color' : ""});
}

function staffview() {
		$$('.staff').invoke('appear',{ duration:2, delay: 0.35 });
		$$('.students').invoke('fade',{ duration: 1.0, from: 1, to: 0 });
		$$('.all').invoke('hide');
		$$('.students-only').invoke('hide');
		$$('.staff-only').invoke('show');

		$$('#students-link').invoke('setStyle',{'textDecoration': "underline", 'fontSize' : "150%", 'color' : ""});
		$$('#staff-link').invoke('setStyle',{'textDecoration': "none", 'fontSize' : "100%", 'color' : "maroon"});
		$$('#all-link').invoke('setStyle',{'textDecoration': "underline", 'fontSize' : "150%", 'color' : ""});
}

function allview() {

		$$('.staff').invoke('appear',{ delay: 0.35 });
		$$('.students').invoke('appear',{ delay: 0.35 });
		$$('.all').invoke('show');
		$$('.students-only').invoke('hide');
		$$('.staff-only').invoke('hide');

		$$('#students-link').invoke('setStyle',{'textDecoration': "underline", 'fontSize' : "150%", 'color' : ""});
		$$('#staff-link').invoke('setStyle',{'textDecoration': "underline", 'fontSize' : "150%", 'color' : ""});
		$$('#all-link').invoke('setStyle',{'textDecoration': "none", 'fontSize' : "100%", 'color' : "maroon"});
}


//determines url hash onload


	window.onload=function(){
urlquery=location.href.split("#")
if (urlquery[1]){
		urlterms=urlquery[1].split(",")
		if (urlterms[0]=="students"){
			studentview()
			}
		if (urlterms[0]=="staff"){
			staffview()
			}
		}
else{
	wbshc=readCookie("wbshelp")
	if(wbshc=="students"){students()}
	if(wbshc=="staff"){staff()}
	}	
}

//determines url hash onhashchange (only newer browsers) - eg. back button

window.onhashchange=function(){
urlquery=location.href.split("#")
if (urlquery[1]){
	urlterms=urlquery[1].split(",")
		if (urlterms[0]=="students"){
		studentview()
}
		if (urlterms[0]=="staff"){
		staffview()
}
		if (urlterms[0]=="all"){
		allview()
}
}
}

//cookies

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

