
// true if IE
var IE = /*@cc_on!@*/false;

Cufon.replace('h2, .maincontainer h3', { fontFamily: 'Helvetica LT Std' })
Cufon.replace('h1, a.resourcesButton, #categories a, #courselist h3, .imageholder h3, #slidetwo h3', {
			  	fontFamily: 'Helvetica LT Std',
				textShadow: '0 -1px 0px rgba(0, 0, 0, 0.4)'
});
Cufon.replace('.studentzone h1, #leftside h3, .studentzone .graphiclink', {
			  	fontFamily: 'Helvetica LT Std',
				textShadow: '#222 0px -1px'
});
Cufon.replace('#coursefinder h2, #leftside h4', {
			  	fontFamily: 'Helvetica LT Std',
				textShadow: '#000 0px -1px'
});
Cufon.replace('.w2 h3, .w2 h4', {
			  	fontFamily: 'Helvetica Neue LT Std',
				textShadow: '#eee 0px 1px'
});
Cufon.replace('#calendar th', {
			  	fontFamily: 'Helvetica Neue LT Std',
				textShadow: '#ddd 0px 1px'
});
Cufon.replace('#calendar td .day, .w3 h3', {
			  	fontFamily: 'Helvetica Neue LT Std',
				textShadow: '#fff 0px 1px'
});
Cufon.replace('#calendar .today .day', {
			  	fontFamily: 'Helvetica Neue LT Std',
				textShadow: '#444 0px 1px'
});


//detect flash
var flashversion = 0;
if (navigator.plugins && navigator.mimeTypes.length) {
	var x = navigator.plugins["Shockwave Flash"];
	if(x && x.description) {
		var y = x.description;
		flashversion = parseInt(y.substr(y.indexOf(".") - 2, 2), 10);
	}
} else {
	result = false;
	for(var i = 30; i >= 3 && result != true; i--){
		execScript('on error resume next: result = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.'+i+'"))','VBScript');
		flashversion = i;
	}
}

if (flashversion >= 8) {
	    document.getElementsByTagName('html')[0].className = 'flashInstalled';
}
		document.getElementsByTagName('html')[0].className += ' json';

		
