$(document).ready(function(){
	//function for contact form dropdown
	function contact() {
		if ($("#contactForm").is(":hidden")){
			$("#contactForm").slideDown("slow");
			$("#close").fadeIn("slow");
				}
		else{
			$("#contactForm").slideUp("slow");
			$("#close").fadeOut("slow");
		}
	}
	 
	//run contact form when any contact link is clicked
	$(".contact").click(function(){contact()});

$("#close").click(function () { 
			$("#contactForm").slideUp("slow");
			$("#close").fadeOut("slow");
    });

   //animation for same page links #
	$('a[href*=#]').each(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
		&& location.hostname == this.hostname
		&& this.hash.replace(/#/,'') ) {
		  var $targetId = $(this.hash), $targetAnchor = $('[name=' + this.hash.slice(1) +']');
		  var $target = $targetId.length ? $targetId : $targetAnchor.length ? $targetAnchor : false;
			if ($(this.hash).length) {
				$(this).click(function(event) {
					var targetOffset = $(this.hash).offset().top;
					var target = this.hash;
					event.preventDefault();			   
					$('html, body').animate({scrollTop: targetOffset}, 500);
					return false;
				});
			}
		}
	});



   //submission scripts
  $('.contactForm').submit( function(){
		//statements to validate the form	
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		var email = document.getElementById('e-mail');
		if (!filter.test(email.value)) {
			$('.email-missing').show();
		} else {$('.email-missing').hide();}
		if (document.cform.name.value == "") {
			$('.name-missing').show();
		} else {$('.name-missing').hide();}	
		if (document.cform.message.value == "") {
			$('.message-missing').show();
		} else {$('.message-missing').hide();}	
		
		if ((document.cform.name.value == "") || (!filter.test(email.value)) || (document.cform.message.value == "") || (document.cform.emailadd.value != "")){
			return false;
		} 
		
		if ((document.cform.name.value != "") && (filter.test(email.value)) && (document.cform.message.value != "") && (document.cform.emailadd.value == "")) {
			//hide the form
			$('.contactForm').hide();
		
			//show the loading bar
			$('.load').append($('.bar'));
			$('.bar').css({display:'block'});
		
			//send the ajax request
			$.post('mail.php',{name:$('#name').val(),
							  email:$('#e-mail').val(),
							  message:$('#message').val()},
		
			//return the data
			function(data){
			  //hide the graphic
			  $('.bar').css({display:'none'});
			  $('.load').append(data);
			});
			
			//waits 2000, then closes the form and fades out
			setTimeout('$("#contactForm").fadeOut("slow")', 2000);
			
			//stay on the page
			return false;
		} 
  });

});

function switchvideo(videolink) {
    var videopath = '<object width="585" height="352"><param name="movie" value="'+videolink+'"></param>';
        videopath += '<param name="allowFullScreen" value="true"></param>';
        videopath += '<param name="allowscriptaccess" value="always"></param>';
        videopath += '<param name="wmode" value="transparent"></param>';
        videopath += '<embed src="'+videolink+'&hl=en_US&fs=1&rel=0&color1=0x402061&color2=0x9461ca&autoplay=1" allowscriptaccess="always" allowfullscreen="true" width="585" height="352"></embed></object>';
    $('#myvideo').html(videopath);
}

function switchplaylist(playlistlink) {
    var playlistpath = "videoplaylist/"+playlistlink+"";
    $('#vidplaylist').load(playlistpath);
}
  
function switchpicture(picturelink) {
    var picturepath = "photogallery/"+picturelink+"";
    $('#photogallery').load(picturepath);
}

