function theRotator() {
	//Set the opacity of all images to 0
	$j('div#quotes ul li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	$j('div#quotes ul li:first').css({opacity: 1.0});
 
	$j('div#quotes ul li:first').addClass('show');
 
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('rotate()',10000);
	
}
 
function rotate() {	
	//Get the first image
	var current = ($j('div#quotes ul li.show')?  $j('div#quotes ul li.show') : $j('div#quotes ul li:first'));
 
	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $j('div#quotes ul li:first') :current.next()) : $j('div#quotes ul li:first'));	
	
	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);
 
	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
};
 
$(document).ready(function() {		
	//Load the slideshow
	theRotator();
});


var $j = jQuery.noConflict();


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


//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();
			
	},
	
		coreFunctions : function(){
		
		$j('.openWindow').click(function() {pageTracker._trackPageview('/outbound/'+this.href.replace('http://','')); window.open(this.href); return false});
		$j('.printWindow').click(function() {window.print()});
	
		$j('.textform').focus(function() {
			if(this.nodeName != 'SELECT'){
				$j('#' + this.id).attr('class', 'textformfocus');
				if (this.value.charAt(0) == '-' && this.value.charAt(this.value.length-1) == '-') {this.value=''; }
						}
			});
		 $j('.textform').blur(function(){$j('#' + this.id).attr('class', 'textformfocus');});
	
	},
	
	
	flashRewrite : function (x, movie, query, width, height) {
	
		if (flashversion >= 8){
	
			$j(x).each(function(){
			var q='';
			var addspan = '';
			if ($j(this).html()){title = $j(this).html().replace("&", "%26").replace("'","\'")} else {title='';}
			if ($j(this).attr('class') == "flash on"){ q+= "&s=1" }
			if ($j(this).parent().attr('id')!='news'){addspan = '<span class="hidden">'+$j(this).html()+'</span>\n'}
			
			$j(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="'+$j(this).width()+'" height="'+$j(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='+$j(this).css('color')+q+'">\n' +
		'<param name="scale" value="noscale" />\n' +
		'<param name="salign" value="lt" />\n' +
		'<embed src="'+movie+'" flashvars="title='+title+'&color='+$j(this).css('color')+q+'" width="'+$j(this).width()+'" height="'+$j(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);
			
			$j(this).css('visibility', 'visible');
				});
		}
	}
	
}


var citrusWeb = {
	
	
}


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

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

	}
	
}


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



