$(document).ready(function() {
	
	function isValidEmailAddress(emailAddress) 
	{
		var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
		
		return pattern.test(emailAddress);
	}

	// You need to specify the size of your background image here (could be done automatically by some PHP code)
	var FullscreenrOptions = {width: 1400, height: 800, bgID: '#background-body'};
	// This will activate the full screen background!
	jQuery.fn.fullscreenr(FullscreenrOptions);
	
	$(".map").colorbox({iframe:true, innerWidth:575, innerHeight:450});
	
	$("#history-link").colorbox({inline:true, href:"#photos", title:"", width: 650});
	
	$('#photos').galleryView({panel_width:600,panel_height:386,overlay_height:70,gallery_width:600,frame_width:90,frame_height:90, nav_theme:"light", transition_speed:100, transition_interval:10000000, fade_panels:false, pause_on_hover:true});

  /*var $gw_div = "<div id='galleryview-pause'><img src='/images/galleryview-pause.png' alt='' /></div>";*/

  /*$(document).bind('cbox_complete',function(){
    $('#photos').prepend($gw_div);
  });*/

  /*$('#photos').hover(
    function(){
      $('#galleryview-pause').show();
    },function(){
      $('#galleryview-pause').hide();
    }
  );*/
  
  $('.person-thumb').click(function()
	{
		var parent = $(this).parent('.contact');
		
		var targetImage = parent.find('img.person-image');
		var targetPath = targetImage.attr('src');
		
		if(targetPath != null)
		{	
			$.fn.colorbox({href:targetPath});
		}
	})
	
	/*--------------------------------------------------
		Description
	--------------------------------------------------*/
	// Window load event used just in case window height is dependant upon images
	$(window).bind("load", function() {

		stickyFooter();

		function stickyFooter() 
		{	
			var windowHeight = ($(window).scrollTop()+$(window).height());
			
			var heightWrapper = $('#wrapper').height();
			var heightFooter = $('#footer').height();
			
			if(heightWrapper < windowHeight)
			{
				
			}
			else
			{
				
			}
		}

		$(window).resize(stickyFooter);

	});
	
	/*--------------------------------------------------
		Description
	--------------------------------------------------*/
	$('.navigation_list').hover(
		function () 
		{
			$(this).addClass('over');
		}, 
		function () 
		{
			$(this).removeClass('over');
		}
	);
	
	/*--------------------------------------------------
		Description
	--------------------------------------------------*/
	$('.acessability-list').hover(
		function() 
		{
			$(this).siblings(' .navigation_list').addClass('over');
		}, 
		function() 
		{
			$(this).siblings(' .navigation_list').removeClass('over');
		}
	);
	
	/*--------------------------------------------------
		Description
	--------------------------------------------------*/
	$(function()
	{
		var page_name = $('#page-name').val();
	
		$('#body-background-home').attr('src', 'images/background-body-'+page_name+'.jpg');
		$('body').attr('id', page_name);
		
		//$('#logo-image').attr('src', 'images/logo-'+page_name+'.png');
	});
	
	/*--------------------------------------------------
		Description
	--------------------------------------------------*/
	$('#contact-form').submit(function()
	{
		var validation_success = true;
		
		var inputs = $('form#contact-form').find('.required');
		
		jQuery.each(inputs, function()
		{
			var id = $(this).attr('id');
			var value = $(this).val();
			
			if(value == '' || value == 'undefined' || value.length < 1)
			{
				validation_success = false;
				
				$('#'+id).focus();
				$('#'+id).css('background-color', '#e3f0f7');
			}
			else
			{	
				if(id == 'email' && !isValidEmailAddress(value))
				{
					validation_success = false;

					$('#'+id).focus();
					$('#'+id).css('background-color', '#e3f0f7');
				}
				else
				{
					$('#'+id).css('background-color', '#ffffff');
				}
				
			}
		});
		
		if(!validation_success)
		{
			return false;
		}
		
	});
	
});

/**
 * Set height of two elements equal
 */
function fixHeights(first, second)
{
	if($(first).height() > $(second).height())
		$(second).height($(first).height());
	else if($(first).height() < $(second).height())
		$(first).height($(second).height());
}
