/*************************** Page Fade In Effect ***************************/

jQuery(document).ready(function (){
	jQuery('#page-overlay').delay(1000).fadeOut('normal');
});


/*************************** Gallery Shortcode Lightbox Support ***************************/

jQuery(document).ready(function(){

	jQuery("div.gallery-item .gallery-icon a").prepend('<span class="hover-image"></span>');
	jQuery("div.gallery-item .gallery-icon a").attr("rel", "prettyPhoto[gallery]");
	var galleryimgWidth = jQuery("div.gallery-item .gallery-icon img").width();
	var galleryimgHeight = jQuery("div.gallery-item .gallery-icon img").height();
	jQuery("div.gallery-item .gallery-icon .hover-image").css({"width": galleryimgWidth, "height": galleryimgHeight});
	jQuery("div.gallery-item .gallery-icon a").css({"width": galleryimgWidth});

});


/*************************** Lightbox ***************************/

function gp_lightbox() {

	jQuery("a[rel^='prettyPhoto']").prettyPhoto({
		theme: 'pp_default',
		social_icons:''
	});

}

jQuery(document).ready(function(){
	gp_lightbox();
});


/*************************** Lightbox Image Hover ***************************/

function gp_image_hover() {

	jQuery('.hover-image, .hover-video').css({'opacity':'0'});
	jQuery('.overlay, div.gallery-item .gallery-icon').hover(
		function() {
			jQuery(this).find('.hover-image, .hover-video').stop().fadeTo(750, 1);
			jQuery(this).find("a[rel^='prettyPhoto'] img").stop().fadeTo(750, 0.5);
		},
		function() {
			jQuery(this).find('.hover-image, .hover-video').stop().fadeTo(750, 0);
			jQuery(this).find("a[rel^='prettyPhoto'] img").stop().fadeTo(750, 1);			
		}
	);
		
}

jQuery(document).ready(function(){
	gp_image_hover();
});


/*************************** Image Preloader ***************************/

jQuery(function () {
	jQuery('.preload').hide();
});

var i = 0;
var int=0;
jQuery(window).bind("load", function() {
	var int = setInterval("doThis(i)",150);
});

function doThis() {
	var images = jQuery('.preload').length;
	if (i >= images) {
		clearInterval(int);
	}
	jQuery('.preload:hidden').eq(0).fadeIn(750);
	i++;
}


/*************************** Accordion Slider Captions ***************************/

jQuery(document).ready(function(){	
	
	jQuery(".accordion-slider .panel").hover(
	function() {
		jQuery(this).find(".caption").stop().fadeTo(500, 1);
	},
	function() {
		jQuery(this).find(".caption").stop().fadeTo(500, 0);
	});
	
});


/*************************** Accordion ***************************/

jQuery(document).ready(function(){
	jQuery(".accordion").accordion({ header: "h3.accordion-title", autoHeight: false });
	jQuery("h3.accordion-title").toggle(function(){
		jQuery(this).addClass("active");
		}, function () {
		jQuery(this).removeClass("active");
	});	
});


/*************************** Tabs ***************************/

jQuery(document).ready(function(){
	jQuery(".sc-tabs").tabs({
		fx: {
			height:'toggle',
			duration:'fast'
		}
	});	
});


/*************************** Toggle Content ***************************/

jQuery(document).ready(function(){
	jQuery(".toggle-box").hide(); 
	
	jQuery(".toggle").toggle(function(){
		jQuery(this).addClass("toggle-active");
		}, function () {
		jQuery(this).removeClass("toggle-active");
	});
	
	jQuery(".toggle").click(function(){
		jQuery(this).next(".toggle-box").slideToggle();
	});
});


/*************************** Portfolio Sorting - Quicksand ***************************/

jQuery.noConflict();
jQuery(document).ready(function(jQuery){
	var jQuerydata = jQuery(".portfolio-wrapper").clone();

	jQuery('.portfolio-list li').click(function(e) {
		jQuery(".filter li").removeClass("active");	
		var filterClass=jQuery(this).attr('class').split(' ').slice(-1)[0];
		
		if (filterClass == 'all-categories') {
			var jQueryfilteredData = jQuerydata.find('.category');
		} else {
			var jQueryfilteredData = jQuerydata.find('.category[data-type=' + filterClass + ']');
		}
		jQuery(".portfolio-wrapper").quicksand(jQueryfilteredData, {
			duration: 800,
			easing: 'swing'
		}, function() {
			gp_lightbox();
			gp_image_hover();
		});		
		jQuery(this).addClass("active"); 			
		return false;
	});
});


/*************************** Contact Form ***************************/

jQuery(document).ready(function(){
	
	jQuery('#contact-form').submit(function() {

		jQuery('.contact-error').remove();
		var hasError = false;
		jQuery('.requiredFieldContact').each(function() {
			if(jQuery.trim(jQuery(this).val()) == '') {
				jQuery(this).addClass('input-error');
				hasError = true;
			} else if(jQuery(this).hasClass('email')) {
				var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
				if(!emailReg.test(jQuery.trim(jQuery(this).val()))) {
					jQuery(this).addClass('input-error');
					hasError = true;
				}
			}
		});
	
	});
				
	jQuery('#contact-form .contact-submit').click(function() {
		jQuery('.loader').css({display:"block"});
	});	

});