var citrusCMS = {
		
	load : function() {
		citrusCMS.coreFunctions();
		citrusCMS.tabWidgets();
		citrusCMS.sizeChanger();
		if ($('#header')[0]){citrusCMS.slideSwitch();}
		if ($('#boxes')[0]){citrusCMS.boxLinks();}	
		if ($('#widgets')[0]){citrusCMS.calendarControls();}
		citrusCMS.courseFinder();
		//citrusCMS.sizeChanger();
		//citrusCMS.coursesMain();
	},
	
		coreFunctions : function(){
		
		$('.openWindow').click(function() {pageTracker._trackPageview('/outbound/'+this.href.replace('http://','')); window.open(this.href); return false});
		$('.printWindow').click(function() {window.print()});
		$('.confirm').click(function() {return confirm('Are you sure you want to '+this.title+'?')}); 
		
		if ($('#appForm')[0]){
			$('.textform').focus(function() {
			if(this.nodeName != 'SELECT'){
				$('#' + this.id).attr('class', 'textformfocus');
				$('.textform').each(function(){if ($(this).attr('value')==''){$(this).attr('value',$(this).attr('id').replace(/_/gi,' ')+'...');} });
				if (this.value.substr(this.value.length-3,3) == '...') {this.value=''; }
						}
			});
		} else {
		$('.textform').focus(function() {
			if(this.nodeName != 'SELECT'){
				$('#' + this.id).attr('class', 'textformfocus');
				if (this.value.substr(this.value.length-3,3) == '...') {this.value=''; }
						}
			});
		}
		 $('.textform').blur(function(){$('#' + this.id).attr('class', 'textform');});
		$('.datepicker').datepicker({ dateFormat: 'dd/mm/yy' });
		
		
		 $('.playVid').fancybox({
			'autoScale'     	: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'				: 'iframe'
		});
		 
		
		 $('#playShowreel').click(function() {
			if (flashversion < 8) {
				$('html, body').animate({scrollTop:0}, 'slow');
				$('#showreel').css('display','block');
				$('#showreelplayer').html('<a href="http://get.adobe.com/flashplayer/" onclick="window.open(this.href); return false;"><img src="/_img/layup/nonflash.jpg" alt="Get Flash player" width="988" height="313" /></a>');
			} else {
				$('html, body').animate({scrollTop:0}, 'slow');
				$('#showreel').css('display','block');
				$('#showreelplayer').html('');
				citrusCMS.flashRewrite('#showreelplayer','/video/showreel.swf', '', '1');
			}
			return false
		 });
		 
		 $('#hideShowreel').click(function() {
			$('#showreel').css('display','none');
			$('#showreelplayer').html('');
			return false;
		});
		},
	
	tabWidgets : function() {
		$('.tab').click(function () {
			if ($(this).attr('class') == 'tab on') {
				$(this).siblings('.content').animate({
						height: '0px'
					    }, 500, function() {
						$(this).hide();
							
				});
				$(this).removeClass('on');
					
				} else {
				$(this).siblings('.content').show();
				$(this).siblings('.content').animate({
						height: '300px'
					    }, 500, function() {
				});
				
			    $(this).addClass('on');
				
				}
				return false;
			});	
			 
		$('.widget .content').hide();
		$('.widget .content').css({'height' : '0px' });
		citrusCMS.emailsignup();
	},
	
	emailsignup : function() {
		$('#signupform').submit(function(){
			$('#signupform').ajaxStart(function() {
			  $('.w4 .holder').html('<p class="emailloading">Your request is being processed</p>');
			});
										 
			$.post('/content/ajax/emailsignup.asp', $('#signupform').serialize(), function(data){$('.w4 .holder').html(data);citrusCMS.coreFunctions();citrusCMS.emailsignup(); });
			return false;							 
		});
	},
	
	resourceLibrary : function() {
		$('a.resourcesButton').click(function() {
				if($(this).next().is(':visible')) {
					$('div.resourcesContent').slideUp('normal');
					$('.resources a.on').removeClass('on');
				} else {
					$('div.resourcesContent').slideUp('normal');	
					$(this).next().slideDown('normal');
					$('.resources a.on').removeClass('on');
					$(this).removeClass('on').addClass('on');
				}
				return false;
			});
		
			citrusCMS.librarySearch();
			
	},
		
	librarySearch : function() {
		$('#filterlibrary').keypress(function(){
				$.get('/content/ajax/librarysearch.asp',$('#filtersearch').serialize(),function(data){
				
				//if ($('#filterlibrary').attr('value').length > 1) {
				if ($('#resourcesresults')[0]){	
					$('#resourcesresults').html(data.replace('<li id="resourcesresults">','').replace('</li>',''));
				} else {
					$('.resources').children(':eq(0)').prepend(data);
					
				}
				
				$('#resourcesresults a.resourcesButton').click(function(){
						if($(this).next().is(':visible')) {
							$('div.resourcesContent').slideUp('normal');
							$('.resources a.on').removeClass('on');
						} else {
							$('div.resourcesContent').slideUp('normal');	
							$(this).next().slideDown('normal');
							$('.resources a.on').removeClass('on');
							$(this).removeClass('on').addClass('on');
						}						  
				});
				
						Cufon.replace('a.resourcesButton', {
								fontFamily: 'Helvetica LT Std',
								textShadow: '0 -1px 0px rgba(0, 0, 0, 0.5)'
								});
				});
		});
	},
	
		courseFinder : function() {
	
			$('#cfinder').bind('click', function() {
					if ($('#coursefinder').attr('class')=='on') {
						$('#coursefinder').fadeOut('fast', function() {
									$('#coursefinder').removeClass('on');		
									$('#cfinder').removeClass('on');	
						}) ;
						
					} else {
						$('#coursefinder').fadeIn('fast', function() {
									$('#coursefinder').addClass('on');	
									$('#cfinder').addClass('on');
							}) ;
						
					}
					return false;
				});
				
					$('#coursefinder').bind('mouseleave', function(){
							$('#coursefinder').fadeOut('fast', function() {
									$('#coursefinder').removeClass('on');		
									$('#cfinder').removeClass('on');	
						});								 
					 });
			
			
			//step 1
			$('#coursefinder .step1 a').click(function () {
			if ($(this).attr('class') == 'selected'){
				$(this).removeClass('selected');
				$('#coursefinder .step2 .inner').animate({left: '-300px'}, 500);
				$('#coursefinder .step2 a').each(function(){$(this).removeClass('selected');})	
				
				if ($('#coursefinder .step3 .inner').css('left')=='0px'){
									$('#coursefinder .step3 .inner').animate({left: '-600px'}, 500);
					$('#coursefinder .step3 a').each(function(){$(this).removeClass('selected');})					
					}	
				
			} else {
				$('#coursefinder .step1 a').each(function(){$(this).removeClass('selected');})
				$(this).addClass('selected');
 				$('#step1value').attr('value',$(this).attr('href').replace('#',''));		
				$.get('/content/ajax/step2.asp','ajax=1&step1=' + $(this).attr('href').replace('#',''), function(data){
						$('#step2results').html(data); citrusCMS.courseFinderStep2();	
					});
				
				$('#coursefinder .step2 .inner').show();
				
				if ($('#coursefinder .step2 .inner').css('left')=='0px'){
									$('#coursefinder .step2 .inner').animate({left: '-300px'}, 500);
				$('#coursefinder .step2 a').each(function(){$(this).removeClass('selected');})	
					}
				
				if ($('#coursefinder .step3 .inner').css('left')=='0px'){
									$('#coursefinder .step3 .inner').animate({left: '-600px'}, 500);
					$('#coursefinder .step3 a').each(function(){$(this).removeClass('selected');})					
					}
					
				$('#coursefinder .step2 .inner').animate({left: '0px'}, 500);
				
			
				}
			});
				
		//hide all
		//$('#coursefinder .step2 .inner, #coursefinder .step3 .inner').css({left : '-300px'});
		$('#coursefinder .step2 .inner').css({left : '-300px'});
		$('#coursefinder .step3 .inner').css({left : '-600px'});
		$('#coursefinder .step2 .inner, #coursefinder .step3 .inner').hide();
			
			
		},
		
		courseFinderStep2 : function() {
			$('#coursefinder .step2 a').click(function () {
				if ($(this).attr('class') == 'selected'){
					$(this).removeClass('selected');
					$('#coursefinder .step3 .inner').animate({left: '-600px'}, 500);
					
					
				} else {
				
						$('#coursefinder .step2 a').each(function(){$(this).removeClass('selected');})
							$(this).addClass('selected');
						$('#step2value').attr('value',$(this).attr('id').replace('s',''));	
						
						$.get('/content/ajax/step3.asp','ajax=1&step1='+$('#coursefinder .step1 .selected').attr('href').replace('#','')+'&step2='+$(this).attr('id').replace('s',''), function(data){
								$('#step3results').html(data); citrusCMS.courseFinderStep3();			
							});
						
							$('#coursefinder .step3 .inner').show();
							
							if ($('#coursefinder .step3 .inner').css('left')=='0px'){
									$('#coursefinder .step3 .inner').animate({left: '-600px'}, 500);
								}
								
							$('#coursefinder .step3 .inner').animate({left: '0px'}, 500);
				
				}
														
			});
		},
		
		courseFinderStep3 : function() {
			$('#coursefinder .step3 a').click(function () {
					$('#coursefinder .step3 a').each(function(){$(this).removeClass('selected');})	
					$(this).addClass('selected');
					$('#step3value').attr('value',$(this).attr('id').replace('c',''));	
					$('#cfilterform').submit();
			});
		},
		
	boxLinks : function(){
		  $('.box').click(function(){
				window.location = $(this).children('div').children('a').attr('href');				 
		 });
	
	},
	
	slideSwitch : function(){$('#thumbs').galleriffic();},
	
	coursesMain : function() {
		if ($('#coursesectors')[0]){
				$('#coursesectors >li > a').click(function(){
				//$.get('/content/ajax/coursesmain.asp', 'ajax=1&cat=' +$(this).attr('href').split('/')[2] , function(data){$('#text').html(data)});		
				//return false;
			});
		}
	},
	
	courseSelector : function() {
		
		if ($('#courseselect').height()==''){$('#courseselect').css({height: $('#slideone').height()});}
		
		$('#categories a').click(function(){
			var cat = $(this).attr('href').split('/');
			$.get('/content/ajax/courseresults.asp', 'ajax=1&cat='+cat[2]+'&sector=' + cat[3], function(data){
				$('#slidetwo').html(data);	
				Cufon.refresh();
				$('#slidetwo').show();
				
				$('#courseselect').animate({
					height: $('#slidetwo').height()
					}, 500, function() {
				});

				$('#slideone').animate({
						left: '-712px'
						}, 500, function() {
				});
				$('#slidetwo').animate({
						left: '0px'
						}, 500, function() {
				});
				
			citrusCMS.courseSelector2();
		});
			
			return false;
			
	});
	},
		
	courseSelector2 : function(){	
		$('#slidetwo a.backtocats').click(function(){
				$('#slideone').animate({
						left: '0px'
						}, 500, function() {
				});
				$('#slidetwo').animate({
						left: '712px'
						}, 500, function() {
						
						
				});
				$('#courseselect').animate({
							height: $('#slideone').height()
							}, 500, function() {
					});
				return false;
		});
		
	},
	
	
courseTabs : function() {
	if ($('#tabs')) {	
		$('#tabs > li').click(function() {
		$('#tabs > li > a').each(function(){$(this).removeClass('on');})
		$('#tabmain > div').each(function(){$(this).attr('class','taboff');})
			$(this).children().addClass('on'); 
			$('#'+$(this).children().attr('id').replace('t', '')).attr('class','tabon'); 
			return false;
		});	
	}
	},
	
	calendarControls : function() {
		
		$('.controls > a').click(function(){
			$.get($(this).attr('href'), 'ajax=1', function(data){
					$('#minicalendar').html(data); citrusCMS.calendarControls();
					Cufon.replace('#events .date', { fontFamily: 'Helvetica LT Std' });
					Cufon.replace('#calendar th', {
								fontFamily: 'Helvetica Neue LT Std',
								textShadow: '#ddd 0px 1px'
				});
				Cufon.replace('#calendar td .day, .w3 h3, .maincontainer h4', {
								fontFamily: 'Helvetica Neue LT Std',
								textShadow: '#fff 0px 1px'
				});
				Cufon.replace('#calendar .today .day', {
								fontFamily: 'Helvetica Neue LT Std',
								textShadow: '#444 0px 1px'
				});

					});
			return false;
		});
	},
	
	
	peoplePage : function() {
		$('.people > .first').each(function(){
				h1 = $(this).height();
				h2 = $(this).next().height();
				
				if (h1 > h2){
					$(this).css('height', h1);
					$(this).next().css('height', h1);
				} else {
					$(this).css('height', h2);
					$(this).next().css('height', h2);
				}
			});
	},
	
	
	flashRewrite : function (x, movie, query, width, height) {
	
		if (flashversion >= 8){
	
			$(x).each(function(){
			var q='';
			var addspan = '';
			if ($(this).html()){title = $(this).html().replace("&", "%26").replace("'","\'")} else {title='';}
			if ($(this).attr('class') == "flash on"){ q+= "&s=1" }
			if ($(this).parent().attr('id')!='news'){addspan = '<span class="hidden">'+$(this).html()+'</span>\n'}
			
			$(this).html('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="'+$(this).width()+'" height="'+$(this).height()+'">\n' +
		'<param name="movie" value="'+movie+'">\n' + 
		'<param name="quality" value="high" />\n' +
		'<param name="menu" value="false">\n' +
		'<param name="wmode" value="transparent">\n' +
		'<param name="flashvars" value="title='+title +'&color='+$(this).css('color')+q+'">\n' +
		'<param name="scale" value="noscale" />\n' +
		'<param name="salign" value="lt" />\n' +
		'<embed src="'+movie+'" flashvars="title='+title+'&color='+$(this).css('color')+q+'" width="'+$(this).width()+'" height="'+$(this).height()+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" menu="false" scale="noscale" salign="lt" wmode="transparent"></embed>\n' +
		'</object>' + addspan);
			
			$(this).css('visibility', 'visible');
				});
		}
	},
	
		cookie : function(name,value,options) {
		if(typeof value!='undefined'){options=options||{};if(value===null){value='';options.expires=-1;}var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000));}else{date=options.expires;}expires='; expires='+date.toUTCString();}var path=options.path?'; path='+(options.path):'';var domain=options.domain?'; domain='+(options.domain):'';var secure=options.secure?'; secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('');}else{var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break;}}}return cookieValue;}
	},
	
	
	opacityrollover : function() {
		var defaults = {
		mouseOutOpacity:   0.67,
		mouseOverOpacity:  1.0,
		fadeSpeed:         'fast',
		exemptionSelector: '.selected'
	};

		$.fn.opacityrollover = function(settings) {
			// Initialize the effect
			$.extend(this, defaults, settings);
	
			var config = this;
	
			function fadeTo(element, opacity) {
				var $target = $(element);
				
				if (config.exemptionSelector)
					$target = $target.not(config.exemptionSelector);	
				
				$target.fadeTo(config.fadeSpeed, opacity);
			}
	
			this.css('opacity', this.mouseOutOpacity)
				.hover(
					function () {
						fadeTo(this, config.mouseOverOpacity);
					},
					function () {
						fadeTo(this, config.mouseOutOpacity);
					});
	
			return this;
	};
		
		
	},
	

	sizeChanger : function() {
		//load cookie for css switcher
	var cookie = citrusCMS.cookie('style');
	var title = cookie ? cookie : getPreferredStyleSheet();
	setActiveStyleSheet(title);
		
		//show correct size on navi
		if (cookie){
		cookiestr = cookie.toString().replace(' Screen Style','');
	
		if ($('#' + cookiestr)){
			$('#' + cookiestr).attr('class', 'on');
		}else{
			$('#Default').attr('class', 'on');
		}
		
		}else{
			$('#Default').attr('class', 'on');
		}
		
		//textchange navi
		$('#tools > li > a').click(function(){
			if ($(this).attr('class') != 'textstyle' && $(this).attr('class') != 'printWindow'){
				$('#tools > li > a').each(function(){$(this).removeClass('on');});
				$(this).attr('class', 'on');
				setActiveStyleSheet($(this).attr('id')); 
				Cufon.refresh();
				if ($('#courseselect')[0]){$('#courseselect').css({height: $('#slideone').height()});}
				return false; 
			}
		});
			

	}
	
}


