function isValidEmail(sEmail) {

  var sQtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]';
  var sDtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]';
  var sAtom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+';
  var sQuotedPair = '\\x5c[\\x00-\\x7f]';
  var sDomainLiteral = '\\x5b(' + sDtext + '|' + sQuotedPair + ')*\\x5d';
  var sQuotedString = '\\x22(' + sQtext + '|' + sQuotedPair + ')*\\x22';
  var sDomain_ref = sAtom;
  var sSubDomain = '(' + sDomain_ref + '|' + sDomainLiteral + ')';
  var sWord = '(' + sAtom + '|' + sQuotedString + ')';
  var sDomain = sSubDomain + '(\\x2e' + sSubDomain + ')*';
  var sLocalPart = sWord + '(\\x2e' + sWord + ')*';
  var sAddrSpec = sLocalPart + '\\x40' + sDomain; // complete RFC822 email address spec
  var sValidEmail = '^' + sAddrSpec + '$'; // as whole string
  
  var reValidEmail = new RegExp(sValidEmail);
  
  if (reValidEmail.test(sEmail)) {
    return true;
  }
  
  return false;
}


function isSet( variable )
{
return( typeof( variable ) != 'undefined' );
}

$(document).ready(function(){
 var scrollnavstr = '';
 var scrollcontainer = $('#scrollcontainer');

maingallery = {
	totalImages : 0,
	timerLength : 6000,
	initialize : function(startposition){
		tthis = this;
	 	$('#scrollboard li a').each(function(i,o){
 			scrollnavstr += '<a href="' + i + '"></a>';
 			tthis.totalImages = tthis.totalImages + 1;
 		});
 		$('#scrollnav').html(scrollnavstr);

 		
 		this.goTo(startposition);
 		tthis = this;
 		this.ready = true;
 		$('a','#scrollnav').bind('click',function(event){
				event.preventDefault();
				tthis.goTo($(this).attr('href'));
		 	});
	},
	scrollIsAt : '0',
	scrollToPosition: function(position){
		target = $('li:eq(' + position + ')','#scrollboard')
		scrollcontainer.scrollTo(target,'slow',function(){
				
		});

	},
	goTo : function(position)
		{	
			this.scrollIsAt = position;
			this.scrollToPosition(position);
			this.focusDot(position);
			thetitle = $('li:eq(' + position + ') img','#scrollboard').attr('alt');
			this.setTitle($('li:eq(' + position + ') img','#scrollboard').attr('alt'));

			
		},
	goToNext : function(){
		
		//alert(this.scrollIsAt)
		if (this.scrollIsAt >= 2){ // ALWAYS ADJUST TO (TOTALIMAGES - 1)
			this.goTo(0);
		}else{this.goTo(this.scrollIsAt + 1)}
	},
	focusDot : function(position)
	{
		$('a','#scrollnav').animate({opacity:'.5'},'fast',function(){
 			$('a:eq(' + position + ')','#scrollnav').animate({opacity:'0.999'},'fast');
 		});
	},
	setTitle: function(text){
		$('#productname','#scrolllegend').html(text);
 	},
 	startRotation: function(){
// 		if(this.hasTimer){clearTimeout(theTimeout);this.hasTimer = false;}
		
 		tthis = this;
 		clearInterval(tthis.theTimeout)
 		tthis.theTimeout = setInterval("tthis.goToNext()",tthis.timerLength);
 		
// 		this.hasTimer = true;*/
 	}		
}

maingallery.initialize(0);
maingallery.startRotation();

$('.trigger_clients_display').click(function(){
$('#clients_display').animate({width: '400'},'fast');

})

$('#harvestaddress').submit(function(event){

	var theemail = $('input#emailaddress').val();
	if (isValidEmail(theemail)){
		return true;
	}else{
		alert('Please enter a valid email address');
		return false;
	}

})

//
//function addSuccess(){
//	$('.emailform').html('<div style="text-align:center;font-weight:bold;font-size:1.4em;">Thanks!</div>');
//}
//
//function addFailure(){
//	alert('address NOT added');
//}

 $('.unclickable,.mute').click(function(event){
  event.preventDefault();
 });
 
});