$(document).ready(function(){
	
//Navigation
	$('#menu a').click( function () {
	$('#menu a').removeClass("active");
	$(this).addClass("active");
	}); 

	$('#logo').click( function () {
	$('#menu a').removeClass("active");
	}); 
	
	
	


//Initializate fancybox
$("a[data-id^='fancybox-portfolio']").fancybox({
				'overlayShow'	: true,
				'overlayColor'		: '#000',
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic',
				'height' : 800,
				'width'	: 800		
}); 


//fancybox video
$(document).ready(function() { 
$('.video').fancybox({ 
'overlayShow'	: true,
'overlayColor'		: '#000',
'transitionIn'	: 'elastic',
'transitionOut'	: 'elastic',
'padding': 0, //optional 
'width': 750, //or whatever 
'height': 750, //or whatever 
'type': 'iframe' 
}); 
}); //ready 


//Scrol
$('#menu a, #logo, .scrol').click(function() {
	var elementClicked = $(this).attr("href");
	var destination = $(elementClicked).offset().top;
	$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-0}, 1000 );		   
	return false;
});	
		
});



/***************************************************
		FORM VALIDATION JAVASCRIPT
***************************************************/
$(document).ready(function() {
	$('form#contact_form').submit(function() {
		$('form#contact_form .error').remove();
		var hasError = false;
		$('.requiredField').each(function() {
			if(jQuery.trim($(this).val()) == '') {
            	var labelText = $(this).prev('label').text();
            	$(this).parent().append('<span class="error">You forgot to enter your '+labelText+'.</span>');
            	$(this).addClass('inputError');
            	hasError = true;
            } else if($(this).hasClass('email')) {
            	var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
            	if(!emailReg.test(jQuery.trim($(this).val()))) {
            		var labelText = $(this).prev('label').text();
            		$(this).parent().append('<span class="error">You entered an invalid '+labelText+'.</span>');
            		$(this).addClass('inputError');
            		hasError = true;
            	}
            }
		});
		if(!hasError) {
			$('form#contact_form input.submit').fadeOut('normal', function() {
				$(this).parent().append('');
			});
			var formInput = $(this).serialize();
			$.post($(this).attr('action'),formInput, function(data){
				$('form#contact_form').slideUp("fast", function() {
					$(this).before('<p class="success"><strong>Thanks!</strong> Your email was successfully sent. We will contact you as soon as possible.</p>');
				});
			});
		}

		return false;

	});
});




jQuery(document).ready(function(){
	jQuery("#about_box a").hover(function(){
		jQuery(this).find("img").stop().animate({
			opacity:0.4
		}, 400);
	}, function() {
		jQuery(this).find("img").stop().animate({
			opacity:1
		}, 400);
	});
});


jQuery(document).ready(function(){
	jQuery("#portfolio_box a").hover(function(){
		jQuery(this).find("img").stop().animate({
			opacity:0.4
		}, 400);
	}, function() {
		jQuery(this).find("img").stop().animate({
			opacity:1
		}, 400);
	});
});


/** Cycle Slider 1 **/

(function($){ 
	$(function(){
		/** Add the next and previous buttons with JavaScript to gracefully degrade */
		var cycle_container = $('#slide-container');
		cycle_container.append('<div id="cycle-next"></div><div id="cycle-prev"></div>');
		cycle_start(cycle_container, 0);
		/** Restart the slideshow when someone resizes the browser to ensure that sliding distance matches the correct viewport */
		$(window).resize(function(){
			var current_slide = cycle_container.find('.slide:visible').index();
			if(window.console&&window.console.log) { console.log('current_slide'+current_slide); }
			cycle_container.cycle('destroy');
			new_window_width = $(window).width();
			cycle_container.find('.slide').width(new_window_width);
			cycle_start(cycle_container, current_slide);
		});
	});
	/** Cycle configurations */
	function cycle_start(container, index){
		var window_width = $(window).width();
		container.find('.slide').width(window_width);
		if (container.length > 0){
			container.cycle({
				timeout: 8000,
				speed: 900,
				pager: '#cycle-pager',
				slideExpr: '.slide',
				fx: 'scrollHorz',
				easeIn: 'linear',
				easeOut: 'swing',
				startingSlide: index,
				pagerAnchorBuilder: cycle_paginate
			});
		}
	}
	function cycle_paginate(ind, el) {
		return '<a href="#slide-'+ind+'"><span>'+ind+'</span></a>';
	}
})(jQuery);


