$(document).ready(function() {

 

	//Navigation Drop-Down 

	

	$("#navigation ul ul").css({display: "none"}); // Opera Fix

		$(" #navigation li ").hover(function(){

				$(this).find('ul:first').stop(true,true).delay(300).css({visibility: "visible",display: "none"}).slideDown(400);

				},function(){

				$(this).find('ul:first').stop(true,true).delay(300).fadeOut(200);

	});  

		

		

	//Portfolio hover

	

	$("a.portfolio-item").hover(function(){

			$(this).find('span:first').stop(false,true).fadeIn(400);

			},function(){

			$(this).find('span:first').stop(false,true).fadeOut(200);

	});

		

	//Cufon replacement

	

		Cufon.replace("h1");
		Cufon.replace("#logo a",{fontSize: '20px',textShadow: '0 2px #000000'});
		Cufon.replace("#logo span",{fontSize: '16px',textShadow: '0 1px white'});

		Cufon.replace("h2");

		Cufon.replace("h3");

		Cufon.replace("h4");
		
		Cufon.replace("h5");
		
		Cufon.replace("#loggedin",{textShadow: '0 1px #000000'});

		Cufon.replace("#recent-posts h1",{textShadow: '0 2px white'});

		Cufon.replace("#navigation ul li a",{textShadow: '0 1px white',hover: true});

		Cufon.replace(".btn_alt",{textShadow: '0 1px #291937'});

		Cufon.replace(".btn_white");

		Cufon.replace(".name");

		

	// Contact form

	jQuery('form#contactForm').submit(function() {

		jQuery('form#contactForm .error').remove();

		var hasError = false;

		jQuery('.requiredField').each(function() {

			if(jQuery.trim(jQuery(this).val()) == '') {

				var labelText = jQuery(this).prev('label').text();

				jQuery(this).parent().append('<span class="error">You forgot to enter your '+labelText+'.</span>');

				jQuery(this).addClass('inputError');

				hasError = true;

			} else if(jQuery(this).hasClass('email')) {

				var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;

				if(!emailReg.test(jQuery.trim(jQuery(this).val()))) {

					var labelText = jQuery(this).prev('label').text();

					jQuery(this).parent().append('<span class="error">You entered an invalid '+labelText+'.</span>');

					jQuery(this).addClass('inputError');

					hasError = true;

				}

			}

		});

		if(!hasError) {

			var formInput = jQuery(this).serialize();

			jQuery.post(jQuery(this).attr('action'),formInput, function(data){

				jQuery('form#contactForm').slideUp("fast", function() {				   

					jQuery(this).before('<p class="thanks"><strong>Thanks!</strong> Your email was successfully sent.</p>');

				});

			});

		}

		

		return false;

		

	});

	

	// Take a tour functionality

	$('ul#tour li.current a').animate({marginBottom: '20'})

					$('.step').click(function() {

						if($(this).parent().hasClass('current')) {

							



						} else {

							$('ul#tour li.current div').slideUp('slow',function() {

								$(this).parent().removeClass('current');

							}).siblings('a').animate({marginBottom: '0'});

							$(this).animate({marginBottom: '20'}).siblings('div').slideToggle('slow',function() {

								

								$(this).parent().toggleClass('current');

							});



						}

						return false;

	});
	$('#fb-feed').fbWall({
      id:                       '100001033886148',
	  accessToken:				'206158599425293|290f52ce8627abdc0c5b8798.1-39703499|XgOA-B56vocBGDlpoegDT98Ygy4',
      avatarAlternative:        'avatar-alternative.jpg',
      avatarExternal:           'avatar-external.jpg',
      max:                      3,
      showComments:             false,
      showGuestEntries:         false,
      timeConversion:           24,
      useAvatarAlternative:     false,
      useAvatarExternal:        false
	});
	if(document.getElementById('paypal'))
	{
		document.getElementById('paypal').submit();	
	}
	if($('#venues').length != 0)
	{
		showAlt(document.forms[0].venue[0],'othervenues1','othervenues2');
		showAlt(document.forms[0].venue[1],'othervenues2','othervenues1');
	}
});
function addToList(email)
{
	
	if($("#emails").val() == "")
	{
		$("#emails").val(email);
	}
	else
	{
	var currentList = $("#emails").val().split(",");
	if($.inArray(email,currentList) == -1)
	{
	currentList.push(email);
	}
	var newList = currentList.join(",");
	$("#emails").val(newList);
	}
}
function removeFromList()
{
	var currentList = $("#emails").val().split(",");
	if(currentList.length == 1)
	{
		$("#emails").val("");	
	}
	else
	{
		currentList.pop();
		
		var newList = currentList.join(",");
		$("#emails").val(newList);	
	}
}
function showAlternateDays(what,day,where)
{
	if(day == 'Monday' && what.checked)
	{
		document.getElementById(where).style.display = 'block';
		document.getElementById('alttype').style.display = 'block';
	}
	else
	{
		document.getElementById(where).style.display = 'none';
		document.getElementById('alttype').style.display = 'none';
		what.checked = 0;
	}
}
function showOtherVenues(what,day,where)
{
	if((day == 'Tuesday' || day == 'Wednesday') && what.checked)
	{
		document.getElementById(where).style.display = 'block';	
		document.getElementById('alttype').style.display = 'block';
	}
	else
	{
		document.getElementById(where).style.display = 'none';				
		document.getElementById('alttype').style.display = 'none';
	}
}
function showAlt(what,where1,where2)
{
	if(what.checked)
	{
		$('#venues').show();
		$('#'+where1).show();
		$('#'+where2).hide();
	}
}