var citrusWeb = {
	
	
}


var citrusAjax = {
	
	makeRequest: function(requestURL,getID){
		$.ajax({
		    url: requestURL,
		    success: function(data) {
			$(getID).html(data);
		  }
		});
	},
	
	submitForm : function(pageUrl) {
		
		$('#waiting').html('<img src="/_img/layup/loading.gif" />');
		$('#submitButton').type == 'button'; //if js then remove the submit function of the button
		$('#submitButton').disabled = 'disabled'; //when submited disable button
		
		waitPadd = (($('#cmsForm')).height() - 45) /2
		$('#waiting').css('paddingTop', waitPadd + 'px');
		$('#waiting').css('paddingBottom', waitPadd + 'px');
		$('#waiting').fadeIn(); //show waiting div
		
		//stops whole site appearing when ajax is called
		if(pageUrl) {pageLocation = pageUrl} else {pageLocation = window.location}
		
		$.post(pageUrl, 'ajax=1&' +  $('#cmsForm').serialize(), function(data){citrusAjax.showResponse(data)});
		
	},

	showResponse : function(originalRequest) {
			
			if(originalRequest.substring(0,4) == 'http') {
				window.location = originalRequest; //redirect
			  } else {
				$('#waiting').fadeOut() ; //hide waiting div
				$('#cmsForm').html(originalRequest); //show response
				//$('#submitButton').effect('shake', { times:3 }, 100);
				citrusCMS.load();
  			}

	}
	
}

$(document).ready(citrusCMS.load);
