$().ready(function() {
	// prettyWindow
	$("a[rel^='prettyPhoto']").prettyPhoto({
        animationSpeed: 'fast', /* fast/slow/normal */
		padding: 40, /* padding for each side of the picture */
        opacity: 0.35, /* Value betwee 0 and 1 */
        showTitle: true, /* true/false */
        allowresize: true, /* true/false */
        counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
        theme: 'dark_rounded', /* light_rounded / dark_rounded / light_square / dark_square */
        callback: function(){}
   	 });

	    // Raise/Lower Contact Bar
	$('.contactjq, #contactArrow').click(function(event) {
		var $footer = $('#footerwrap');
		var $arrow = $('#contactArrow');
		if ($footer.height() < 160)
		{
			$arrow.attr('src','../images/arrowDown.png');
			$footer.animate({'height':250},{duration:'slow',queue:false});
		}
		else
		{
			$arrow.attr('src','../images/arrowUp.png');
			$footer.animate({'height':70},{duration:'slow',queue:false});
		}
	});
	
	// Submit the contact form via AJAX
	$('#sendnow').click(function() {
		//Form Validation
		var fromname = $('#fromname').val();
		var fromemail = $('#fromemail').val();
		var message = $('#message').val();
		if (fromname == '')
		{
			alert('Please include your name with your email...');
			$('#fromname').addClass('error').focus();			
			return false;
		}
		if (isValidEmail(fromemail) == false)
		{
			alert('Please include your email address so that we may get back to you...');
			$('#fromemail').addClass('error').select();			
			return false;
		}
		if (message == '')
		{
			alert('Please include a message with your email...');
			$('#message').addClass('error').focus();			
			return false;
		}
		
		// Good submit, run the process
		$('#contactForm').remove();
		$('#contact').append('<div id="removeme" >Sending email...</div>');
		
		$.post('./mail.php',{'ajax':1,'operation':'contactSubmit','fromname':fromname,'fromemail':fromemail,'message':message},function(data){$('#removeme').remove();$('#contact').append(data);});
	});
});

function isValidEmail(e)
{
	var email  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (email.test(e) == false) 
	{
      return false;
    } 
    else 
    {
      return true;
    }
}

function toggleLayer( whichLayer )
{
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}