var mT, sifrFont = baseURL+'sifr/prince.swf', inputV = new Array (),galleryPages,galleryCurrentPage=1,working=0,selectedGallery,selectedGalleryItem,pageNum=1, shareThisObject = new Array (), isIE6,vipWork=false,cc=1,vipStore;

if (navigator.userAgent.toLowerCase().indexOf('msie 6') == -1) notIE6 = true; else notIE6 = false;

function messageBox(message,secondsOut,noC) {
	i='messageBox';
	if (mT) clearTimeout(mT);
	mT=null;
	if ($(i) != null) {
		$(i).update(message);
		if (noC == null) centreElement (i,1);
		$(i).show();
		mT = setTimeout(function () { $(i).hide(); }, (secondsOut*1000));
	}
	else {
		alert('Message box doesn\'t exist');	
	}
}

function centreElement (e, vert) {
	var theScrolls = document.viewport.getScrollOffsets();
	theLeft = Math.floor(((document.viewport.getWidth())-($(e).getWidth()))/2) + theScrolls[0];
	theTop = Math.floor(((document.viewport.getHeight())-($(e).getHeight()))/2) + theScrolls[1];
	if (theTop < 0) theTop = 0;
	if (vert==1)  {
		$(e).setStyle({ top: '0px' });
		$(e).setStyle({ top: theTop+'px' });
	}
	$(e).setStyle({ left: theLeft+'px' });
	
}

function closeBox(id,overlay) {
	var ov=1;
	if (overlay != null) {
		ov=0;
		$('pageOverlay').setStyle({ zIndex: overlay });
	}
	if (ov==1) $('pageOverlay').hide();
	$(id).hide();
}

function Select_Value_Set(SelectName, Value) {
  eval('SelectObject = document.' + 
    SelectName + ';');
  for(index = 0; 
    index < SelectObject.length; 
    index++) {
   if(SelectObject[index].value == Value)
     SelectObject.selectedIndex = index;
   }
}

function logInOut(l) {
	if (l==1) {
		if ($('user').present && $('pw').present) {
			var allNodes = Form.serialize('homeForm');
			var aj = new Ajax.Request(baseURL+'ajaxStuffAdmin.php', {method: 'post', parameters: 'logInOut=in&'+allNodes,onComplete: function(response) {
				var r = response.responseText;
				if (r=='You have been logged in') window.location.href = baseURL+'admin.php';
				messageBox(r,3)
			}});
		}
		else {
			messageBox('Please enter your username &amp; password',3)
		}
	}
	else {
		if (confirm("Are you sure?")) {
			var aj = new Ajax.Request(baseURL+'ajaxStuffAdmin.php', {method: 'post', parameters: 'logInOut=out',onComplete: function(response) {
				var r = response.responseText;
				if (r=='You have been logged out' && thisPage.search('admin') != -1) window.location.href = baseURL;
				else if (r=='You have been logged out') $('loginBoxOptions').hide();
			}});
		}
	}
}

function pageOverlay() {
	var theScrolls = document.viewport.getScrollOffsets();
	pageWidth = document.viewport.getWidth() + theScrolls[0]; pageHeight = document.viewport.getHeight() + theScrolls[1];
	if (pageWidth < $('mainContainer').getWidth()) pageWidth = $('mainContainer').getWidth();
	if (pageHeight < ($('mainContainer').getHeight()+127)) pageHeight = ($('mainContainer').getHeight()+127);
	$('pageOverlay').setStyle({ opacity: '0.5', display: 'block', width:pageWidth+'px', height:pageHeight+'px' });
	$('pageOverlay').show();
}

function showBox(id,noDrag) {
	pageOverlay();
	centreElement (id,1);
	$(id).show();
	if (noDrag==null) new Draggable(id, { scroll: window });
}

function readyForPost(t) {
	t = t.replace("‘","'");
	t = t.replace("’","'");
	return escape(t);
}

function encode_utf8(s) {
	return unescape( encodeURIComponent( s ) );
}

function decode_utf8 (s) {
	return decodeURIComponent( escape( s ) );
}

function clearInputBox(i,t,o,c) {
	if (o==1) {
		if ($F(i) == t) $(i).value='';
	}
	else if (o==2) {
		$(i).observe('focus', function () { clearInputBox(i,t,1,c); });
		$(i).observe('blur', function () { clearInputBox(i,t,0,c); });
	}
	else {
		if ($F(i) == '') $(i).value=t;	
	}
	if (c) { $(i).setStyle({ color: c }); }
}

