// FUNCTIONS
$(function(){
   	f_contactInfo();
   	fadeCloseBTN();
   	submitBTN();
   	contactPanel();
   	projectItemFade();
	textjFade();
	fadeArrowBTN();
	photoSlideGallery();
	featureSlideshow();
	submit_contactForm();
})
// ------------------------------------------------------------------------------------------------------------------


// Contact Form validation
function submit_contactForm(evt){

	$('#contactForm')
	   .validate({
	   
	   	errorClass: "invalid", // add invalid class to invalid input field
	   	//errorElement: "em", // it gets rid of the error message
	   	
		errorPlacement: function(error, element) {
			error.appendTo(element);
   		},
	   	
		rules: {
			// simple rule, converted to {required:true}
			Name: "required",
			// compound rule
			Email: {
				required: true,
				email: true
			},
			Comments: "required"
		},
		
         submitHandler: function(form) {
           $(form).ajaxSubmit({
                success: function() {
                    $('#contactForm').hide();
                    $('#thankYou_box').show();
                }
           });
         }
        });

}



// Fade - contact form submit btn
function submitBTN (evt){
    $('#ContactFormSubmitBTNContainer').append('<span class="submitBTNhover"></span>');
	$('#ContactFormSubmitBTNContainer').hover(function() {
	
		// Stuff that happens when you hover on
		$('.submitBTNhover',this).stop().animate({
			'opacity': 1
			}, 700, 'easeOutSine')
	
	},function() {
	
		// Stuff that happens when you unhover
		$('.submitBTNhover',this).stop().animate({
			'opacity': 0
			}, 700,'easeOutExpo')
	});
}


function featureSlideshow(evt){
	$('#feature').cycle({
		fx: 'fade',
		speed: 1000,
		timeout: 5000,
		pager: '#feature_slideshow_counter',
	});
}

function photoSlideGallery(evt){

	$('#photoSlideContainer img:first').fadeIn(1000, function(){
		$('#photoSlideContainer').before('<div id="photoCounter">').cycle({
			fx: 'fade',
			speed: 'slow',
			timeout: 20000,
			next: '#nextPrev .next8',
			prev: '#nextPrev .prev8',
			pager: '#photoCounter',
			/* pagerEvent: 'mouseover', */
			slideExpr: 'img',
		});
	});
}

function fadeArrowBTN (evt){
    $('#nextPrev a.next8').append('<span class="nextArrowHOVER"></span>');
	$('#nextPrev a.next8').hover(function() {
		$('.nextArrowHOVER',this).stop().animate({
			'opacity': 1
			}, 1000, 'easeOutSine')
	},function() {
		$('.nextArrowHOVER',this).stop().animate({
			'opacity': 0
			}, 1000,'easeOutSine')
	});
	$('#nextPrev a.prev8').append('<span class="previousArrowHOVER"></span>');
	$('#nextPrev a.prev8').hover(function() {
		$('.previousArrowHOVER',this).stop().animate({
			'opacity': 1
			}, 1000, 'easeOutSine')
	},function() {
		$('.previousArrowHOVER',this).stop().animate({
			'opacity': 0
			}, 1000,'easeOutSine')
	});
}

function textjFade (evt) {
   	$("#filterNav ul li a").jFade({
   		trigger: "mouseover",
   		property: 'color',
   		start: '909090',
   		end: '333333',
   		step: 25,
   		duration: 50
   	}).jFade({
   		trigger: "mouseout",
   		property: 'color',
   		start: '333333',
   		end: '909090',
   		step: 25,
   		duration: 50
   	});
   	
   	$("#navigation a").jFade({
   		trigger: "mouseover",
   		property: 'color',
   		start: '000000',
   		end: '4d7fcd',
   		step: 25,
   		duration: 50
   	}).jFade({
   		trigger: "mouseout",
   		property: 'color',
   		start: '4d7fcd',
   		end: '000000',
   		step: 25,
   		duration: 50
   	});
}

// Fade - project item thumb
function projectItemFade (evt) {
//	$("#projectListingContainer a").fadeTo(300, 0.8);

	$('#projectListingContainer div.p_image').prepend('<span class="projectItemHover"></span>');
	$('#projectListingContainer div.p_image').append('<span class="projectTextHover"></span>');
	
	$('#projectListingContainer a')
		.hover(function(){
//			$('.p_title',this).stop().animate({color:'#ffffff'},1000);
			$(this).stop().fadeTo(1000, 1.0);
			$('.projectItemHover',this).stop().animate({'opacity':1},1000);
			$('.projectTextHover',this).stop().fadeTo(800, 1);
		}, function(){
//			$('.p_title',this).stop().animate({color:'#333333'},1000);
			$(this).stop().fadeTo(800, 1.0);
			$('.projectItemHover',this).stop().animate({'opacity':0},1000);
			$('.projectTextHover',this).stop().fadeTo(800, 0);
	});
	
	
	
}

// Fade - footer contact info
function f_contactInfo (evt) {
	// Turn text trigger in blue
	$("#f_contact_info_btn").mouseover(function(){
  		$(this).css({color: "#4d7fcd"});
  		}).mouseout(function(){
  		$(this).css({color: ""});
  		});

	// show and hide footer contact info
	$("#f_contact_info_btn").toggle(
		function () {
			$("#f_contact_info_btn").html("Contact Information --");
			$("#f_contact_info").removeClass('hidden').css({opacity: 0.0});
			$("#f_contact_info").stop().animate({ left: "0", opacity: 1.0}, 1000, "swing");
		},
		function () {
			$("#f_contact_info").stop().animate({ left: "20", opacity: 0.0}, 1000, "swing",
				function (){
					$("#f_contact_info").addClass('hidden');
				});
			$("#f_contact_info_btn").html("Contact Information +");
		}
	);
}

// Fade - Contact Panel CloseBTN
function fadeCloseBTN (evt){
    $('#contactCloseBTN a').append('<span class="closeBTNhover"></span>');
	$('#contactCloseBTN a').hover(function() {
	
		// Stuff that happens when you hover on
		$('.closeBTNhover',this).stop().animate({
			'opacity': 1
			}, 700, 'easeOutSine')
	
	},function() {
	
		// Stuff that happens when you unhover
		$('.closeBTNhover',this).stop().animate({
			'opacity': 0
			}, 700,'easeOutExpo')
	});
}

// Slide Contact Panel
function contactPanel (evt) {
	$("#navigation a.n_contact").click(function(){
		$("#contactPanel").animate({top:0}, 1000, 'easeOutCirc');
		return false;
	});
	
	$("#contactCloseBTN a").click(function(){
		$("#contactPanel").animate({top:-600}, 1000, 'easeOutExpo');
		return false;
	});
}
    