/*
-----------------------------------------------
Common JavaScript
Site: cucst.org.uk
Version: 23 October 2008
----------------------------------------------- */

window.addEvent('domready', function() {
	searchbox();
	currentNav();
	headerAnim();
	features();
	leftMenu();
	newWin();
});

/* Current Nav (mt)
----------------------------------------------- */
function currentNav() {
	path = document.location.href.split('/').getLast();
	$$('#nav a[href="' + path + '"]').addClass('current');
}

/* Search Box (mt)
----------------------------------------------- */
function searchbox() {
	var sbox = $$('#term');
	sbox.setStyle('color', '#aaa');
	sbox.addEvent('focus', function() {
		sbox.setProperty('value','');
		sbox.setStyle('color', '#555');
	});
	sbox.addEvent('blur', function() {
		sbox.setProperty('value','Search');
		sbox.setStyle('color', '#aaa');
	});
}

/* Features (mt)
----------------------------------------------- */
function features() {
	if ($('feature_panel')!==null) {
	$$('#feature_panel li').each(function(li) {
		var link = li.getElement('a');
		link.url = link.href;
		if (!li.getPrevious()) {
			$('feature').load(link.url);
			li.toggleClass('current');
		}
		link.removeProperty('href');
		link.addEvent('click', function() {
			$$('.current').removeClass('current');
			li.toggleClass('current');
			$('feature').load(this.url);
		});
	});
	}
}

/* New Window Links (mt)
----------------------------------------------- */
function newWin() {
	$$('#main a[href]').each(function(a) {
		if ((!a.href.indexOf('http://') && !a.href.match('^http://([^.]+[.])?(' + document.domain + ')')) || a.href.match('.wmv|.pdf')) {
			a.onclick = function(e){
				var event;
				if (!e) {
					event = window.event;
				} else {
					event = e;
				}
				if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) {
					return true;
				} else {
					newWindow = window.open(this.href);
					return false;
				}
			};
		}
	});
}

/* Header Animation (mt + slideshow)
----------------------------------------------- */
function headerAnim() {
	var data = ['home1.jpg','home2.jpg','home3.jpg','home4.jpg','home5.jpg','home6.jpg','home7.jpg','home7.jpg','home8.jpg'];
	var headerSlides = new Slideshow('header', data, {controller: false, hu: '/photos/header/', delay: 5000, duration: 750});
}

/* Left Menu (mt)
----------------------------------------------- */
function leftMenu() {	
	$$('#left-side .MGrouplist').setStyle('display', 'block');
	$$('#left-side li.MGroup').each(function(li) {
		var link = li.getElement('a');
		var block = link.getNext();		
		var fx = new Fx.Slide(block);		
		fx.hide();
		link.addEvent('click', function() {
			fx.toggle();
			link.toggleClass('open');
		});
	});
}
document.write('<style type="text/css" media="screen">#left-side ul.MGrouplist{display: none}</style>');

/* Zebra Stripes (MT)
----------------------------------------------- */
function zebraStripes() {
	var z;
	$$('.zebra tr').each(function(tr) {
		z = (z) ? false : true;
		if (z) tr.addClass('alt');
	});
}