function isValidEmail(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1) return false;
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) return false;
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) return false;
	if (str.indexOf(at,(lat+1))!=-1) return false;
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) return false;
	if (str.indexOf(dot,(lat+2))==-1) return false;
	if (str.indexOf(" ")!=-1) return false;
	return true;			
}

function handleEnter (event, func, v) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13) {
		event.stop()
		if (func) func (v);
		return false;
	}
	else return true;
}

function adminLogout () {
	var aj = new Ajax.Request(baseURL+'ajaxStuff.php', {method: 'post', parameters: 'adminLogout=1&'+allNodes,onComplete: function() {
		window.location.href = baseURL+'login/logout';
		messageBox('You have been logged out',8);
	}});
}

function showVimeo (vidID, width, height, divID, colour,auto) {
	var flashvars = {clip_id: vidID,server: "vimeo.com",show_title: "0",show_byline: "0",show_portrait: "0",fullscreen: "1",color: colour,autoplay:auto};
	var params = {allowfullscreen: "true",allowscriptaccess: "always",movie: "http://vimeo.com/moogaloop.swf",wmode: "transparent"};
	var attributes = {clip_id: vidID};
	swfobject.embedSWF("http://vimeo.com/moogaloop.swf", divID, width, height, "9.0.0","expressInstall.swf", flashvars, params, attributes);
}

function showYouTube (vidID, width, height, divID, auto) {
	var flashvars = {};
	var params = {allowfullscreen: "true",allowscriptaccess: "always",wmode: "transparent"};
	var attributes = {id: "vid"};
	swfobject.embedSWF("http://www.youtube.com/v/"+vidID+"&hl=en&fs=1&rel=0&color1=0x000000&color2=0x2d2d2d&autoplay="+auto, divID, width, height, "9.0.0","expressInstall.swf", flashvars, params, attributes);
}

function showJWPlayer (id,w,t) {
	var flashvars = {file: baseURL+'tracks/'+t};
	var params = {allowfullscreen: "true",allowscriptaccess: "always",wmode: "transparent"};
	var attributes = {};
	swfobject.embedSWF(baseURL+'jw_player/player2.swf', id, w, 24, "9.0.0","expressInstall.swf", flashvars, params, attributes);
}

function createSCPlayer (width, height, user, permalink, divID, set, type, colour, play) {
	if (set) user = user + '/sets';
	if (colour == null) colour = '6cff00';
	if (play == null) play = 'false';
	if (type == null || type != 'tiny') type = 'main';
	var flashvars = { url: "http://soundcloud.com/"+user+"/"+permalink,color: colour,player_type:type, auto_play:play};
	var params = {allowscriptaccess: "always",wmode: "transparent"};
	var attributes = {name: 'player'};
	swfobject.embedSWF("http://player.soundcloud.com/player.swf", divID, width, height, "9.0.0","expressInstall.swf", flashvars, params, attributes);
}

function badField (f,t) {
	var b = false;
	if (t==1) {
		f.each(function(n){
			if ($F(n)=='' || $F(n)==inputV[n]) b = true;
		});
	}
	else if ($(f).tagName == 'FORM' || $(f).tagName == 'form') {
		var a=$$('#'+f+' input[type="text"]');
		a.each(function(n){
			if ($F(n.id)=='' || $F(n.id)==inputV[n.id]) b = true;
		});
		var a=$$('#'+f+' textarea');
		a.each(function(n){
			if ($F(n.id)=='' || $F(n.id)==inputV[n.id]) b = true;
		});
	}
	else if ($F(f)=='' || $F(f)==inputV[f]) b = true;
	return b;
}

