/**
 * website.js
 */

var website = {
	
	init: function() {
		
		website.init_slideshow();
		
		if( $('.column-main').height() > $('.column-left').height() ) {
			$('.column-left').height( $('.column-main').height() );
		}
		
		$('.credit a').click(function() {
			window.open( $(this).attr('href') );
			return false;
		});
		
	}
	
	,init_slideshow: function() {

		$('.slideshow li').each(function() {
			if( $(this).find('img').length < 1 ) {
				var img = $(this).find('span').attr('title');
				$(this).html('<img src="' + img + '" alt="" />');
			}
		});
		
		$(window).load(function() {
			setInterval( "website.cycle_images()", 3000 );
		});
		
	}
	
	,cycle_images: function() {
		var $active = $('.slideshow li.active');
		
		if ( $active.length == 0 ) {
			$active = $('.slideshow li:last');
		}
		
		var $next =  $active.next().length ? $active.next() : $('.slideshow li:first');
		
		$active.addClass('last-active');
		
		$next.css({opacity: 0.0})
			 .addClass('active')
			 .animate({opacity: 1.0}, 2000, function() {
			     $active.removeClass('active last-active');
			 });

	}
	
	,validateContactForm: function( form ) {
		
		if(form.name.value == '') {
			alert('Please enter your name to continue');
			form.name.focus();
			return false;
		}
		if(form.emailaddress.value == '') {
			alert('Please enter your email address to continue');
			form.emailaddress.focus();
			return false;
		}
		if( !validateemail(form.emailaddress.value) ) {
			alert('Please enter a valid email address to continue');
			form.emailaddress.focus();
			return false;
		}
		if(form.comments.value == '') {
			alert('Please enter some comments continue');
			form.comments.focus();
			return false;
		}
		if(form.captchacode.value == '') {
			alert('Please enter the anti-spam code to continue');
			form.captchacode.focus();
			return false;
		}
		
		return true;
	}
	
};

$(document).ready(website.init);


function validateemail(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = email;
   if(reg.test(address) == false) {
      return false;
   } else {
	   return true;
   }
}