function doSIFR (s,oL,oT,aL,sC,sBg,sCase) {
	if(typeof sIFR == "function"){
		sIFR.replaceElement(named({sSelector:s, sFlashSrc:sifrFont, sColor:sC, sLinkColor:"#ffffff", sBgColor:sBg, sHoverColor:"#00303b",sCase:sCase,sWmode:"opaque", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign="+aL+"&offsetTop="+oT+"&offsetLeft="+oL+""}));
	};
}

/********************** ALL ************************/

function setUpAll () {
	if ($('signupEmail') != null) Event.observe('signupEmail', 'keypress',function (e) { handleEnter (e, submitSignUp) });
	if ($('signupName') != null) Event.observe('signupName', 'keypress',function (e) { handleEnter (e, submitSignUp) });
	var a=$$('form');
	a.each(function(n){
		$(n.id).reset();
	});
	var a=$$('input[type="text"]');
	a.each(function(n){
		if ($F(n.id) != null && n.id != null) {
			clearInputBox($(n.id),$F(n.id),2);
			inputV[n.id]=$F(n.id);
		}
   	});
	var a=$$('textarea');
	a.each(function(n){
		if ($F(n.id) != null && n.id != null) {
			clearInputBox($(n.id),$F(n.id),2);
			inputV[n.id]=$F(n.id);
		}
   	});
	if ($('soundcloud') != null) {
		var h = $('soundcloud').getHeight(),w=$('soundcloud').getWidth(),pT;
		if (thisPage.search("estival")>0) pT = 'festival';
		else pT = 'clubs';
		var aj = new Ajax.Request(baseURL+'ajaxStuff.php', {method: 'post', parameters: 'getSoundcloud=1&type='+pT,onComplete: function(response) {
			var r = response.responseText.split('||mess||');
			createSCPlayer (w, h, r[0], r[1], 'soundcloud', r[2],null,'cd931c')
		}});
	}
}

function submitSignUp (c) {
	var f,em;
	f = 'signupForm';
	em = 'signupEmail';
	if (badField(f,2)) messageBox('Please enter all fields',3);
	else {
		var allNodes = Form.serialize(f);
		var aj = new Ajax.Request(baseURL+'ajaxStuff.php', {method: 'post', parameters: 'signUp=1&'+allNodes,onComplete: function(response) {
			messageBox('Thanks, your details have been saved',3);
			$(f).reset();
		}});
	}
}

function contactUs (p) {
	var allNodes = Form.serialize(p+'Form'),n,e,c,ci,as;
	if ( $F(p+'Name') && $F(p+'Email') && isValidEmail($F(p+'Email')) && $F(p+'Comment') ) {
		var aj = new Ajax.Request(baseURL+'ajaxStuff.php', {method: 'post', parameters: 'contactUs='+p+'&'+allNodes,onComplete: function(response) {
			messageBox(response.responseText,3);
			$(p+'Form').reset();
		}});
	}
	else if (isValidEmail($F(p+'Email'))==false) {
		messageBox('Please check your email address',3);
	}
	else messageBox('Please enter your name, email and comment',3);
}

/********************** CLUBS - HOME ************************/

function setUpClubsHome () {
	var aj1 = new Ajax.Request(baseURL+'ajaxStuff.php', {method: 'post', parameters: 'getClubHomeVideo=1',onComplete: function(response) {
		var reply = response.responseText.split("||message||"),w = 609,h = 285,divID = 'video';
		if (reply[0]=='vimeo') {
			showVimeo (reply[1], w, h, divID, null)
		}
		else {
			showYouTube (reply[1], w, h, divID);
		}
	}});
	$('fanBox').update('<iframe src="http://www.facebook.com/plugins/likebox.php?id=135991386411113&amp;width=321&amp;connections=15&amp;stream=false&amp;header=false&amp;height=341" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:321px; height:341px;" allowTransparency="true"></iframe>');
}

/********************** CLUBS - CALENDAR ************************/

function setUpClubsCalendar () {
	var a=$$('.calendar li h2 span[id^=c]');
	a.each(function(n){ $(n.id).setOpacity(0.4); });
	var a=$$('.calendar li.no-listing p');
	a.each(function(n){ $(n.id).setOpacity(0.8); });
	
	var a=$$('.calendar li a[id^=a]');
	a.each(function(n){ 
		$(n.id).setOpacity(0.9); 
		var j = v = n.id.split('_');
		var m = j[2],m2 = n.id.replace('a','i');
		if ($(m2) != null) {
			Event.observe(n.id, 'mouseover',function () {
				$(m2).setStyle({ top: '-103px'});
			});
			Event.observe(n.id, 'mouseout',function () {
				if ($(m2).hasClassName('active')==false) $(m2).setStyle({ top: '0px'});
			});
		}
		Event.observe(n.id, 'click',function () { loadCalendarItem(m) });
	});
	var a=$$('.calendar li a img');
	a.each(function(n){ 
		var j = v = n.id.split('_');
		var m = j[2];
		Event.observe(n.id, 'mouseover',function () {
			$(n.id).setStyle({ top: '-103px'});
		});
		Event.observe(n.id, 'mouseout',function () {
			if ($(n.id).hasClassName('active')==false) $(n.id).setStyle({ top: '0px'});
		});
		$(n.id).setOpacity(0.7); 
		Event.observe(n.id, 'click',function () { loadCalendarItem(m) });
	});
	var a=$$('#months a[id^=cal]');
	a.each(function(n){
		//if ($(n.id).hasClassName('active')) changeCalMonth (n.id)
		Event.observe(n.id, 'click',function () {
			changeCalMonth (n.id)
		});
	});
	if ($('overlay').visible()==true) {
		centreElement ('overlay', 1);
		pageOverlay();
		Event.observe('close', 'click',function () { closeBox('overlay') });
	}
}

function changeCalMonth (i) {
	var m = i.replace('cal','');
	if ($('calendar'+m).visible()==false) {
		var c=$$('.left .calendar');
		c.each(function(n){ 
			$(n.id).hide();
			$(n.id).setStyle({ height: '0px'});
			var t = n.id.replace('calendar','');
			$('cal'+t).removeClassName('active');
		});
	}
	$('calendar'+m).show()
	$('calendar'+m).setStyle({ top: '0px',height: 'auto'});
	$('cal'+m).addClassName('active');
}

function loadCalendarItem(i) {
	var aj1 = new Ajax.Updater('overlay',baseURL+'ajaxStuff.php', {method: 'post', parameters: 'getListing='+i,onComplete: function(response) {
		showBox('overlay',1);
		$('close').stopObserving('click');
		Event.observe('close', 'click',function () { closeBox('overlay') });
	}});
}

/********************** CLUBS - BLOG ************************/

function setUpClubsBlog () {
	var a=$$('a[id^=readMore]');
	a.each(function(n){  
		var m = n.id.replace('readMore_','');
		Event.observe(n.id, 'click',function () { loadNewsArticle(m,'clubs-blog') });
	});
}

function loadNewsArticle(i,t) {
	var aj1 = new Ajax.Updater('overlay',baseURL+'ajaxStuff.php', {method: 'post', parameters: 'getNewsItem='+i+'&cat='+t,onComplete: function(response) {
		showBox('overlay',1);
		$('close').stopObserving('click');
		Event.observe('close', 'click',function () { closeBox('overlay') });
	}});
}

/********************** CLUBS - GALLERY ************************/

function setUpClubsGallery () {
	setUpGallery ()
}

function galleryRollovers () {
	var a=$$('#readMore');
	a.each(function(n){  
		$(n.id).setOpacity(0.7);
		Event.observe(n.id, 'mouseover',function () {
			$(n.id).setOpacity(1);
		});
		Event.observe(n.id, 'mouseout',function () {
			if ($(n.id).hasClassName('active')==false) $(n.id).setOpacity(0.7);
		});
	});
}

/********************** CLUBS - REQUESTS ************************/

function setUpClubsRequests () {
	Event.observe('submitRequest', 'click',function () {
		contactUs ('request');
	});
}

/********************** GALLERIES/VIDEO ************************/

function setUpGallery () {
	$('last').observe('click', function () {
		if (working<1 && galleryCurrentPage>1) {
			working=1;
			new Effect.Move('galleryBox2', { x:0, y: 291, mode: 'relative', transition: Effect.Transitions.spring, afterFinish: function(){ working=0; --galleryCurrentPage; }});
		}
	});
	$('next').observe('click', function () {
		if (working<1 && galleryCurrentPage<galleryPages) {
			working=1;
			new Effect.Move('galleryBox2', { x: 0, y: -291, mode: 'relative', transition: Effect.Transitions.spring, afterFinish: function(){ working=0; ++galleryCurrentPage; }});
		}
	});
	if ($('galleryAlbums') != null) setupGalleryObserves();
	else setupGalleryItemObserves ();
	setupGalleryPageObserves ();
	selectPage(pageNum,'galleryPages');
}

function setupGalleryObserves () {
	var a=$$('#galleryAlbums li img'),i=1;
	if (a.length<1) {
		resetGalleryContent ();
		$('galleryBox2').update('No Results');
		selectedGallery = null;
	}
	a.each(function(n){
		$(n.id).setOpacity('0.5');
		if (i<2) {
			$(n.id).setOpacity('1.0');
			loadGallery (n.id);
		}
		$(n.id).stopObserving('mouseout');
		$(n.id).stopObserving('mouseover');
		Event.observe(n.id, 'mouseover',function () { $(n.id).setOpacity('1.0'); });
		Event.observe(n.id, 'mouseout',function () { if ('gal_'+selectedGallery != n.id) $(n.id).setOpacity('0.5'); });
		Event.observe(n.id, 'click',function () { loadGallery (n.id); });
		++i;
	});
}

function setupGalleryItemObserves (l) {
	var a=$$('#galleryBox img'),t,r,i=1;
	galleryPages = Math.ceil(a.length/6);
	$('galleryBox2').setStyle({ height:(a.length*291)+'px'});
	a.each(function(n){
		$(n.id).setOpacity('0.5');
		if (i<2) loadGalleryItem(n.id);
		$(n.id).stopObserving('mouseout');
		$(n.id).stopObserving('mouseover');
		Event.observe(n.id, 'mouseover',function () { $(n.id).setOpacity('1.0'); });
		Event.observe(n.id, 'mouseout',function () { if (selectedGalleryItem != n.id)  $(n.id).setOpacity('0.5'); });
		Event.observe(n.id, 'click',function () { if (selectedGalleryItem != n.id) loadGalleryItem(n.id,1); });
		++i;
	});
}

function setupGalleryPageObserves () {
	var a=$$('#galleryPages li a'),r;
	a.each(function(n){
		$(n.id).observe('click',function(){showGalleryPage(n.id)});
	});
}

function gallerySearch () {
	pageNum=999999;
	selectedGallery = null;
	var aj1 = new Ajax.Updater('galleryPages',baseURL+'ajaxStuff.php', {method: 'post', parameters: 'getGalleryPages=1&search='+readyForPost($F('searchGallery'))+'&type='+type+'&cat='+cat,onComplete: function(response) { showGalleryPage ('page1'); setupGalleryPageObserves (); }});
}

function resetGalleryContent () {
	if (selectedGalleryItem) {
		if ($(selectedGalleryItem) != null) $(selectedGalleryItem).setOpacity('0.5');
		if ((selectedGalleryItem.search('Vimeo')>=0) || (selectedGalleryItem.search('YouTube')>=0)) {
			swfobject.removeSWF('mainContent');
			$('video2').update('<div id="video"></div>');
		}
		else if ($('video') != null) $('video').update();
		else if ($('imageView') != null) $('imageView').update();
	}
}

function loadGalleryItem(i,a) {
	resetGalleryContent ();
	$(i).setOpacity('1.0');
	selectedGalleryItem = i;
	if (a == null) a=0;
	var v,r;
	if ($('video') != null) $('video').setStyle({paddingLeft: '0px'});
	if (i.search('image')>=0) {
		v = i.split('_');
		var pad = Math.ceil(($('imageView').getWidth()-v[2])/2);
		$('imageView').setStyle({paddingLeft: pad+'px'});
		r = $(i).src.replace('preview2','main');
		$('imageView').update('<img src="'+r+'" />');
	}
	if (i.search('Vimeo')>=0) {
		v = i.replace('Vimeo_','').split('_theref_');
		showVimeo (v[0], 609, 337, 'video', 'ff0000',a);
	}
	if (i.search('YouTube')>=0) {
		v = i.replace('YouTube_','').split('_theref_');
		showYouTube (v[0], 609, 337, 'video',a);
	}
}

function loadGalleryItemText (i) {
	var aj1 = new Ajax.Request(baseURL+'ajaxStuff.php', {method: 'post', parameters: 'getGalleryItemInfo='+i,onComplete: function(response) {
		var reply = response.responseText.split('||message||');
		$('imageTitle').update(reply[1]+' <span>'+reply[2]+'</span>');
		$('imageText').update(reply[3]);
	}});
}

function loadGallery (i) {
	var galID = i.replace('gal_',''),m=0;
	if (galID != selectedGallery || selectedGallery == null) {
		if (selectedGallery && $('gal_'+selectedGallery) != null) $('gal_'+selectedGallery).setOpacity('0.5');
		selectedGallery = galID;
		$(i).setOpacity('1.0');
		if (galleryCurrentPage>1) {
			--galleryCurrentPage;
			m = galleryCurrentPage * 291;
			galleryCurrentPage=1;
		}
		var pars;
		if ($('searchGallery') != null) pars = '&search='+readyForPost($F('searchGallery')); else pars = '';
		var aj1 = new Ajax.Updater('galleryBox2',baseURL+'ajaxStuff.php', {method: 'post', parameters: 'getGalleryItems='+galID+pars+'&type='+type+'&cat='+cat,onComplete: function(response) {
			new Effect.Move('galleryBox2', { x: 0, y: m, mode: 'relative', transition: Effect.Transitions.full});
			setupGalleryItemObserves (1);
		}});
	}
}

function showGalleries (p) {
	var pars;
		if ($('searchGallery') != null) pars = '&search='+readyForPost($F('searchGallery')); else pars = '';
	var aj1 = new Ajax.Updater('galleryAlbums',baseURL+'ajaxStuff.php', {method: 'post', parameters: 'getGalleries='+p+pars+'&type='+type+'&cat='+cat,onComplete: function(response) {
		setupGalleryObserves ();
	}});
}

function selectPage(i,ulID) {
	var a=$$('#'+ulID+' li a');
	a.each(function(n){
		if ($(n.id).hasClassName('active')) $(n.id).removeClassName('active');
	});
	if ($('page'+i)) $('page'+i).addClassName('active');
}

function showGalleryPage (p) {
	p=p.replace('page','');
	if (p != pageNum) {
		pageNum = p;
		selectPage(p,'galleryPages');
		showGalleries (p);
	}
}

/********************** FESTIVAL - HOME ************************/

function setUpFestHome() {
	if ($('overlay').visible()==true) {
		centreElement ('overlay', 1);
		pageOverlay();
		Event.observe('close', 'click',function () { closeBox('overlay') });
		doSIFR ("h2.newsFocus",0,0,"left","#FFFFFF",'#0f97d2',"upper");
	}
	Event.observe('readMore', 'click',function () { loadFestivalNews() });
}

function loadFestivalNews() {
	var aj1 = new Ajax.Updater('overlay',baseURL+'ajaxStuff.php', {method: 'post', parameters: 'getFestivalNews=1',onComplete: function(response) {
		showBox('overlay',1);
		$('close').stopObserving('click');
		Event.observe('close', 'click',function () { closeBox('overlay') });
		doSIFR ("h2.newsFocus",0,0,"left","#FFFFFF",'#0f97d2',"upper");
	}});
}

/********************** FESTIVAL - BLOG ************************/

function setUpFestivalBlog () {
	var a=$$('a[id^=readMore]');
	a.each(function(n){  
		var m = n.id.replace('readMore_','');
		Event.observe(n.id, 'click',function () { loadNewsArticle(m,'festival-news') });
	});
}

/********************** FESTIVAL - PAST EVENTS ************************/

function setUpFestPast() {
	doSIFR ("h2.title",0,-2,"left","#FFFFFF",'#0f8cc3',"upper");
	var a=$$('a[id^=readMore]');
	a.each(function(n){  
		var m = n.id.replace('readMore_','');
		Event.observe(n.id, 'click',function () { loadPastEvents(m) });
	});
	if ($('overlay').visible()) {
		showBox('overlay',1);
		$('close').stopObserving('click');
		Event.observe('close', 'click',function () { closeBox('overlay') });
		doSIFR ("h2.pastEventFocus",0,0,"left","#FFFFFF",'#0f97d2',"upper");
	}
}

function loadPastEvents(i) {
	var aj1 = new Ajax.Updater('overlay',baseURL+'ajaxStuff.php', {method: 'post', parameters: 'getPastEvents='+i,onComplete: function(response) {
		showBox('overlay',1);
		$('close').stopObserving('click');
		Event.observe('close', 'click',function () { closeBox('overlay') });
		doSIFR ("h2.pastEventFocus",0,0,"left","#FFFFFF",'#0f97d2',"upper");
	}});
}

/********************** FESTIVAL - BANDS ************************/

function setUpBands() {
	doSIFR ("h3",4,2,"left","#FFFFFF",'#1c9ac6',"upper");
	doSIFR ("h2.stageTitle",0,0,"left","#FFFFFF",'#0f97d2',"upper");
	doSIFR ("h2.bandFocus",0,0,"left","#FFFFFF",'#0f97d2',"upper");
	var a=$$('a[id^=readMore]');
	a.each(function(n){  
		var m = n.id.replace('readMore_','');
		Event.observe(n.id, 'click',function () { loadBand(m) });
	});
}

function loadBand(i) {
	var aj1 = new Ajax.Updater('overlay',baseURL+'ajaxStuff.php', {method: 'post', parameters: 'getBand='+i,onComplete: function(response) {
		showBox('overlay',1);
		$('close').stopObserving('click');
		Event.observe('close', 'click',function () { closeBox('overlay') });
		doSIFR ("h2.bandFocus",0,0,"left","#FFFFFF",'#0f97d2',"upper");
	}});
}

/********************** FESTIVAL - DIRECTIONS ************************/

function setUpDirections() {
	var a=$$('a[id^=readMore]');
	a.each(function(n){  
		var m = n.id.replace('readMore_','');
		Event.observe(n.id, 'click',function () { loadDirections(m) });
	});
	Event.observe('lrgMap', 'click',function () { showBox('overlay2',1); centreElement ('overlay2', 1); pageOverlay();  });
	Event.observe('lrgMap2', 'click',function () { showBox('overlay3',1); centreElement ('overlay3', 1); pageOverlay();  });
}

function loadDirections(i) {
	var aj1 = new Ajax.Updater('overlay',baseURL+'ajaxStuff.php', {method: 'post', parameters: 'getDirections='+i,onComplete: function(response) {
		showBox('overlay',1);
		$('close').stopObserving('click');
		Event.observe('close', 'click',function () { closeBox('overlay') });
		doSIFR ("h2.directionFocus",0,0,"left","#FFFFFF",'#0f97d2',"upper");
	}});
}

/********************** FESTIVAL - PRESS ************************/

function setUpPress() {
	var a=$$('a[id^=pressLink]');
	a.each(function(n){  
		var m = n.id.replace('pressLink_','');
		$(n.id).stopObserving('click');
		Event.observe(n.id, 'click',function () { loadPress(m) });
	});
	Event.observe('submit', 'click',function () {
		contactUs ('press');
	});
}

function loadPress(i) {
	var aj1 = new Ajax.Updater('overlay',baseURL+'ajaxStuff.php', {method: 'post', parameters: 'getPress='+i,onComplete: function(response) {
		showBox('overlay',1);
		$('close').stopObserving('click');
		Event.observe('close', 'click',function () { closeBox('overlay') });
		doSIFR ("h2.pressFocus",0,0,"left","#FFFFFF",'#0f97d2',"upper");
	}});
}

function setUpLandingHome () {
	
	if ($('trackForm') != null) {
		
		Event.observe( 'trackForm', 'submit',function (e) {
			Event.stop(e);
			var em = $F('email');
			
			if (isValidEmail(em)) {
			
				
					var aj1 = new Ajax.Request(baseURL+'ajaxStuff.php', {method: 'post', parameters: 'getDownload=1&email='+em,onComplete: function(response) {
						
						messageBox(response.responseText,4,1);
						$('trackForm').reset();
						
					}});
				
			
			}
			else messageBox('Please enter a valid email address',4,1);
		
		});
	
	}
	
}


Event.observe( window, 'load',setUpAll);
if (thisPage == 'clubs-home') 
	Event.observe( window, 'load',setUpClubsHome);
if (thisPage == 'clubs-calendar') 
	Event.observe( window, 'load',setUpClubsCalendar);
if (thisPage == 'clubs-blog') 
	Event.observe( window, 'load',setUpClubsBlog);
if (thisPage == 'clubs-gallery') 
	Event.observe( window, 'load',setUpGallery);
if (thisPage == 'clubs-requests') 
	Event.observe( window, 'load',setUpClubsRequests);
if (thisPage == 'festival-blog') 
	Event.observe( window, 'load',setUpFestivalBlog);
if (thisPage == 'festival-bands') 
	Event.observe( window, 'load',setUpBands);
if (thisPage == 'festival-gallery') 
	Event.observe( window, 'load',setUpGallery);
if (thisPage == 'festival-video') 
	Event.observe( window, 'load',setUpGallery);
if (thisPage == 'festival-home') 
	Event.observe( window, 'load',setUpFestHome);
if (thisPage == 'festival-past') 
	Event.observe( window, 'load',setUpFestPast);
if (thisPage == 'festival-press') 
	Event.observe( window, 'load',setUpPress);
if (thisPage == 'landing-home') 
	Event.observe( window, 'load',setUpLandingHome);
if (thisPage == 'festival-south' || thisPage == 'festival-north') 
	Event.observe( window, 'load',setUpDirections);
